q-koa 13.8.19 → 13.8.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const util = require('util')
|
|
2
2
|
const axios = require('axios')
|
|
3
|
-
const getAccessTokenUrl =
|
|
3
|
+
const getAccessTokenUrl = 'https://api.weixin.qq.com/cgi-bin/stable_token'
|
|
4
4
|
const getTicketUrl =
|
|
5
5
|
'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi'
|
|
6
6
|
const sha1 = require('sha1')
|
|
@@ -31,16 +31,22 @@ module.exports = class Singleton {
|
|
|
31
31
|
init() {
|
|
32
32
|
return this
|
|
33
33
|
}
|
|
34
|
-
async getAccessToken() {
|
|
35
|
-
const { appid, secrect
|
|
36
|
-
if (cache.get(
|
|
37
|
-
return cache.get(
|
|
34
|
+
async getAccessToken(force_refresh = false) {
|
|
35
|
+
const { appid, secrect } = this.config
|
|
36
|
+
if (!force_refresh && cache.get(appid)) {
|
|
37
|
+
return cache.get(appid)
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
const result = await axios
|
|
40
|
+
.post(getAccessTokenUrl, {
|
|
41
|
+
grant_type: 'client_credential',
|
|
42
|
+
appid,
|
|
43
|
+
secret: secrect,
|
|
44
|
+
force_refresh,
|
|
45
|
+
})
|
|
46
|
+
.then((res) => res.data)
|
|
41
47
|
if (result.errcode) throw new Error(result.errmsg)
|
|
42
48
|
|
|
43
|
-
cache.set(
|
|
49
|
+
cache.set(appid, result.access_token)
|
|
44
50
|
return result.access_token
|
|
45
51
|
}
|
|
46
52
|
|
|
@@ -12,8 +12,7 @@ const util = require('util')
|
|
|
12
12
|
const axios = require('axios')
|
|
13
13
|
const crypto = require('crypto')
|
|
14
14
|
const { lodash, ServiceError } = require('q-koa')
|
|
15
|
-
const getAccessTokenUrl =
|
|
16
|
-
'https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s'
|
|
15
|
+
const getAccessTokenUrl = 'https://api.weixin.qq.com/cgi-bin/stable_token'
|
|
17
16
|
const getPhoneNumberUrl =
|
|
18
17
|
'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s'
|
|
19
18
|
const createQRCodeUrl =
|
|
@@ -173,14 +172,20 @@ module.exports = class Singleton {
|
|
|
173
172
|
return this
|
|
174
173
|
}
|
|
175
174
|
|
|
176
|
-
async getAccessToken() {
|
|
177
|
-
const { appid, secrect
|
|
178
|
-
if (cache.get(appid)) {
|
|
175
|
+
async getAccessToken(force_refresh = false) {
|
|
176
|
+
const { appid, secrect } = this.config
|
|
177
|
+
if (!force_refresh && cache.get(appid)) {
|
|
179
178
|
return cache.get(appid)
|
|
180
179
|
}
|
|
181
|
-
const
|
|
180
|
+
const result = await wxAxios
|
|
181
|
+
.post(getAccessTokenUrl, {
|
|
182
|
+
grant_type: 'client_credential',
|
|
183
|
+
appid,
|
|
184
|
+
secret: secrect,
|
|
185
|
+
force_refresh,
|
|
186
|
+
})
|
|
187
|
+
.then((res) => res.data)
|
|
182
188
|
|
|
183
|
-
const result = await wxAxios.get(url).then((res) => res.data)
|
|
184
189
|
const { errcode, errmsg, access_token } = result
|
|
185
190
|
|
|
186
191
|
if (errcode) {
|