wechat
wechat copied to clipboard
消息加解密方式 安全模式 失败
在公众号中设置安全模式或兼容模式都不能被动回复成功(text类型) 但是在微信公众平台接口调试工具调试是成功的。 通过运维中心看到的日志
请求表单数据(解密后)
无
没有遇见过不成功的情况
能复现方法么。
var app = express();
// set up handlebars view engine var handlebars = require('express3-handlebars').create({ defaultLayout:'main', helpers: { section: function(name, options){ if(!this._sections) this._sections = {}; this._sections[name] = options.fn(this); return null; } } }); app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.set('port', process.env.PORT || 3391);
app.use(express.static(__dirname + '/public'));
app.use(express.query());
app.use('/wechat', wechat(config, function (req, res, next) { // 微信输入信息都在req.weixin上 var message = req.weixin; console.log(message); if (message.MsgType === 'text') { if (message.Content === 'hello') { res.reply("你好"); } else { // 回复屌丝(普通回复) // res.reply('你好!'); res.reply({type: "text", content: 'Hello 好吧!'}); } } }));
// app.get('/', function(req, res) { // res.render('home'); // });
app.listen(app.get('port'), function(){ console.log( 'Express started on http://localhost:' + app.get('port') + '; press Ctrl-C to terminate.' ); });
用明文方式就是正常的
版本 "dependencies": { "express": "^4.14.0", "express3-handlebars": "^0.5.2", "wechat": "^2.0.3", "wechat-api": "^1.28.0", "weui": "^0.4.3" }
用了nginx跳转 server { listen 80; server_name weixin.********.com; root /home/webroot;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
access_log /var/log/nginx/weixin.log main;
error_log /var/log/nginx/weixin..error.log error;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.60:7890;
add_header Cache-Control no-cache;
}
}
我也碰到这问题了
确认参数传对了吗
只要修改为明文的就可以正常使用,参数没有问题 不知道是不是测试账号的问题?
@JacksonTian @tonyleecn 我用的是未认证的公众号,不是测试账号,也是这个问题
在配置服务器的时候根本就验证不了,就是根本没有回复微信服务器post过来的值。
我也遇到同样的问题。
知道原因了,问题发生在本地调试,post的data和server不同。本地只post了基本的消息xml,而实际wechat发过来的数据远不止这么多。 wechat/lib/wechat.js
var xml = formatMessage(result.xml);
var encryptMessage = xml.Encrypt; //这里本地调试的时候是undefined.
if (signature !== cryptor.getSignature(timestamp, nonce, encryptMessage)) {
res.writeHead(401);
res.end('Invalid signature');
return;
}
另外,wechat,wechat-api等几个lib非常棒,感谢作者。
遇到同样的问题. res.reply非空字符串以及其它,公众号直接报不能服务。 微信调试工具显示success. res.reply空字符串公众号,能正常不回复。