wechat.js
1.37 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
/**
* 微信model
* @author: qiujun <jun.qiu@yoho.cn>
* @date: 15/11/2017
*/
const mysqlCli = global.yoho.utils.mysqlCli;
const TABLE_WECHAT = 'wechat_token';
class WechatModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getAccessKeys() {
let strSql = `select * from ${TABLE_WECHAT} limit 0, 1;`;
return mysqlCli.query(strSql);
}
saveAccessKeys(access_token, access_ticket, access_create_time, access_expired, type) {
let strSql = '';
let params = {
access_token,
access_ticket,
access_create_time,
access_expired
};
if (type === 'save') {
strSql = `insert into ${TABLE_WECHAT}
(access_token, access_ticket, access_create_time, access_expired) values
(:access_token, :access_ticket, :access_create_time, :access_expired);`;
return mysqlCli.insert(strSql, params);
} else if (type === 'update') {
strSql = `update ${TABLE_WECHAT} set
access_token = :access_token,
access_ticket = :access_ticket,
access_create_time = :access_create_time,
access_expired = :access_expired`;
return mysqlCli.update(strSql, params);
}
}
}
module.exports = WechatModel;