-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
112 lines (99 loc) · 3.85 KB
/
index.html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WX-Demo</title>
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<script>
var time = Math.ceil(+new Date()/1000);
var nonceStr='';
for(var i=0;i<16;i++){
nonceStr+=String(Math.floor(Math.random()*10));
}
// var accessToken = getLocalMsg('accessToken');
// if(!accessToken || accessToken.expire_time<time){
// accessToken = setLocalMsg('accessToken',access_token);
// }
// var jsapiTicket = getLocalMsg('jsapiTicket');
// if(!jsapiTicket || jsapiTicket.expire_time<time){
// jsapiTicket = setLocalMsg('jsapiTicket',jsapi_ticket);
// }
getToken ();
// getTicket ();
console.log(time)
console.log(nonceStr)
wx.config({
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
// appId: 'wx25bcadab6332cd52', // 必填,公众号的唯一标识
// timestamp: time, // 必填,生成签名的时间戳
// nonceStr: nonceStr, // 必填,生成签名的随机串
// signature: '',// 必填,签名,见附录1
jsApiList: ["onMenuShareTimeline"] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.error(function (res) {
alert(res);
});
function getToken () {
// $.getJSON("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx25bcadab6332cd52&secret=d7d4b491902637445a2402713fcdca67&jsoncallback=?", function (data) {
// console.log(data)
// });
var url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
$.ajax({
url:url,
type:'GET',
dataType:'jsonp',
data:{'appid':'wx25bcadab6332cd52','secret':'d7d4b491902637445a2402713fcdca67'},
success:function(json){
eval(json);
}
})
}
function getTicket (result) {
console.log(result)
var url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
$.ajax({
url:url,
type:'GET',
dataType:'jsonp',
data:{'access_token':'TbwGRn7lQSU2Uybz-8to5Hr44T0fcghzm-HVcENCbUn3cPpJIW0n42nhCCan2_0k_8-AlxI5LJAo4JKKSBuE8AWIht6NVdzO9BePMEVcW6tK7q28BAt2a270oqtEpeaxZHRhAEACKU'},
// jsonp: "callback",
//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名
// jsonpCallback:"getTicket",
//成功获取跨域服务器上的json数据后,会动态执行这个callback函数
success:function(json){
console.log(json);
}
})
}
/*
储存信息到localStorage:
localName:储存在localStorage里的名称
obj:要储存的数据
*/
function setLocalMsg(localName,obj) {
localStorage.setItem(localName,JSON.stringify(obj)); //往本地存cartList这个数组(先将其转为字符串)
userName=JSON.parse(localStorage.getItem(localName)); //从本地取出 cartList这个数组并转为对象
// console.log(typeof cartList);
console.log(userName);
console.log(localStorage);
return userName;
// alert(localStorage.userName)
// localStorage.removeItem("userName");//清除userName的值
// localStorage.clear(); //批量删除数据
}
/*
获得储存的localStorage:
localName:储存在localStorage里的名称
*/
function getLocalMsg(localName) {
// localStorage.clear(); //批量删除数据
return JSON.parse(localStorage.getItem(localName)); //从本地取出 cartList这个数组并转为对象
// localStorage.removeItem("userName");//清除userName的值
// localStorage.clear(); //批量删除数据
}
</script>
</body>
</html>