Showing
2 changed files
with
44 additions
and
0 deletions
apps/activity/controllers/wechat.js
0 → 100644
apps/activity/models/wechat.js
0 → 100644
1 | +const request = require('request-promise'); | ||
2 | +const Promise = require('bluebird'); | ||
3 | +const logger = require('../../../library/logger'); | ||
4 | + | ||
5 | +const appId = ''; | ||
6 | +const secret = ''; | ||
7 | + | ||
8 | +const wechat = { | ||
9 | + getAccessToken: Promise.coroutine(function* () { | ||
10 | + return request({ | ||
11 | + url: 'https://api.weixin.qq.com/cgi-bin/token', | ||
12 | + qs: { | ||
13 | + grant_type: 'client_credential', | ||
14 | + appid: appId, | ||
15 | + secret: secret | ||
16 | + } | ||
17 | + }).catch((err) => { | ||
18 | + logger.error('微信分享 Token, 获取 accessToken 时出错', JSON.stringify(err)); | ||
19 | + }); | ||
20 | + }), | ||
21 | + | ||
22 | + getTicket: Promise.coroutine(function* (accessToken) { | ||
23 | + return request({ | ||
24 | + url: 'https://api.weixin.qq.com/cgi-bin/ticket/getticket', | ||
25 | + qs: { | ||
26 | + access_token: accessToken, | ||
27 | + type: 'jsapi' | ||
28 | + } | ||
29 | + }).catch((err) => { | ||
30 | + logger.error('微信分享 Token, 获取 ticket 时出错', JSON.stringify(err)); | ||
31 | + }); | ||
32 | + }), | ||
33 | + | ||
34 | + calcSignature: Promise.coroutine(function* () { | ||
35 | + return yield Promise.resolve(true); | ||
36 | + }) | ||
37 | +}; | ||
38 | + | ||
39 | +module.exports = wechat; |
-
Please register or login to post a comment