Showing
1 changed file
with
9 additions
and
9 deletions
@@ -11,13 +11,14 @@ const crypto = require('crypto'); | @@ -11,13 +11,14 @@ const crypto = require('crypto'); | ||
11 | const logger = require('../../../library/logger'); | 11 | const logger = require('../../../library/logger'); |
12 | const cache = require('../../../library/cache'); | 12 | const cache = require('../../../library/cache'); |
13 | 13 | ||
14 | -const appId = 'wx75e5a7c0c88e45c2'; | ||
15 | -const secret = 'ce21ae4a3f93852279175a167e54509b'; | 14 | +// 此处请勿使用有货公众号的 appId, 此处使用的是 女生志 的appId |
15 | +const appId = 'wx3de6d30e9567c227'; | ||
16 | +const secret = '1110772674e5751caad6563f2e9f0f53'; | ||
16 | 17 | ||
17 | -const sha1 = (etr) => { | 18 | +const sha1 = (str) => { |
18 | const generator = crypto.createHash('sha1'); | 19 | const generator = crypto.createHash('sha1'); |
19 | 20 | ||
20 | - generator.update(etr); | 21 | + generator.update(str); |
21 | return generator.digest('hex'); | 22 | return generator.digest('hex'); |
22 | }; | 23 | }; |
23 | 24 | ||
@@ -55,7 +56,7 @@ const wechat = { | @@ -55,7 +56,7 @@ const wechat = { | ||
55 | }); | 56 | }); |
56 | }), | 57 | }), |
57 | 58 | ||
58 | - getTicket: Promise.coroutine(function* (accessToken) { | 59 | + getTicket: Promise.coroutine(function* () { |
59 | let ticket = yield cache.get(ticketCacheKey); | 60 | let ticket = yield cache.get(ticketCacheKey); |
60 | 61 | ||
61 | if (ticket) { | 62 | if (ticket) { |
@@ -66,7 +67,7 @@ const wechat = { | @@ -66,7 +67,7 @@ const wechat = { | ||
66 | return request({ | 67 | return request({ |
67 | url: 'https://api.weixin.qq.com/cgi-bin/ticket/getticket', | 68 | url: 'https://api.weixin.qq.com/cgi-bin/ticket/getticket', |
68 | qs: { | 69 | qs: { |
69 | - access_token: accessToken, | 70 | + access_token: yield this.getAccessToken(), |
70 | type: 'jsapi' | 71 | type: 'jsapi' |
71 | }, | 72 | }, |
72 | json: true | 73 | json: true |
@@ -83,13 +84,12 @@ const wechat = { | @@ -83,13 +84,12 @@ const wechat = { | ||
83 | }), | 84 | }), |
84 | 85 | ||
85 | calcSignature: Promise.coroutine(function* (data) { | 86 | calcSignature: Promise.coroutine(function* (data) { |
86 | - let accessToken = yield this.getAccessToken(); | ||
87 | - | ||
88 | data = Object.assign({ | 87 | data = Object.assign({ |
89 | noncestr: Math.random().toString(36).substr(2, 15), | 88 | noncestr: Math.random().toString(36).substr(2, 15), |
90 | timestamp: Math.floor(Date.now() / 1000) + '', | 89 | timestamp: Math.floor(Date.now() / 1000) + '', |
91 | - ticket: yield this.getTicket(accessToken) | 90 | + ticket: yield this.getTicket() |
92 | }, data); | 91 | }, data); |
92 | + | ||
93 | const str = `jsapi_ticket=${data.ticket}&noncestr=${data.noncestr}×tamp=${data.timestamp}&url=${data.url}`; | 93 | const str = `jsapi_ticket=${data.ticket}&noncestr=${data.noncestr}×tamp=${data.timestamp}&url=${data.url}`; |
94 | 94 | ||
95 | data.signature = sha1(str); | 95 | data.signature = sha1(str); |
-
Please register or login to post a comment