lrf402788946 4 years ago
parent
commit
5eb202d2eb
1 changed files with 9 additions and 8 deletions
  1. 9 8
      app/service/weixin.js

+ 9 - 8
app/service/weixin.js

@@ -47,14 +47,15 @@ class WeixinAuthService extends AxiosService {
     const { code, state } = query;
     if (!code) throw new BusinessError(ErrorCode.SERVICE_FAULT, '授权未成功');
     const { appid, appSecret } = this.wxInfo;
-    const url = 'https://api.weixin.qq.com/sns/oauth2/access_token';
-    const params = {
-      appid,
-      secret: appSecret,
-      code,
-      grant_type: 'authorization_code',
-    };
-    const req = await this.httpGet(url, params);
+    // const url = 'https://api.weixin.qq.com/sns/oauth2/access_token';
+    // const params = {
+    //   appid,
+    //   secret: appSecret,
+    //   code,
+    //   grant_type: 'authorization_code',
+    // };
+    // const req = await this.httpGet(url, params);
+    const req = await this.httpGet('/api/fetch', { code });
     if (req.errcode && req.errcode !== 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, 'openid获取失败');
     const openid = _.get(req, 'openid');
     const access_token = await this.app.redis.get(this.access_tokenKey);