掉进坑里面了{"errMsg":"config:invalid signature"},调试两天了过不去
来源:5-9 第五天 微信 JS-SDK-使用微信官方的WEB调试工具
Brouce
2016-09-18
不知道哪里出错了,debug出的值也都有
var createNoce = function() { return Math.random().toString(36).substr(2,15) } var createTimestamp = function(){ return parseInt(new Date().getTime() / 1000,10) + '' } function _sign(noncestr,ticket,timestamp,url){ var params = [ 'noncestr=' + noncestr, 'jsapi_ticket=' + ticket, 'timestamp=' +timestamp, 'url'+url ] var str = params.sort().join("&") var shasum = crypto.createHash('sha1') shasum.update(str) return shasum.digest('hex') } // noncestr=Wm3WZYTPz0wzccnW // jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg // timestamp=1414587457 // url=http://mp.weixin.qq.com?params=value function sign(ticket,url) { var noncestr = createNoce(); var timestamp = createTimestamp(); console.log(noncestr) var signature = _sign(noncestr,ticket,timestamp,url) console.log(ticket) console.log(url) console.log(signature) return { noncestr:noncestr, timestamp:timestamp, signature:signature } } app.use(function *(next){ if(this.url.indexOf('/movie')> -1) { var wechatApi = new Wechat(config.wechat) var data = yield wechatApi.fetchAccessToken() var access_token = data.access_token var ticketData = yield wechatApi.fetchTicket(access_token) var ticket = ticketData.ticket var url = this.href var params = sign(ticket,url) params.appId = config.wechat.appId this.body = ejs.render(tpl,params) return next } yield next })
输出的信息是
h2h6vy9ad4r0ms4
kgt8ON7yVITDhtdwci0qecBfhXJw7pqsXVhmJXCLhG9iaOp93d1z6m-zmGDVuBoR8Ukhm1RT4hYuXOAr6t8GLQ
http://wx.v-life.cn/movie/index
1a78cbdf34644916f8bed2f9be37c1f8efb050ad
写回答
2回答
-
特意换windows回复:
```
var params = [
'noncestr=' + noncestr,
'jsapi_ticket=' + ticket,
'timestamp=' +timestamp,
'url'+url // 这少写个等号 params里只要一个参数有错都会报 invalid signature
]
```
012016-10-10 -
Brouce
提问者
2016-09-21
老师可以帮忙看看吗?卡在这里四天了,实在搞不懂不知道哪里出错了
00
相似问题