Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

客户端发送消息的时候 服务器没有反应, #249

Open
shuxuezhang opened this issue Sep 20, 2016 · 3 comments
Open

客户端发送消息的时候 服务器没有反应, #249

shuxuezhang opened this issue Sep 20, 2016 · 3 comments

Comments

@shuxuezhang
Copy link

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 生成的 求解。。。 谢主隆恩

@JacksonTian
Copy link
Member

确认绑定对了吗

@qingmuAdore
Copy link

我也是这个问题, 服务器已配置成功... 代码如下:

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);

@qingmuAdore
Copy link

问题解决了... 域名路径问题
app.use('/wechat', wechat('mytoken', function (req, res, next) {***});

微信服务器配置中不带 /wechat路径,代码修改为
app.use('/', wechat('mytoken', function (req, res, next) {***});
成功

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants