wx_share.html
15.2 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<script type="text/javascript" src="__STATIC__/js/crypto23bc20.js"></script>
<!--正式环境要用https-->
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<input id="xlocation" value="" type="hidden"/>
<input id="ylocation" value="" type="hidden"/>
<script type="text/javascript">
var ShareTitle="";
var ShareDesc="";
var wxstoid="{$Think.request.stoid}";
var ShareImgUrl = "{:getImg($tpshop_config['shop_info_store_logo'])}";
var moddesc="{$moddesc}";
<if condition="$goods_images_list">
ShareImgUrl="{:getImg($goods_images_list[0]['image_url'])}";
</if>
<if condition="CONTROLLER_NAME eq 'Distribut'">
var ShareLink = "{:curHostURL()}/mobile/Distribut/myshop/stoid/"+wxstoid; //分销商链接
ShareTitle="{$distribut_sharetitle}";
ShareDesc="{$distribut_shareremark}";
<else/>
<if condition="$teamshare0 eq 1">
var ShareLink = "{$shareurl}"; //分销商链接
ShareTitle="{$pdact.share_title}";
ShareDesc="{$pdact.share_remark}";
<if condition="$pdact.share_imgurl">
ShareImgUrl="{:getImg($pdact['share_imgurl'])}";
</if>
<else/>
ShareTitle=document.title;
if(moddesc!=""){
ShareDesc=moddesc;
}else{
ShareDesc="{$tpshop_config['shop_info_store_desc']}";
}
var urk=location.href;
if(urk.indexOf('integral_info')>0
|| urk.indexOf('group/')>0
|| urk.indexOf('seckill_info')>0
|| urk.indexOf('goodsInfo')>0
|| urk.indexOf('goodsinfo')>0
){
ShareDesc="{$goods.goods_remark}";
}
var ShareLink = location.href.split('#')[0]; //默认分享链接
if(ShareLink.indexOf("?")!=-1) {
ShareLink = changeURLArg(ShareLink, "code,state", "");
}
</if>
</if>
var is_distribut = "{$tpshop_config['is_distribut']}"; // 是否分销代理
var user_id = "{$tpshop_config['user_id']}"; // 当前用户id
// 如果已经登录了, 并且是分销商
if(parseInt(user_id) > 0) {
if (ShareLink.indexOf("?") != -1) {
ShareLink = ShareLink + "&first_leader=" + user_id;
}
else {
ShareLink = ShareLink + "?first_leader=" + user_id;
}
}
$(function() {
if(isWeiXin()){
$.ajax({
type : "POST",
url:"/index.php?m=Mobile&c=Index&a=ajaxGetWxConfig&stoid="+wxstoid+"&t="+Math.random(),
data:{'askUrl':encodeURIComponent(location.href.split('#')[0])},
dataType:'JSON',
success: function(res)
{
//微信配置
if (wxstoid==23)
{
wx.config({
debug: false,
appId: res.appId,
timestamp: res.timestamp,
nonceStr: res.nonceStr,
signature: res.signature,
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareQZone', 'hideOptionMenu','addCard','scanQRCode','closeWindow'] // 功能列表,我们要使用JS-SDK的什么功能
});
}
else {
wx.config({
debug: false,
appId: res.appId,
timestamp: res.timestamp,
nonceStr: res.nonceStr,
signature: res.signature,
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareQZone', 'hideOptionMenu','addCard','scanQRCode','closeWindow'] // 功能列表,我们要使用JS-SDK的什么功能
});
}
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在 页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready 函数中。
wx.ready(function() {
// 获取"分享到朋友圈"按钮点击状态及自定义分享内容接口
wx.onMenuShareTimeline({
title: ShareTitle, // 分享标题
link: ShareLink,
imgUrl: ShareImgUrl // 分享图标
});
// 获取"分享给朋友"按钮点击状态及自定义分享内容接口
wx.onMenuShareAppMessage({
title: ShareTitle, // 分享标题
desc: ShareDesc, // 分享描述
link: ShareLink,
imgUrl: ShareImgUrl // 分享图标
});
// 分享到QQ
wx.onMenuShareQQ({
title: ShareTitle, // 分享标题
desc: ShareDesc, // 分享描述
link: ShareLink,
imgUrl: ShareImgUrl // 分享图标
});
// 分享到QQ空间
wx.onMenuShareQZone({
title: ShareTitle, // 分享标题
desc: ShareDesc, // 分享描述
link: ShareLink,
imgUrl: ShareImgUrl // 分享图标
});
if (typeof(issortsto) != "undefined"){
if (issortsto == 1) {
//如果session中有存有位置信息,就不重新定位
var ulx = $("#ulx").val();
var uly = $("#uly").val();
//alert(1000+":"+ulx+":"+uly);
if (ulx != "" && uly != "" && ulx != "0" && uly != "0") {
if (typeof(mapshow) != "undefined") {
mapshow(ulx, uly);
}
} else {
var x = 0;
var y = 0;
wx.getLocation({
success: function (res) {
y = res.latitude; // 纬度,浮点数,范围为90 ~ -90
x = res.longitude; // 经度,浮点数,范围为180 ~ -180
if (typeof(mapshow) != "undefined"){
mapshow(x, y);
}
},
cancel: function (res) {
if (typeof(mapshow) != "undefined"){
mapshow(0, 0)
}
},
fail: function (res) {
if (typeof(mapshow) != "undefined"){
mapshow(0, 0)
}
},
error: function () {
if (typeof(mapshow) != "undefined"){
mapshow(0, 0)
}
}
});
}
} else {
if (typeof(mapshow) != "undefined"){
mapshow(0, 0);
}
}
}
<if condition="((CONTROLLER_NAME eq 'User') and (ACTION_NAME neq 'shopping_hascard') and (ACTION_NAME neq 'shopping_card')) or (ACTION_NAME eq 'qr_code')" >
wx.hideOptionMenu();
</if>
//首页扫一扫start
$("#btnqrcode").click(function () {
wx.scanQRCode({
desc: 'scanQRCode desc',
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: function (res) {
// alert(JSON.stringify(res));
// return false;
// wx.closeWindow();
var result = res.resultStr.split(','); // 当needResult 为 1 时,扫码返回的结果
var resultvalue="";
if (result.length>1)
{
resultvalue=result[1];
}
else
{
resultvalue=result;
}
resultvalue=encodeURIComponent(resultvalue);
var url="/index.php/mobile/Goods/search/time/"+Math.random()*10+"/stoid/"+wxstoid+"/q/"+resultvalue;
window.location.href=url;
}
});
})
//首页扫一扫end
});
},
error:function(){
return false;
}
});
<if condition="$stoid_card">
var code="{$user['mobile']}";
var getopenid="{$user['openid']}";
//微信卡包
$.ajax({
type : "POST",
url:"/index.php?m=Mobile&c=Index&a=ajaxGetWxConfig_wxcard&stoid="+wxstoid+"&code="+code+"&openid="+getopenid+"&t="+Math.random(),
dataType:'JSON',
success: function(res) {
var arr = new Array(6)
arr[0] = code;
arr[1] = res.timestamp;
arr[2] = res.jsapiTicket;
arr[3] = getopenid;
arr[4] = res.cardid;
arr[5] = res.nonceStr;
var c=arr.sort();
var newstr="";
for (var i=0;i<c.length;i++)
{
newstr+=c[i];
}
var sh1=CryptoJS.SHA1(newstr);
$("#addCard").click(function () {
wx.addCard({
cardList: [
{
cardId: res.cardid,
cardExt: '{"code": "'+code+'", "openid": "'+getopenid+'", "timestamp": "' + res.timestamp + '","nonce_str":"' + res.nonceStr + '","outer_str":"web", "signature":"' + sh1 + '"}'
}
],
success: function (res) {
//alert('已添加卡券:' + JSON.stringify(res.cardList));
},
cancel: function (res) {
// alert(JSON.stringify(res))
}
});
})
},
error:function(){
return false;
}
});
</if>
//
}
else{
if(typeof(mapshow) != "undefined"){
mapshow(0,0)
}
}
});
function isWeiXin(){
var ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
return true;
}else{
return false;
}
}
//去掉某参数
//arg 多个以,分开
//arg_val 替换值
function changeURLArg(url,arg,arg_val){
var isgo=false;
var arg1 = arg.split(",");//以逗号作为分隔字符串
for (var e=0;e<arg1.length ;e++) {
if (GetQueryString(arg1[e]) !=null) {
isgo = true;
}
}
if (isgo==true) {
for (var i = 0; i < arg1.length; i++) {
var pattern = arg1[i] + '=([^&]*)';
var replaceText = arg_val;
if (url.match(pattern)) {
var tmp = '/(' + arg1[i] + '=)([^&]*)/gi';
tmp = url.replace(eval(tmp), replaceText);
url = tmp;
}
}
var newtmp = tmp;
var tmp1 = tmp.split('?');
if (tmp1.length >= 2) {
if (tmp1[1] == "") {
newtmp = tmp1[0];
}
else {
//&&fff=111
var newtmp1 = "";
var tmp2 = tmp1[1].split('&');
for (var y = 0; y < tmp2.length; y++) {
if (tmp2[y] != "") {
if (newtmp1 == "") {
newtmp1 = tmp2[y];
}
else {
newtmp1 += "&" + tmp2[y];
}
}
}
if (newtmp1 != "") {
newtmp = tmp1[0] + "?" + newtmp1;
} else {
newtmp = tmp1[0];
}
}
} else {
newtmp = tmp1[0];
}
return newtmp;
}
else
{
return url;
}
}
//取某参数
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}
var ws = null,wo = null; var scan = null,
domready = false;
// H5 plus事件处理
function plusReady() {
if (ws || !window.plus || !domready) {
return;
}
// 获取窗口对象
ws = plus.webview.currentWebview();
wo = ws.opener();
// 开始扫描
ws.addEventListener('show', function () {
scan = new plus.barcode.Barcode('bcid');
scan.onmarked = onmarked;
scan.start({
conserve: true,
filename: '_doc/barcode/'
});
}, false);
// 显示页面并关闭等待框
ws.show('pop-in');
wo.evalJS('closeWaiting()');
}
</script>