配置微信设置的时候,配置成功返回正确,但是打开这个地址运行2次返回signature均为undefined
来源:1-6 第一天 写段代码实现加密认证逻辑
 
			大丢
2017-04-01
输出内容:
配置成功后输出
sha = 63b7ad58d28ecb1a87da4de3e6be9eaa6e19f6bc signature = 63b7ad58d28ecb1a87da4de3e6be9eaa6e19f6bc
打开浏览器地址输出
sha = 9fa71d753282f94f85eca97d45811ce60ead189f signature = undefined sha = 9fa71d753282f94f85eca97d45811ce60ead189f signature = undefined
app.js 源码
app.use(
    function *(next){
            // console.log(this.query);
    
            var token = config.wechat.token;
            var signature = this.query.signature;
            var nonce = this.query.nonce;
            var timestamp = this.query.timestamp;
            var echostr = this.query.echostr;
            var str = [token, timestamp, nonce].sort().join('');
            var sha = sha1(str);
    
            console.log('str = ' + str);
            console.log('signature = ' + signature);
            
    
            if(sha === signature){
                this.body = echostr + '';
            }
            else {
                this.body = 'wrong';
            }
            
        }
)5回答
- 
				
				代码我目测没问题,你换一个其他的代理试试,怀疑这个代理转发时候丢包 032017-04-06
- 
				  Scott 2017-04-08 恩,先换一个代理试一下,代码我目测没问题 00
- 
				  Scott 2017-04-02 安装 koa 的时候用老的版本 npm i koa@1.2.0 --save 然后重新跑一下试试 032017-04-04
- 
				  Hero_Tan 2017-04-08 同学,如果是代理,我推荐用这个 https://www.ngrok.cc/ 00
- 
				  PanameraTurboS 2017-04-04 回复 Scott:'use strict' var Koa = require('koa'); var sha1 = require('sha1'); var config = { wechat: { appID: 'wx46394103d21ddd67', appSecret: 'd5f43a9f10eb6e4eca061163eab7288f', token: 'xiewechatproject' } } var app = new Koa(); app.use(function *(next) { console.log('url=' + this.url); console.log('href' + this.href); console.log(this.query); var token = config.wechat.token; var signature = this.query.signature; var nonce = this.query.nonce; var timestamp = this.query.timestamp; var echostr = this.query.echostr; var str = [token, timestamp, nonce].sort().join(''); var sha = sha1(str); console.log('sha=' + sha); console.log('signature=' + signature); if (sha === signature) { this.body = echostr + ''; } else { this.body = 'wrong'; } }) app.listen(1234) console.log('Listening: 1234') 说明:node版本为6.9.2 系统为macOS Sierra 10.12.3 暴露到外网用的是:localtunnel。 koa版本:看了老师在另外一个问题的回复,所以新版本和旧版本都尝试过,不知道是不是localtunnel的问题,如果还是不行,打算尝试一下其他工具。 00
相似问题
 
						 
						