liuyu 4 år sedan
förälder
incheckning
de2ae4a918
2 ändrade filer med 8 tillägg och 10 borttagningar
  1. 4 4
      app/controller/weixin.js
  2. 4 6
      app/service/weixin.js

+ 4 - 4
app/controller/weixin.js

@@ -25,7 +25,7 @@ class WeixinController extends Controller {
   //       store - 默认,认证结果写入sessionStore,然后重定向回请求页面(要求请求页面和认证服务在同一域名下)
   //       token - url带上token参数重定向到原始地址
   async auth() {
-    const { redirect_uri, code, test, type, response_type = 'store', uid, qrcode } = this.ctx.query;
+    const { redirect_uri, code, test, type, response_type = 'store', uid, qrcode, msgid, objid } = this.ctx.query;
     if (test) {
       return await this.authTest();
     }
@@ -43,7 +43,7 @@ class WeixinController extends Controller {
     // TODO: 保存原始请求地址
     const state = uuid();
     const key = `visit:auth:state:${state}`;
-    const val = JSON.stringify({ redirect_uri, type, uid, qrcode });
+    const val = JSON.stringify({ redirect_uri, type, uid, qrcode, msgid, objid });
     await this.app.redis.set(key, val, 'EX', 600);
 
     // TODO: 生成回调地址
@@ -77,7 +77,7 @@ class WeixinController extends Controller {
     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);
+      const { redirect_uri, type, uid, qrcode, msgid, objid } = JSON.parse(val);
       console.log('redirect_uri-->' + redirect_uri);
       const user = await this.ctx.service.user.findByOpenid(openid);
       console.log('type-->' + type);
@@ -127,7 +127,7 @@ class WeixinController extends Controller {
       } else if (type === '9') {
         if (user) {
           const token = await this.ctx.service.login.createJwt(user);
-          const to_uri = urljoin(redirect_uri, `?openid=${openid}&type=${type}&token=${token}`);
+          const to_uri = urljoin(redirect_uri, `?openid=${openid}&type=${type}&token=${token}&msgid=${msgid}&objid=${objid}`);
           // TODO: 重定性页面
           console.log('99999---?' + to_uri);
           this.ctx.redirect(to_uri);

+ 4 - 6
app/service/weixin.js

@@ -186,14 +186,12 @@ class WeixinAuthService extends AxiosService {
     const url = this.ctx.app.config.sendDirMq + this.ctx.app.config.appid;
     let _url = '';
     if (tourl) {
-      _url = this.ctx.app.config.baseUrl + '/api/train/auth?state=1&redirect_uri=' + this.ctx.app.config.baseUrl + '/classinfo/&type=9&objid=' + tourl;
-      // 需要回执的时候进行保存处理
       // 通过openid取得用户基本信息
       const user = await this.ctx.model.User.findOne({ openid });
-      if (user) {
-        const newdata = { openid, name: user.name, title: first, detail: keyword1, date: keyword2, remark, status: '0' };
-        await this.ctx.model.Message.create(newdata);
-      }
+      const newdata = { openid, name: user.name, title: first, detail: keyword1, date: keyword2, remark, status: '0' };
+      const res = await this.ctx.model.Message.create(newdata);
+      // 需要回执的时候进行保存处理
+      _url = this.ctx.app.config.baseUrl + '/api/train/auth?state=1&redirect_uri=' + this.ctx.app.config.baseUrl + '/classinfo/&type=9&objid=' + tourl + '&msgid=' + res.id;
     }
     const requestData = { // 发送模板消息的数据
       touser: openid,