weixinConfig.js
3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Created by zhanghong on 15/3/8.
*/
function weixinOptionMenuInit(appId, timestamp, nonceStr, signature){
try {
// wwsDebug.info("appId:" + appId);
// wwsDebug.info("timestamp:" + timestamp);
// wwsDebug.info("nonceStr:" + nonceStr);
// wwsDebug.info("signature:" + signature);
// alert("typeof wx.config " + typeof wx.config);
// if (wx) {
/*wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: appId, // 必填,公众号的唯一标识
timestamp: timestamp, // 必填,生成签名的时间戳
nonceStr: nonceStr, // 必填,生成签名的随机串
signature: signature,// 必填,签名,见附录1
jsApiList: ['scanQRCode','getLocation'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.error(function(res){
layer.open({
content:"微信扫码功能不能用,无法使用扫码租车",
time:1
});
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
});
wx.ready(function(){
// alert('wx ready')
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
wx.checkJsApi({
jsApiList: ['scanQRCode','getLocation'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function(res) {
if(res.checkResult.scanQRCode != true){
layer.open({
content: '您的微信版本太低,不支持扫码',
time:1
});
}
// 以键值对的形式返回,可用的api值true,不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
}
});
});*/
// }
}catch(exception){
// alert("exception " + exception)
layer.open({
content:"微信扫码功能异常,无法使用扫码租车",
time:1
});
}
}
function initWeixinMenu($http){
var url = encodeURIComponent(location.href.split('#')[0]);
//生产环境 wechat.api.dingdatech.com
$http.post("http://wechat.dy.dingdatech.com/wx/qrCodeParms",
{
webUrl : url
})
.success(function(data){
// alert(JSON.stringify(data) + ", with url : " + location.href.split('#')[0])
if(data){
// weixinOptionMenuInit(data.appid, data.timestamp, data.noncestr, data.signature);
}
})
.error(function(arg1){
try {
layer.open({
content:"微信jssdk配置接口失败:" + JSON.stringify(arg1),
time:1
});
}catch(e){
layer.open({
content:"微信jssdk配置接口失败:" + arg1,
time:1
});
}
// alert(arg1);
});
}