|
@@ -17,6 +17,7 @@ const maintainConst = require('../const/maintain');
|
|
|
const wxConst = require('../const/wechat_template.js');
|
|
|
const smsTypeConst = require('../const/sms_type');
|
|
|
const wxWork = require('../lib/wx_work');
|
|
|
+const { parseStringXml } = require('../lib/common');
|
|
|
|
|
|
module.exports = app => {
|
|
|
class WechatController extends app.BaseController {
|
|
@@ -48,6 +49,37 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
+ * 微信自动回复
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局页面
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async replyMessage(ctx) {
|
|
|
+ const xml = ctx.request.body;
|
|
|
+ try {
|
|
|
+ const {
|
|
|
+ createTime, msgType, toUserName, toFromName, event, msgContent,
|
|
|
+ } = await parseStringXml(xml);
|
|
|
+ let body = '';
|
|
|
+ if (msgType === 'text') {
|
|
|
+ const reply_msg = '如有问题需要咨询,请电话联系0756-3850888;或添加企业QQ:800003850。';
|
|
|
+ body = `
|
|
|
+ <xml>
|
|
|
+ <ToUserName><![CDATA[${toFromName}]]></ToUserName>
|
|
|
+ <FromUserName><![CDATA[${toUserName}]]></FromUserName>
|
|
|
+ <CreateTime>${createTime}</CreateTime>
|
|
|
+ <MsgType><![CDATA[text]]></MsgType>
|
|
|
+ <Content><![CDATA[${reply_msg}]]></Content>
|
|
|
+ <MediaId><![CDATA[media_id]]></MediaId>
|
|
|
+ </xml>
|
|
|
+ `;
|
|
|
+ }
|
|
|
+ ctx.body = body;
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
* 微信登录验证
|
|
|
*
|
|
|
* @param {Object} ctx - egg全局页面
|