liuyu пре 5 година
родитељ
комит
74a3586bcf
3 измењених фајлова са 24 додато и 3 уклоњено
  1. 8 0
      app/controller/weixin.js
  2. 2 0
      app/router.js
  3. 14 3
      app/service/login.js

+ 8 - 0
app/controller/weixin.js

@@ -103,6 +103,10 @@ class WeixinController extends Controller {
         const to_uri = urljoin(redirect_uri, `?openid=${openid}&uid=${uid}&type=${_type}`);
         // TODO: 重定性页面
         this.ctx.redirect(to_uri);
+      } else if (type === '2') {
+        const to_uri = urljoin(redirect_uri, `?openid=${openid}&type=${type}`);
+        // TODO: 重定性页面
+        this.ctx.redirect(to_uri);
       }
     }
 
@@ -142,6 +146,10 @@ class WeixinController extends Controller {
       const to_uri = urljoin(redirect_uri, `?openid=${openid}&uid=${uid}&type=${_type}`);
       // TODO: 重定性页面
       this.ctx.redirect(to_uri);
+    } else if (type === '2') {
+      const to_uri = urljoin(redirect_uri, `?openid=${openid}&type=${type}`);
+      // TODO: 重定性页面
+      this.ctx.redirect(to_uri);
     }
   }
 }

+ 2 - 0
app/router.js

@@ -147,6 +147,8 @@ module.exports = app => {
 
   // pc端登录
   router.post('/api/train/login', controller.login.login);// 登录
+  // 微信端登录
+  router.post('/api/train/wxlogin', controller.login.wxlogin);// 登录
 
   // 评分表设置路由
   router.resources('score', '/api/train/score', controller.score); // index、create、show、destroy

+ 14 - 3
app/service/login.js

@@ -69,13 +69,24 @@ class LoginService extends CrudService {
     const { openid } = data;
     assert(openid, 'openid不能为空');
     const res = await this.uModel.findOne({ openid });
-    let newdata = {};
     if (!res) {
       throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    const result = await this.createJwt(res);
+    const { mq } = this.ctx;
+    if (mq) {
+      const msg = res.name + '微信登录成功';
+      const parm = {
+        durable: true,
+        headers: {
+          token: result,
+        } };
+      console.log(parm);
+      console.log(msg);
+      await mq.topic('wx_login', res.id, msg, parm);
     } else {
-      newdata = { id: res.id, name: res.name, openid: res.openid, type: res.type };
+      this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
     }
-    return await newdata;
   }
 }
 module.exports = LoginService;