wx is not defined
来源:5-9 第五天 微信 JS-SDK-使用微信官方的WEB调试工具
慕村4893497
2017-06-12
总是报错wx is not defined.
app.js如下,是不是js之间版本冲突?该如何解决呢
'use strict'
var Koa = require('koa')
var path = require('path')
var util = require('./libs/util')
var config = require('./config')
var wechat = require('./wechat/g')
var reply = require('./wx/reply')
var Wechat = require('./wechat/wechat')
var ejs = require('ejs')
var crypto = require('crypto')
var heredoc = require('heredoc')
// var wechat_file = path.join(__dirname,'/config/wechat.txt')
var app = new Koa()
var tpl = heredoc(function(){/*
<!DOCTYPE html>
<html>
<head>
<title>猜电影</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,minimum-scale=1">
</head>
<body>
<h1>点击标题,开始录音翻译</h1>
<p id="title"></p>
<div id="poster"></div>
<script scr="http://zeptojs.com/zepto-docs.min.js"></script>
<script scr="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
wx.config({
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: 'wxb475538ffa192fce', // 必填,公众号的唯一标识
timestamp: '<%= timestamp%>', // 必填,生成签名的时间戳
nonceStr: '<%= noncestr%>', // 必填,生成签名的随机串
signature: '<%= signature%>',// 必填,签名,见附录1
jsApiList: [
'startRecord',
'stopRecord',
'onVoiceRecordEnd',
'translateVoice'
] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
})
</script>
</body>
</html>
*/})
app.use(function *(next){
if(this.url.indexOf('/movie')>-1){
var wechatAapi = new Wechat(config.wechat)
var data = yield (wechatAapi.fetchAccessToken())
var access_token = data.access_token
var ticketData = yield (wechatAapi.fetchTicket(access_token))
var ticket = ticketData.ticket
var url = this.href
var params = sign(ticket,url)
console.log(params)
this.body = ejs.render(tpl,params)
return next
}
yield (next)
})
var createNonce = function(){
return Math.random().toString(36).substr(2,15)
}
var createTimestamp = function(){
return parseInt(new Date().getTime()/1000,10) +''
}
var _sign = function(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')
}
function sign(ticket,url){
var noncestr = createNonce()
var timestamp = createTimestamp()
var signature = _sign(noncestr,ticket,timestamp,url)
console.log(ticket)
console.log(url)
return {
noncestr :noncestr,
timestamp :timestamp,
signature:signature
}
}
app.use(wechat(config.wechat,reply.reply))
app.listen(8088)
console.log('Listening: 8088')
1回答
-
Scott
2017-06-13
那把这个 jweixin 先移出去,然后 script 里面,打印下 wx 这个变量,看看有没有被微信注入这个脚本,这个报错是挺古怪
00
相似问题