'use strict'
var ejs = require('ejs');
var heredoc = require('heredoc');
var tpl = heredoc(function(content){/*
<xml>
<ToUserName><![CDATA[<%= toUserName %>]]></ToUserName>
<FromUserName><![CDATA[<%= fromUserName %>]]></FromUserName>
<CreateTime><%= createTime%></CreateTime>
<MsgType><![CDATA[<%= msgType %>]]></MsgType>
<% if(msgType ==='text') { %>
<Content><![CDATA[<%= content %>]]></Content>
<% }else if(msgType ==='image'){ %>
<Image>
<MediaId><![CDATA[<%= content.mediaId %>]]></MediaId>
</Image>
<% }else if(msgType ==='voice'){ %>
<Voice>
<MediaId><![CDATA[<%= content.mediaId %>]]></MediaId>
</Voice>
<% } %>else if(msgType ==='video'){ %>
<Video>
<MediaId><![CDATA[<%= content.mediaId %>]]></MediaId>
<Title><![CDATA[<%= content.title %>]]></Title>
<Description><![CDATA[<%= content.description %>]]></Description>
</Video>
<% } %>else if(msgType ==='music'){ %>
<Music>
<Title><![CDATA[<%= content.title %>]]></Title>
<Description><![CDATA[<%= content.description %>]]></Description>
<MusicUrl><![CDATA[<%= content.musicUrl %>]]></MusicUrl>
<HQMusicUrl><![CDATA[<%= content.hqMusicUrl %>]]></HQMusicUrl>
<ThumbMediaId><![CDATA[<%= content.thumbMediaId %>]]></ThumbMediaId>
</Music>
<% } %>else if(msgType ==='news'){ %>
<ArticleCount><%= content.length %></ArticleCount>
<Articles>
<% content.forEach(function(item){ %>
<item>
<Title><![CDATA[<%= item.title %>]]></Title>
<Description><![CDATA[<%= item.description %>]]></Description>
<PicUrl><![CDATA[<%= item.picUrl %>]]></PicUrl>
<Url><![CDATA[<%= item.url %>]]></Url>
</item>
<% }) %>
</Articles>
<% } %>
</xml>
*/});
var compiled = ejs.compiled(tpl);
exports = module.exports = {
compiled:compiled
};
var message = util.formatMessage(content.xml);
this.weixin = message; //挂载消息
yield handler.call(this,next); //转到业务层逻辑
wechat.replay.call(this); //真正回复
var weixin = require('./weixin');
...
app.use(wechat(config.wechat,weixin.reply));
exports.reply = function* (next){
var message = this.weixin;
if(message.magType === 'event'){
if(message.Event === 'subscribe'){
if(message.EventKey) console.log('扫描二维码关注:'+message.EventKey+' '+message.ticket);
this.body = '终于等到你,还好我没放弃';
}else if(message.Event === 'unsubscribe'){
console.log(message.FromUserName +' 悄悄地走了...');
}
}else{
//
}
yield next;
}
Wechat.prototype.replay = function(){
var content = this.body;
var message = this.weixin;
var xml = util.tpl(content,message);
this.status = 200;
this.type = 'application/xml';
this.body = xml;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有