lrf402788946 4 年之前
父節點
當前提交
a69198e5ec
共有 1 個文件被更改,包括 3 次插入5 次删除
  1. 3 5
      app/service/weixin.js

+ 3 - 5
app/service/weixin.js

@@ -17,16 +17,14 @@ class WeixinAuthService extends AxiosService {
     this.prefix = 'visit-auth:';
     this.jsapiKey = 'visit-access_token';
     this.wxInfo = ctx.app.config.wxapi;
+    this.authBackUrl = `${ctx.app.config.baseUrl}/api/visit/authBack`;
   }
   /**
    * 网页授权
    * @param {Object} query 参数
    */
   async auth(query) {
-    let { redirect_uri, ...others } = query;
-    if (!redirect_uri) {
-      redirect_uri = `${this.ctx.app.config.baseUrl}/api/visit/authBack`;
-    }
+    const { redirect_uri, ...others } = query;
     const { appid } = this.wxInfo;
     if (!appid) {
       throw new BusinessError(ErrorCode.SERVICE_FAULT, '缺少公众号设置');
@@ -36,7 +34,7 @@ class WeixinAuthService extends AxiosService {
     const key = `${this.prefix}${state}`;
     const val = JSON.stringify({ ...others, redirect_uri });
     await this.app.redis.set(key, val, 'EX', 600);
-    const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=${state}#wechat_redirect`;
+    const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${this.authBackUrl}&response_type=code&scope=snsapi_base&state=${state}#wechat_redirect`;
     console.log(`url=>${url}`);
     this.ctx.redirect(url);
   }