lrf402788946 4 years ago
parent
commit
ef5be4c87f
1 changed files with 2 additions and 2 deletions
  1. 2 2
      app/service/weixin.js

+ 2 - 2
app/service/weixin.js

@@ -68,9 +68,9 @@ class WeixinAuthService extends AxiosService {
   async jsapiAuth(query) {
     const { url } = query;
     let jsapi_ticket = await this.app.redis.get(this.jsapiKey);
+    const { appid, appSecret } = this.wxInfo;
     if (!jsapi_ticket) {
       // 1,重新获取access_token
-      const { appid, appSecret } = this.wxInfo;
       const atUrl = `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${appSecret}`;
       const req = await this.ctx.curl(atUrl, { method: 'GET' });
       if (req.status !== 200) throw new BusinessError(ErrorCode.SERVICE_FAULT, 'access_token获取失败');
@@ -89,7 +89,7 @@ class WeixinAuthService extends AxiosService {
     const timestamp = new Date().getTime();
     const signStr = `jsapi_ticket=${jsapi_ticket}&noncestr=${noncestr}&timestamp=${timestamp}&url=${url}`;
     const sign = crypto.createHash('sha1').update(signStr).digest('hex');
-    return { jsapi_ticket, noncestr, timestamp, signStr, sign };
+    return { jsapi_ticket, noncestr, timestamp, signStr, sign, appid };
   }