فهرست منبع

微信和短信审批发送bug修复

laiguoran 4 سال پیش
والد
کامیت
8cdc8f62f8
5فایلهای تغییر یافته به همراه47 افزوده شده و 40 حذف شده
  1. 23 18
      app/controller/wechat_controller.js
  2. 2 1
      app/lib/wechat.js
  3. 1 1
      app/middleware/wechat_auth.js
  4. 7 6
      app/router.js
  5. 14 14
      app/service/stage_audit.js

+ 23 - 18
app/controller/wechat_controller.js

@@ -12,6 +12,8 @@ const moment = require('moment');
 // const Controller = require('egg').Controller;
 const crypto = require('crypto');
 const maintainConst = require('../const/maintain');
+const wxConst = require('../const/wechat_template.js');
+const smsTypeConst = require('../const/sms_type');
 
 module.exports = app => {
     class WechatController extends app.BaseController {
@@ -172,27 +174,30 @@ module.exports = app => {
 
         async testwx(ctx) {
             try {
-                const sessionUser = ctx.session.sessionUser;
-                // 获取账号数据
-                const accountData = await ctx.service.projectAccount.getDataByCondition({ id: sessionUser.accountId });
-                // 解绑成功通知
-                const templateId = 'gsYUIt5CFY1uJQhiqnkhu38yi0adkZtEH9fGI49g_Lk';
-                const url = '';
-                const msgData = {
-                    first: {
-                        value: '你已成功与纵横云计量帐号解除绑定',
-                    },
-                    keyword1: {
-                        value: sessionUser.account,
+                const sck = 'https://scn.ink/';
+                // 微信模板通知
+                const tender = {
+                    data: {
+                        name: 'XXX标段',
                     },
-                    keyword2: {
-                        value: '项目编号' + ctx.session.sessionProject.code + ' 账号' + sessionUser.account + ' 解绑成功',
-                    },
-                    remark: {
-                        value: '欢迎使用纵横云计量,我们竭诚为您服务。',
+                    info: {
+                        deal_info: {
+                            buildName: 'XX项目',
+                        },
                     },
                 };
-                await app.wechat.api.sendTemplate(accountData.wx_openid, templateId, url, '', msgData);
+                ctx.tender = tender;
+                const stageInfo = await ctx.service.stage.getDataById(1704);
+                const shenpiUrl = await ctx.helper.urlToShort(ctx.protocol + '://' + ctx.host + '/wap/tender/1998/stage/' + stageInfo.order);
+                const wechatData = {
+                    wap_url: sck + shenpiUrl,
+                    qi: stageInfo.order,
+                    status: wxConst.status.success,
+                    tips: wxConst.tips.success,
+                    code: 'P1002',
+                };
+                // ctx.body = { tender, wechatData };
+                await ctx.helper.sendWechat(133, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), wxConst.template.stage, wechatData);
                 ctx.body = 'success';
             } catch (error) {
                 console.log(error);

+ 2 - 1
app/lib/wechat.js

@@ -38,7 +38,8 @@ class WX {
         try {
             // 解绑成功通知
             const templateId = template;
-            const url = this.ctx.request.header.host + '/wx/url2wap?project=' + data.code + '&url=' + data.wap_url;
+            const sck = 'https://scn.ink/';
+            const url = this.ctx.protocol + '://' + this.ctx.host + '/wx/url2wap?project=' + data.code + '&url=' + sck + data.wap_url;
             for (const openid of wx_openid) {
                 if (template === wxConst.template.stage) {
                     const msgData = {

+ 1 - 1
app/middleware/wechat_auth.js

@@ -16,7 +16,7 @@ module.exports = (options, app) => {
             }
             const wechatToken = ctx.session.wechatToken;
             if (!wechatToken) {
-                ctx.redirect('/wx/oauth?redirect_uri=' + encodeURIComponent(ctx.request.header.host + ctx.request.url));
+                ctx.redirect('/wx/oauth?redirect_uri=' + encodeURIComponent(ctx.protocol + '://' + ctx.host + ctx.request.url));
                 return;
             }
             // 同步系统维护信息

+ 7 - 6
app/router.js

@@ -376,10 +376,11 @@ module.exports = app => {
     app.post('/wap/tender/:id/change/approval', sessionAuth, tenderCheck, 'wapController.changeApproval')
 
     // 微信
-    app.get('/wx', 'wechatController.index')
-    app.get('/wx/oauth', 'wechatController.oauth')
-    app.get('/wx/bind', wechatAuth, 'wechatController.bind')
-    app.post('/wx/bindwx', wechatAuth, 'wechatController.bindwx')
-    app.get('/wx/test', wechatAuth, 'wechatController.testwx')
-    app.get('/MP_verify_t3MkWAMqplVxPjmr.txt', 'wechatController.oauthTxt')
+    app.get('/wx', 'wechatController.index');
+    app.get('/wx/oauth', 'wechatController.oauth');
+    app.get('/wx/bind', wechatAuth, 'wechatController.bind');
+    app.post('/wx/bindwx', wechatAuth, 'wechatController.bindwx');
+    app.get('/wx/url2wap', wechatAuth, 'wechatController.url2wap');
+    app.get('/wx/test', 'wechatController.testwx');
+    app.get('/MP_verify_t3MkWAMqplVxPjmr.txt', 'wechatController.oauthTxt');
 }

+ 14 - 14
app/service/stage_audit.js

@@ -281,7 +281,7 @@ module.exports = app => {
                 //     }
                 // }
                 const stageInfo = await this.ctx.service.stage.getDataById(audit.sid)
-                const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
                 await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
                     qi: stageInfo.order,
                     code: shenpiUrl
@@ -295,7 +295,7 @@ module.exports = app => {
                     tips: wxConst.tips.check,
                     code: this.ctx.session.sessionProject.code,
                 };
-                this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
+                await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
 
                 // todo 更新标段tender状态 ?
                 await transaction.commit()
@@ -393,7 +393,7 @@ module.exports = app => {
                     //     }
                     // }
                     const stageInfo = await this.ctx.service.stage.getDataById(nextAudit.sid)
-                    const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                    const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
                     await this.ctx.helper.sendAliSms(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
                         qi: stageInfo.order,
                         code: shenpiUrl
@@ -406,7 +406,7 @@ module.exports = app => {
                         tips: wxConst.tips.check,
                         code: this.ctx.session.sessionProject.code,
                     };
-                    this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
+                    await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
                 } else {
                     // 本期结束
                     // 生成截止本期数据 final数据
@@ -453,14 +453,14 @@ module.exports = app => {
                     //     const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,审批通过。';
                     //     sms.send(mobile_array, content);
                     // }
-                    const users = this._.pull(this._.map(auditList, 'aid'), stageInfo.user_id)
+                    const users = this._.uniq(this._.concat(this._.map(auditList, 'aid'), stageInfo.user_id));
                     await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, {
                         qi: stageInfo.order,
                         status: SmsAliConst.status.success
                     });
 
                     // 微信模板通知
-                    const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                    const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
                     const wechatData = {
                         wap_url: shenpiUrl,
                         qi: stageInfo.order,
@@ -468,7 +468,7 @@ module.exports = app => {
                         tips: wxConst.tips.success,
                         code: this.ctx.session.sessionProject.code,
                     };
-                    this.ctx.helper.sendWechat(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), wxConst.template.stage, wechatData);
+                    await this.ctx.helper.sendWechat(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), wxConst.template.stage, wechatData);
                 }
                 await transaction.commit()
             } catch (err) {
@@ -586,13 +586,13 @@ module.exports = app => {
                 //     const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,审批退回。';
                 //     sms.send(mobile_array, content);
                 // }
-                const users = this._.pull(this._.map(auditList, 'aid'), stageInfo.user_id)
+                const users = this._.uniq(this._.concat(this._.map(auditList, 'aid'), stageInfo.user_id));
                 await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, {
                     qi: stageInfo.order,
                     status: SmsAliConst.status.back
                 });
                 // 微信模板通知
-                const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
                 const wechatData = {
                     wap_url: shenpiUrl,
                     qi: stageInfo.order,
@@ -600,7 +600,7 @@ module.exports = app => {
                     tips: wxConst.tips.back,
                     code: this.ctx.session.sessionProject.code,
                 };
-                this.ctx.helper.sendWechat(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), wxConst.template.stage, wechatData);
+                await this.ctx.helper.sendWechat(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), wxConst.template.stage, wechatData);
 
                 await transaction.commit()
             } catch (err) {
@@ -736,7 +736,7 @@ module.exports = app => {
                 //     }
                 // }
                 const stageInfo = await this.ctx.service.stage.getDataById(audit.sid)
-                const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
                 await this.ctx.helper.sendAliSms(preAuditor.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
                     qi: stageInfo.order,
                     code: shenpiUrl
@@ -749,7 +749,7 @@ module.exports = app => {
                     tips: wxConst.tips.check,
                     code: this.ctx.session.sessionProject.code,
                 };
-                this.ctx.helper.sendWechat(preAuditor.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
+                await this.ctx.helper.sendWechat(preAuditor.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
 
                 await transaction.commit()
             } catch (err) {
@@ -872,7 +872,7 @@ module.exports = app => {
                 //     }
                 // }
                 const stageInfo = await this.ctx.service.stage.getDataById(audit.sid)
-                const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
                 await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
                     qi: stageInfo.order,
                     code: shenpiUrl
@@ -885,7 +885,7 @@ module.exports = app => {
                     tips: wxConst.tips.check,
                     code: this.ctx.session.sessionProject.code,
                 };
-                this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
+                await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
 
                 await transaction.commit()
             } catch (err) {