im.js
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict';
const _ = require('lodash');
const crypto = global.yoho.crypto;
const config = global.yoho.config;
const ImAPI = new global.yoho.ApiBase(config.domains.imCs, {
name: 'im',
cache: global.yoho.cache,
useCache: false
});
const encryptedUid = uid => crypto.encryption(null, uid + '');
/**
* 新建留言信息
* path: {host}/leavemessage/saveLeavemessage
*
* @param {int} uid 用户id
* @param {int} conversationId 会话id
* @param {str} content 留言内容
*/
exports.saveMessage = (uid, conversationId, content) => {
let params = {
uid,
conversationId,
content,
encryptedUid: encryptedUid(uid)
};
return ImAPI.post('/api/leavemessage/saveLeavemessage', params);
};
/**
* 查询用户聊天记录
* @param {int} uid 用户uid
* @param [int] pageSize 每次加载的聊天记录
* @param [int] startTime
* @param [int] endTime
*/
exports.fetchImHistory = (uid, endTime, pageSize, startTime) => {
pageSize = pageSize || 10;
let params = {
uid,
pageSize,
encryptedUid: encryptedUid(uid)
};
_.forEach({startTime, endTime}, (key, val) => {
val && (params[key] = val);
});
return ImAPI.get('/api/conversationMessage/pageList', params)
.then(result => {
return result;
}, () => {
return {
code: 500,
data: {
records: [], totalCount: 0
}
};
});
};
/**
* 获取用户订单, 默认最近10笔
* @param {int} uid 用户uid
* @param {init} createTimeBegin 开始时间
*/
exports.fetchOrderList = (uid, createTimeBegin) => {
let params = {
uid,
encryptedUid: encryptedUid(uid),
imgSize: '90x120',
};
_.forEach({createTimeBegin}, (key, val) => {
val && (params[key] = val);
});
return ImAPI.get('/api/order/queryLastTenOrder', params);
};