客户端发送消息的时候 服务器没有反应,
app.js ` app.use(express.query()); app.use('/wechat', wechat(config, function (req, res, next) { // 微信输入信息都在req.weixin上 var message = req.weixin; if (message.FromUserName === '屌丝') { // 回复屌丝(普通回复) res.reply('hehe'); } else if (message.FromUserName === 'text') { //你也可以这样回复text类型的信息 res.reply({ content: 'text object', type: 'text' }); } else if (message.FromUserName === '呵呵') { // 回复一段音乐 res.reply({ type: "music", content: { title: "来段音乐吧", description: "一无所有", musicUrl: "http://mp3.com/xx.mp3", hqMusicUrl: "http://mp3.com/xx.mp3", thumbMediaId: "thisThumbMediaId" } }); } else { // 回复高富帅(图文回复) res.reply([ { title: '你来我家接我吧', description: '这是女神与高富帅之间的对话', picurl: 'http://nodeapi.cloudfoundry.com/qrcode.jpg', url: 'http://nodeapi.cloudfoundry.com/' } ]); } }));
app.listen(7500,function(){
console.log('listen 7500')
})
下面验证服务器 没问题 7500 和 80 端口绑定了 routes/index.js
router.get('/', function(req, res, next) {
console.log(req.url)
var query = req.query;
var signature = query.signature;
var echostr = query.echostr;
var timestamp = query['timestamp'];
var nonce = query.nonce;
var oriArray = new Array();
oriArray[0] = nonce;
oriArray[1] = timestamp;
oriArray[2] = "tujiaowechat";//这里是你在微信开发者中心页面里填的token,而不是****
oriArray.sort();
var original = oriArray.join('');
console.log("Original str : " + original);
console.log("Signature : " + signature );
var scyptoString = sha1(original);
if(signature == scyptoString){
res.end(echostr);
console.log("Confirm and send echo back");
}else {
res.end("false");
console.log("Failed!");
}
}); ` 接口配置也成功了 http://xxxx:7500 没问题 但是发送消息没有反应 项目是用express-generate 生成的 求解。。。 谢主隆恩
确认绑定对了吗
我也是这个问题, 服务器已配置成功... 代码如下:
var express = require('express'); var app = express(); var wechat = require('wechat'); app.use(express.query()); app.use('/wechat', wechat('mytoken', function (req, res, next) { // 微信输入信息都在req.weixin上 var message = req.weixin; if (message.FromUserName === 'diaosi') { // 回复屌丝(普通回复) res.reply('hehe'); } else if (message.FromUserName === 'text') { //你也可以这样回复text类型的信息 res.reply({ content: 'text object', type: 'text' }); } else if (message.FromUserName === 'hehe') { // 回复一段音乐 res.reply({ type: "music", content: { title: "来段音乐吧", description: "一无所有", musicUrl: "http://mp3.com/xx.mp3", hqMusicUrl: "http://mp3.com/xx.mp3", thumbMediaId: "thisThumbMediaId" } }); } else { // 回复高富帅(图文回复) res.reply([ { title: '你来我家接我吧', description: '这是女神与高富帅之间的对话', picurl: 'http://nodeapi.cloudfoundry.com/qrcode.jpg', url: 'http://nodeapi.cloudfoundry.com/' } ]); } }));
app.listen(80);
问题解决了... 域名路径问题 app.use('/wechat', wechat('mytoken', function (req, res, next) {***});
微信服务器配置中不带 /wechat路径,代码修改为
app.use('/', wechat('mytoken', function (req, res, next) {***});
成功