guhongwei 4 năm trước cách đây
mục cha
commit
fbb4497c5a
1 tập tin đã thay đổi với 37 bổ sung37 xóa
  1. 37 37
      app/controller/weixin.js

+ 37 - 37
app/controller/weixin.js

@@ -61,46 +61,46 @@ class WeixinController extends Controller {
     assert(code, 'code不能为空');
     assert(state, 'state不能为空');
     // console.log('code-->' + code);
-    console.log('code-->1' + code);
+    console.log('code-->' + code);
     const { weixin } = this.ctx.service;
-    let openid;
-    try {
-      ({ openid } = await weixin.fetch(code));
-    } catch (err) {
-      await this.ctx.render('error.njk', { title: err.message, message: err.details });
-      return;
-    }
-    console.log('code-->2' + code);
+    let openid  = await weixin.fetch(code));
+    // try {
+    //   ({ openid } = await weixin.fetch(code));
+    // } catch (err) {
+    //   await this.ctx.render('error.njk', { title: err.message, message: err.details });
+    //   return;
+    // }
+    console.log('code-->' + code);
     console.log('openid--->' + openid);
-    if (openid) {
-      const key = `visit:auth:state:${state}`;
-      const val = await this.app.redis.get(key);
-      const { redirect_uri, type, uid, qrcode } = JSON.parse(val);
-      // console.log('redirect_uri-->' + redirect_uri);
-      const user = await this.ctx.service.user.findByOpenid(openid);
-      if (type === '0') {
-        // 通过openid取得用户信息
-        if (user) {
-          const token = await this.ctx.service.login.createJwt(user);
-          const to_uri = urljoin(redirect_uri, `?token=${token}`);
-          // TODO: 重定性页面
-          // console.log('to_uri000-->' + to_uri);
-          this.ctx.redirect(to_uri);
+    // if (openid) {
+    //   const key = `visit:auth:state:${state}`;
+    //   const val = await this.app.redis.get(key);
+    //   const { redirect_uri, type, uid, qrcode } = JSON.parse(val);
+    //   // console.log('redirect_uri-->' + redirect_uri);
+    //   const user = await this.ctx.service.user.findByOpenid(openid);
+    //   if (type === '0') {
+    //     // 通过openid取得用户信息
+    //     if (user) {
+    //       const token = await this.ctx.service.login.createJwt(user);
+    //       const to_uri = urljoin(redirect_uri, `?token=${token}`);
+    //       // TODO: 重定性页面
+    //       // console.log('to_uri000-->' + to_uri);
+    //       this.ctx.redirect(to_uri);
 
-        } else {
-          // console.log('rrr0000--->' + redirect_uri);
-          const touri = `${this.app.config.baseUrl}/platmobile/live/index`;
-          const to_uri = urljoin(touri, `?openid=${openid}`);
-          // TODO: 重定性页面
-          this.ctx.redirect(to_uri);
-        }
-      } else if (type === '1') {
-        const to_uri = urljoin(redirect_uri, `?openid=${openid}&uid=${uid}&type=${type}&qrcode=${qrcode}`);
-        // TODO: 重定性页面
-        // console.log('1111---?' + to_uri);
-        this.ctx.redirect(to_uri);
-      }
-    }
+    //     } else {
+    //       // console.log('rrr0000--->' + redirect_uri);
+    //       const touri = `${this.app.config.baseUrl}/platmobile/live/index`;
+    //       const to_uri = urljoin(touri, `?openid=${openid}`);
+    //       // TODO: 重定性页面
+    //       this.ctx.redirect(to_uri);
+    //     }
+    //   } else if (type === '1') {
+    //     const to_uri = urljoin(redirect_uri, `?openid=${openid}&uid=${uid}&type=${type}&qrcode=${qrcode}`);
+    //     // TODO: 重定性页面
+    //     // console.log('1111---?' + to_uri);
+    //     this.ctx.redirect(to_uri);
+    //   }
+    // }
 
   }