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

消息加解密方式 安全模式 失败 #243

Open
tonyleecn opened this issue Jul 27, 2016 · 12 comments
Open

消息加解密方式 安全模式 失败 #243

tonyleecn opened this issue Jul 27, 2016 · 12 comments

Comments

@tonyleecn
Copy link

在公众号中设置安全模式或兼容模式都不能被动回复成功(text类型)
但是在微信公众平台接口调试工具调试是成功的。
通过运维中心看到的日志

请求表单数据(解密后)

1469610839 6311930491764374545
被动回复内容

1469610775634
被动回复内容(解密后)

@JacksonTian
Copy link
Member

没有遇见过不成功的情况

@JacksonTian
Copy link
Member

能复现方法么。

@tonyleecn
Copy link
Author

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.' );
});

@tonyleecn
Copy link
Author

tonyleecn commented Jul 27, 2016

用明文方式就是正常的

版本
"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;
}

}

@atjiu
Copy link

atjiu commented Aug 27, 2016

我也碰到这问题了

@JacksonTian
Copy link
Member

确认参数传对了吗

@tonyleecn
Copy link
Author

只要修改为明文的就可以正常使用,参数没有问题
不知道是不是测试账号的问题?

@atjiu
Copy link

atjiu commented Aug 30, 2016

@JacksonTian @tonyleecn 我用的是未认证的公众号,不是测试账号,也是这个问题

@szwork2013
Copy link

在配置服务器的时候根本就验证不了,就是根本没有回复微信服务器post过来的值。

@jarvisji
Copy link

jarvisji commented Apr 8, 2017

我也遇到同样的问题。

@jarvisji
Copy link

jarvisji commented Apr 8, 2017

知道原因了,问题发生在本地调试,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非常棒,感谢作者。

@wyvern92
Copy link

遇到同样的问题. res.reply非空字符串以及其它,公众号直接报不能服务。
微信调试工具显示success.
res.reply空字符串公众号,能正常不回复。

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

6 participants