js代碼以下:javascript
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
var
app = {};
app.appId=
""
;
app.jsApiTicket=
""
;
app.sign =
""
;
app.nonceStr=
""
;
app.timeStamp=
""
;
app.func={};
var
logoUrl =
"http://ysj.weilaila.com:8080/demo/img/baby_logo.jpg"
;
//生成隨機字符串
app.func.createRandomStr=
function
(num){
var
s =
"0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
;
var
r = [];
var
x = s.split(
""
);
for
(
var
i = 0; i<num; i++){
var
random = parseInt(Math.random()*62);
r.push(x[random]);
}
return
r.join(
""
);
};
app.func.getUrl =
function
(){
return
location.href.split(
"#"
)[0];
}
//獲得js api 接口憑證
app.func.getConfigInfo=
function
(){
$.ajax({
type:
"POST"
,
url:
"user/getjsapisign.jhtml"
,
data:{
url:app.func.getUrl(),
nonceStr:app.func.createRandomStr()
},
async:
false
,
success:
function
(data){
if
(data.status==
"ok"
){
app.jsApiTicket = data.jsApiTicket;
app.appId=data.appId;
app.sign=data.sign;
app.nonceStr = data.nonceStr;
app.timeStamp = data.timeStamp;
app.func.wxconfig();
}
else
{
window.location.reload();
}
},
error:
function
(){
alert(
"網絡出錯,請檢查你的網絡"
);
window.location.reload();
}
});
};
/*//生成時間戳
app.func.createTimeStamp=function(){
return Date.parse(new Date())/1000;
};*/
/*//生成簽名
app.func.createSign=function(obj){
var str="";
var param = ['jsapi_ticket','noncestr','timestamp','url'];
param.sort();
for(var i = 0; i<param.length;i++){
str+=param[i]+"="+obj[param[i]];
if(i!=param.length-1){
str+="&"
}
}
console.log(str);
return CryptoJS.SHA1(str).toString();
}*/
app.func.wxconfig =
function
(){
wx.config({
debug:
false
,
appId:app.appId,
timestamp:app.timeStamp,
nonceStr:app.nonceStr,
signature:app.sign,
jsApiList:[
'onMenuShareTimeline'
,
'onMenuShareAppMessage'
,
'hideOptionMenu'
,
'showOptionMenu'
,
'hideMenuItems'
,
'showMenuItems'
,
'closeWindow'
]
});
wx.ready(
function
(){
wx.checkJsApi({
jsApiList:[
'onMenuShareTimeline'
,
'onMenuShareAppMessage'
],
success:
function
(res){
if
(!res.checkResult.onMenuShareAppMessage||!res.checkResult.onMenuShareTimeline){
alert(
'你的微信客戶端不支持JSSDK,請升級你的客戶端'
);
}
}
});
//*********這裏的這些值,能夠寫死。******************
wx.onMenuShareTimeline({
title:
'長得好看的人都來參加花式裹孩紙大賽了,贏取IPHONE6S,不服來戰!'
,
//分享標題
link:
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxec524716a0216797&redirect_uri=http%3a%2f%2fysj.weilaila.com%3a8080%2fdemo%2findex.jhtml&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
,//分享連接
imgUrl:logoUrl,
//
type:
'link'
,
//type是music或者video,link
success:
function
(){
//如下是給用戶加積分的函數請求
addNum();
}
});
wx.onMenuShareAppMessage({
title:
'長得好看的人都來參加花式裹孩紙大賽了,贏取IPHONE6S,不服來戰!'
,
desc:
'聽說只要眼疾手快,你就能夠贏得大獎,走向人生巔峯'
,
//分享描述
link:
'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxec524716a0216797&redirect_uri=http%3a%2f%2fysj.weilaila.com%3a8080%2fdemo%2findex.jhtml&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
,
imgUrl:logoUrl,
success:
function
(){
addNum();
}
});
function
addNum(num){
var
addscroe = 5;
$.ajax({
type:
"POST"
,
data:{
score:addscroe,
type:1
},
url:
"user/addscore.jhtml"
,
async:
true
,
success:
function
(data){
alert(
"分享成功!"
);
if
(data.error)
window.location.href =
"index/rank.jhtml?score=0"
;
else
window.location.href =
"index/rank.jhtml?score="
+addscroe;
},
error:
function
(){
alert(
'抱歉,網絡出錯,請從新分享'
);
}
});
}
});
}
app.func.getConfigInfo();
|
1
2
|
if
(location.search)
location.href=location.origin+location.pathname;
|