q-koa 13.8.18 → 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.
package/core/app.js CHANGED
@@ -491,10 +491,13 @@ class APP {
491
491
 
492
492
  subscriber = client.duplicate()
493
493
  await subscriber.connect()
494
- push({
495
- appName,
496
- message: `${appName}连接redis成功,${this.config.ip}:${this.port}`,
497
- })
494
+
495
+ if (!is_dev) {
496
+ push({
497
+ appName,
498
+ message: `${appName}连接redis成功,${this.config.ip}:${this.port}`,
499
+ })
500
+ }
498
501
  } catch (e) {
499
502
  client = null
500
503
 
@@ -1,6 +1,6 @@
1
1
  const util = require('util')
2
2
  const axios = require('axios')
3
- const getAccessTokenUrl = `https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s`
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, grant_type } = this.config
36
- if (cache.get('access_token')) {
37
- return cache.get('access_token')
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 url = util.format(getAccessTokenUrl, grant_type, appid, secrect)
40
- const result = await axios.get(url).then((res) => res.data)
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('access_token', result.access_token)
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, grant_type } = this.config
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 url = util.format(getAccessTokenUrl, grant_type, appid, secrect)
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.8.18",
3
+ "version": "13.8.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {