-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhack.html
More file actions
1554 lines (1236 loc) · 79.1 KB
/
Copy pathhack.html
File metadata and controls
1554 lines (1236 loc) · 79.1 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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<link href="/Content/active.css" rel="stylesheet" />
<link href="/BootStrap/bootstrap.min.css" rel="stylesheet" />
<link href="/BootStrap/bootstrap-theme.min.css" rel="stylesheet" />
<script src="/BootStrap/jquery.min.js"></script>
<script src="/BootStrap/bootstrap.min.js"></script>
<script>/**!
* 微信内置浏览器的Javascript API,功能包括:
*
* 1、分享到微信朋友圈
* 2、分享给微信好友
* 3、分享到腾讯微博
* 4、新的分享接口,包含朋友圈、好友、微博的分享(for iOS)
* 5、隐藏/显示右上角的菜单入口
* 6、隐藏/显示底部浏览器工具栏
* 7、获取当前的网络状态
* 8、调起微信客户端的图片播放组件
* 9、关闭公众平台Web页面
* 10、判断当前网页是否在微信内置浏览器中打开
* 11、增加打开扫描二维码
* 12、支持WeixinApi的错误监控
* 13、检测应用程序是否已经安装(需要官方开通权限)
* 14、发送电子邮件
*
* @author zhaoxianlie(http://www.baidufe.com)
*/
(function (window) {
"use strict";
/**
* 定义WeixinApi
*/
var WeixinApi = {
version: 4.0
};
// 将WeixinApi暴露到window下:全局可使用,对旧版本向下兼容
window.WeixinApi = WeixinApi;
/////////////////////////// CommonJS /////////////////////////////////
if (typeof define === 'function' && (define.amd || define.cmd)) {
if (define.amd) {
// AMD 规范,for:requirejs
define(function () {
return WeixinApi;
});
} else if (define.cmd) {
// CMD 规范,for:seajs
define(function (require, exports, module) {
module.exports = WeixinApi;
});
}
}
/**
* 对象简单继承,后面的覆盖前面的,继承深度:deep=1
* @private
*/
var _extend = function () {
var result = {}, obj, k;
for (var i = 0, len = arguments.length; i < len; i++) {
obj = arguments[i];
if (typeof obj === 'object') {
for (k in obj) {
obj[k] && (result[k] = obj[k]);
}
}
}
return result;
};
/**
* 内部私有方法,分享用
* @private
*/
var _share = function (cmd, data, callbacks) {
callbacks = callbacks || {};
// 分享过程中的一些回调
var progress = function (resp) {
switch (true) {
// 用户取消
case /\:cancel$/i.test(resp.err_msg) :
callbacks.cancel && callbacks.cancel(resp);
break;
// 发送成功
case /\:(confirm|ok)$/i.test(resp.err_msg):
callbacks.confirm && callbacks.confirm(resp);
break;
// fail 发送失败
case /\:fail$/i.test(resp.err_msg) :
default:
callbacks.fail && callbacks.fail(resp);
break;
}
// 无论成功失败都会执行的回调
callbacks.all && callbacks.all(resp);
};
// 执行分享,并处理结果
var handler = function (theData, argv) {
// 加工一下数据
if (cmd.menu == 'menu:share:timeline' ||
(cmd.menu == 'general:share' && argv.shareTo == 'timeline')) {
var title = theData.title;
theData.title = theData.desc || title;
theData.desc = title || theData.desc;
}
// 新的分享接口,单独处理
if (cmd.menu === 'general:share') {
// 如果是收藏操作,并且在wxCallbacks中配置了favorite为false,则不执行回调
if (argv.shareTo == 'favorite' || argv.scene == 'favorite') {
if (callbacks.favorite === false) {
return argv.generalShare(theData, function () {
});
}
}
if (argv.shareTo === 'timeline') {
WeixinJSBridge.invoke('shareTimeline', theData, progress);
} else if (argv.shareTo === 'friend') {
WeixinJSBridge.invoke('sendAppMessage', theData, progress);
} else if (argv.shareTo === 'QQ') {
WeixinJSBridge.invoke('shareQQ', theData, progress);
}
} else {
WeixinJSBridge.invoke(cmd.action, theData, progress);
}
};
// 监听分享操作
WeixinJSBridge.on(cmd.menu, function (argv) {
callbacks.dataLoaded = callbacks.dataLoaded || new Function();
if (callbacks.async && callbacks.ready) {
WeixinApi["_wx_loadedCb_"] = callbacks.dataLoaded;
if (WeixinApi["_wx_loadedCb_"].toString().indexOf("_wx_loadedCb_") > 0) {
WeixinApi["_wx_loadedCb_"] = new Function();
}
callbacks.dataLoaded = function (newData) {
callbacks.__cbkCalled = true;
var theData = _extend(data, newData);
theData.img_url = theData.imgUrl || theData.img_url;
delete theData.imgUrl;
WeixinApi["_wx_loadedCb_"](theData);
handler(theData, argv);
};
// 然后就绪
if (!(argv && (argv.shareTo == 'favorite' || argv.scene == 'favorite') && callbacks.favorite === false)) {
callbacks.ready && callbacks.ready(argv, data);
// 如果设置了async为true,但是在ready方法中并没有手动调用dataLoaded方法,则自动触发一次
if (!callbacks.__cbkCalled) {
callbacks.dataLoaded({});
callbacks.__cbkCalled = false;
}
}
} else {
// 就绪状态
var theData = _extend(data);
if (!(argv && (argv.shareTo == 'favorite' || argv.scene == 'favorite') && callbacks.favorite === false)) {
callbacks.ready && callbacks.ready(argv, theData);
}
handler(theData, argv);
}
});
};
/**
* 分享到微信朋友圈
* @param {Object} data 待分享的信息
* @p-config {String} appId 公众平台的appId(服务号可用)
* @p-config {String} imgUrl 图片地址
* @p-config {String} link 链接地址
* @p-config {String} desc 描述
* @p-config {String} title 分享的标题
*
* @param {Object} callbacks 相关回调方法
* @p-config {Boolean} async ready方法是否需要异步执行,默认false
* @p-config {Function} ready(argv, data) 就绪状态
* @p-config {Function} dataLoaded(data) 数据加载完成后调用,async为true时有用,也可以为空
* @p-config {Function} cancel(resp) 取消
* @p-config {Function} fail(resp) 失败
* @p-config {Function} confirm(resp) 成功
* @p-config {Function} all(resp) 无论成功失败都会执行的回调
*/
WeixinApi.shareToTimeline = function (data, callbacks) {
_share({
menu: 'menu:share:timeline',
action: 'shareTimeline'
}, {
"appid": data.appId ? data.appId : '',
"img_url": data.imgUrl,
"link": data.link,
"desc": data.desc,
"title": data.title,
"img_width": "640",
"img_height": "640"
}, callbacks);
};
/**
* 发送给微信上的好友
* @param {Object} data 待分享的信息
* @p-config {String} appId 公众平台的appId(服务号可用)
* @p-config {String} imgUrl 图片地址
* @p-config {String} link 链接地址
* @p-config {String} desc 描述
* @p-config {String} title 分享的标题
*
* @param {Object} callbacks 相关回调方法
* @p-config {Boolean} async ready方法是否需要异步执行,默认false
* @p-config {Function} ready(argv, data) 就绪状态
* @p-config {Function} dataLoaded(data) 数据加载完成后调用,async为true时有用,也可以为空
* @p-config {Function} cancel(resp) 取消
* @p-config {Function} fail(resp) 失败
* @p-config {Function} confirm(resp) 成功
* @p-config {Function} all(resp) 无论成功失败都会执行的回调
*/
WeixinApi.shareToFriend = function (data, callbacks) {
_share({
menu: 'menu:share:appmessage',
action: 'sendAppMessage'
}, {
"appid": data.appId ? data.appId : '',
"img_url": data.imgUrl,
"link": data.link,
"desc": data.desc,
"title": data.title,
"img_width": "640",
"img_height": "640"
}, callbacks);
};
/**
* 分享到腾讯微博
* @param {Object} data 待分享的信息
* @p-config {String} link 链接地址
* @p-config {String} desc 描述
*
* @param {Object} callbacks 相关回调方法
* @p-config {Boolean} async ready方法是否需要异步执行,默认false
* @p-config {Function} ready(argv, data) 就绪状态
* @p-config {Function} dataLoaded(data) 数据加载完成后调用,async为true时有用,也可以为空
* @p-config {Function} cancel(resp) 取消
* @p-config {Function} fail(resp) 失败
* @p-config {Function} confirm(resp) 成功
* @p-config {Function} all(resp) 无论成功失败都会执行的回调
*/
WeixinApi.shareToWeibo = function (data, callbacks) {
_share({
menu: 'menu:share:weibo',
action: 'shareWeibo'
}, {
"content": data.desc,
"url": data.link
}, callbacks);
};
/**
* 新的分享接口
* @param {Object} data 待分享的信息
* @p-config {String} appId 公众平台的appId(服务号可用)
* @p-config {String} imgUrl 图片地址
* @p-config {String} link 链接地址
* @p-config {String} desc 描述
* @p-config {String} title 分享的标题
*
* @param {Object} callbacks 相关回调方法
* @p-config {Boolean} async ready方法是否需要异步执行,默认false
* @p-config {Function} ready(argv, data) 就绪状态
* @p-config {Function} dataLoaded(data) 数据加载完成后调用,async为true时有用,也可以为空
* @p-config {Function} cancel(resp) 取消
* @p-config {Function} fail(resp) 失败
* @p-config {Function} confirm(resp) 成功
* @p-config {Function} all(resp) 无论成功失败都会执行的回调
*/
WeixinApi.generalShare = function (data, callbacks) {
_share({
menu: 'general:share'
}, {
"appid": data.appId ? data.appId : '',
"img_url": data.imgUrl,
"link": data.link,
"desc": data.desc,
"title": data.title,
"img_width": "640",
"img_height": "640"
}, callbacks);
};
/**
* 加关注(此功能只是暂时先加上,不过因为权限限制问题,不能用,如果你的站点是部署在*.qq.com下,也许可行)
* @param {String} appWeixinId 微信公众号ID
* @param {Object} callbacks 回调方法
* @p-config {Function} fail(resp) 失败
* @p-config {Function} confirm(resp) 成功
*/
WeixinApi.addContact = function (appWeixinId, callbacks) {
callbacks = callbacks || {};
WeixinJSBridge.invoke("addContact", {
webtype: "1",
username: appWeixinId
}, function (resp) {
var success = !resp.err_msg || "add_contact:ok" == resp.err_msg
|| "add_contact:added" == resp.err_msg;
if (success) {
callbacks.success && callbacks.success(resp);
} else {
callbacks.fail && callbacks.fail(resp);
}
})
};
/**
* 调起微信Native的图片播放组件。
* 这里必须对参数进行强检测,如果参数不合法,直接会导致微信客户端crash
*
* @param {String} curSrc 当前播放的图片地址
* @param {Array} srcList 图片地址列表
*/
WeixinApi.imagePreview = function (curSrc, srcList) {
if (!curSrc || !srcList || srcList.length == 0) {
return;
}
WeixinJSBridge.invoke('imagePreview', {
'current': curSrc,
'urls': srcList
});
};
/**
* 显示网页右上角的按钮
*/
WeixinApi.showOptionMenu = function () {
WeixinJSBridge.call('showOptionMenu');
};
/**
* 隐藏网页右上角的按钮
*/
WeixinApi.hideOptionMenu = function () {
WeixinJSBridge.call('hideOptionMenu');
};
/**
* 显示底部工具栏
*/
WeixinApi.showToolbar = function () {
WeixinJSBridge.call('showToolbar');
};
/**
* 隐藏底部工具栏
*/
WeixinApi.hideToolbar = function () {
WeixinJSBridge.call('hideToolbar');
};
/**
* 返回如下几种类型:
*
* network_type:wifi wifi网络
* network_type:edge 非wifi,包含3G/2G
* network_type:fail 网络断开连接
* network_type:wwan 2g或者3g
*
* 使用方法:
* WeixinApi.getNetworkType(function(networkType){
*
* });
*
* @param callback
*/
WeixinApi.getNetworkType = function (callback) {
if (callback && typeof callback == 'function') {
WeixinJSBridge.invoke('getNetworkType', {}, function (e) {
// 在这里拿到e.err_msg,这里面就包含了所有的网络类型
callback(e.err_msg);
});
}
};
/**
* 关闭当前微信公众平台页面
* @param {Object} callbacks 回调方法
* @p-config {Function} fail(resp) 失败
* @p-config {Function} success(resp) 成功
*/
WeixinApi.closeWindow = function (callbacks) {
callbacks = callbacks || {};
WeixinJSBridge.invoke("closeWindow", {}, function (resp) {
switch (resp.err_msg) {
// 关闭成功
case 'close_window:ok':
callbacks.success && callbacks.success(resp);
break;
// 关闭失败
default :
callbacks.fail && callbacks.fail(resp);
break;
}
});
};
/**
* 当页面加载完毕后执行,使用方法:
* WeixinApi.ready(function(Api){
* // 从这里只用Api即是WeixinApi
* });
* @param readyCallback
*/
WeixinApi.ready = function (readyCallback) {
/**
* 加一个钩子,同时解决Android和iOS下的分享问题
* @private
*/
var _hook = function () {
var _WeixinJSBridge = {};
Object.keys(WeixinJSBridge).forEach(function (key) {
_WeixinJSBridge[key] = WeixinJSBridge[key];
});
Object.keys(WeixinJSBridge).forEach(function (key) {
if (typeof WeixinJSBridge[key] === 'function') {
WeixinJSBridge[key] = function () {
try {
var args = arguments.length > 0 ? arguments[0] : {},
runOn3rd_apis = args.__params ? args.__params.__runOn3rd_apis || [] : [];
['menu:share:timeline', 'menu:share:appmessage',
'menu:share:qq', 'general:share'].forEach(function (menu) {
runOn3rd_apis.indexOf(menu) === -1 && runOn3rd_apis.push(menu);
});
} catch (e) {
}
return _WeixinJSBridge[key].apply(WeixinJSBridge, arguments);
};
}
});
};
if (readyCallback && typeof readyCallback == 'function') {
var Api = this;
var wxReadyFunc = function () {
_hook();
readyCallback(Api);
};
if (typeof window.WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', wxReadyFunc, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', wxReadyFunc);
document.attachEvent('onWeixinJSBridgeReady', wxReadyFunc);
}
} else {
wxReadyFunc();
}
}
};
/**
* 判断当前网页是否在微信内置浏览器中打开
*/
WeixinApi.openInWeixin = function () {
return /MicroMessenger/i.test(navigator.userAgent);
};
/*
* 打开扫描二维码
* @param {Object} callbacks 回调方法
* @p-config {Boolean} needResult 是否直接获取分享后的内容
* @p-config {String} desc 扫描二维码时的描述
* @p-config {Function} fail(resp) 失败
* @p-config {Function} success(resp) 成功
*/
WeixinApi.scanQRCode = function (callbacks) {
callbacks = callbacks || {};
WeixinJSBridge.invoke("scanQRCode", {
needResult: callbacks.needResult ? 1 : 0,
desc: callbacks.desc || 'WeixinApi Desc'
}, function (resp) {
switch (resp.err_msg) {
// 打开扫描器成功
case 'scanQRCode:ok':
case 'scan_qrcode:ok':
callbacks.success && callbacks.success(resp);
break;
// 打开扫描器失败
default :
callbacks.fail && callbacks.fail(resp);
break;
}
});
};
/**
* 检测应用程序是否已安装
* by mingcheng 2014-10-17
*
* @param {Object} data 应用程序的信息
* @p-config {String} packageUrl 应用注册的自定义前缀,如 xxx:// 就取 xxx
* @p-config {String} packageName 应用的包名
*
* @param {Object} callbacks 相关回调方法
* @p-config {Function} fail(resp) 失败
* @p-config {Function} success(resp) 成功,如果有对应的版本信息,则写入到 resp.version 中
* @p-config {Function} all(resp) 无论成功失败都会执行的回调
*/
WeixinApi.getInstallState = function (data, callbacks) {
callbacks = callbacks || {};
WeixinJSBridge.invoke("getInstallState", {
"packageUrl": data.packageUrl || "",
"packageName": data.packageName || ""
}, function (resp) {
var msg = resp.err_msg, match = msg.match(/state:yes_?(.*)$/);
if (match) {
resp.version = match[1] || "";
callbacks.success && callbacks.success(resp);
} else {
callbacks.fail && callbacks.fail(resp);
}
callbacks.all && callbacks.all(resp);
});
};
/**
* 发送邮件
* @param {Object} data 邮件初始内容
* @p-config {String} subject 邮件标题
* @p-config {String} body 邮件正文
*
* @param {Object} callbacks 相关回调方法
* @p-config {Function} fail(resp) 失败
* @p-config {Function} success(resp) 成功
* @p-config {Function} all(resp) 无论成功失败都会执行的回调
*/
WeixinApi.sendEmail = function (data, callbacks) {
callbacks = callbacks || {};
WeixinJSBridge.invoke("sendEmail", {
"title": data.subject,
"content": data.body
}, function (resp) {
if (resp.err_msg === 'send_email:sent') {
callbacks.success && callbacks.success(resp);
} else {
callbacks.fail && callbacks.fail(resp);
}
callbacks.all && callbacks.all(resp);
})
};
/**
* 开启Api的debug模式,比如出了个什么错误,能alert告诉你,而不是一直很苦逼的在想哪儿出问题了
* @param {Function} callback(error) 出错后的回调,默认是alert
*/
WeixinApi.enableDebugMode = function (callback) {
/**
* @param {String} errorMessage 错误信息
* @param {String} scriptURI 出错的文件
* @param {Long} lineNumber 出错代码的行号
* @param {Long} columnNumber 出错代码的列号
*/
window.onerror = function (errorMessage, scriptURI, lineNumber, columnNumber) {
// 有callback的情况下,将错误信息传递到options.callback中
if (typeof callback === 'function') {
callback({
message: errorMessage,
script: scriptURI,
line: lineNumber,
column: columnNumber
});
} else {
// 其他情况,都以alert方式直接提示错误信息
var msgs = [];
msgs.push("额,代码有错。。。");
msgs.push("\n错误信息:", errorMessage);
msgs.push("\n出错文件:", scriptURI);
msgs.push("\n出错位置:", lineNumber + '行,' + columnNumber + '列');
alert(msgs.join(''));
}
}
};
})(window);
</script>
<script>
var logs = {
sender: function (class0, method, ex) {
$.ajax({
url: '/LogReceiver/Script',
type: 'post',
data: { 'class': class0, 'method': method, 'ex': ex }
});
}
};
//活动主函数
var active = function (u, a, v, p, l, i, b, t) {
try {
alert("initial");
this.visitor = v;
this.parent = p;
this.level = l;
this.icon = i;
this.baseUrl = b;
this.title = t;
var self = this;
self.Publicity();
WeixinApi.ready(function (api) {
alert("load");
api.showOptionMenu();
var wxData = {
'appId': '',
'imgUrl': self.icon,
"link": self.baseUrl + '?v=' + self.visitor + '&parent=' + self.parent + '&l=' + (parseInt(self.level) + 1),
"desc": self.title,
"title": self.title
};
var wxCallbacks = {
favorite: false,
ready: function () { alert("This is a ready hook"); },
cancel: function () { alert("This is a cancel hook"); },
fail: function () { alert("This is a fail hook"); },
confirm: function (resp) {
alert("This is a confirm hook");
if (resp.err_msg === 'share_timeline:ok' || resp.err_msg === 'general_share:ok') {
$.ajax({
url: '/activev1/StartShare',
type: 'post',
success: function (data) {
if (data === 'False_Contribution') {
$('#divContribution').modal('show');
} else if (data === 'False_ShareLimit') {
$('#divMalicious').modal('show');
} else if (data === 'False_IsRepeatShare') {
$('#divIsRepeatShare').modal('show');
}
var cookevalue = getCookie("isFirst2");
if (cookevalue === "") {
setCookie("isFirst2", "true", 10000);
$('#divFirstMark').modal('show');
}
}
});
}
},
all: function (resp) {
}
};
api.shareToFriend(wxData, wxCallbacks);
api.shareToTimeline(wxData, wxCallbacks);
api.shareToWeibo(wxData, wxCallbacks);
api.generalShare(wxData, wxCallbacks);
});
}
catch (e) {
logs.sender('active', 'active', e);
}
};
active.prototype.WeixinVersion = function () {
if (navigator.userAgent.indexOf('MicroMessenger/6.0.2') != -1 && navigator.userAgent.indexOf('iPhone') != -1) {
$('#divWeixinVersion').modal('show');
}
};
//活动状态
active.prototype.ActivityStat = {
Started: 3,
Over: 4
};
//活动公示
active.prototype.Publicity = function () {
$('#divIconContainer').bind('click', function () {
var isExpand = $(this).data('expand') === 'true';
if (isExpand) {
$(this).data('expand', 'false');
$(this).children('.publicity_down').removeClass('publicity_up');
$('#divPublicityInfo').slideUp(100);
} else {
$(this).data('expand', 'true');
$(this).children('.publicity_down').addClass('publicity_up');
if ($.trim($('#divPublicityInfo').html()) === '') {
$.ajax({
url: '/activev1/LoadActivityInfo',
type: 'get',
dataType: 'json',
cache: true,
success: function (data) {
var html = '';
html += '<ul class="publicity-expand">';
html += '<li class="publicity-title">奖品设置</li>';
var startDate = new Date(parseInt(data.LimitStartTime.substr(6)));
var endDate = new Date(parseInt(data.LimitEndTime.substr(6)));
$.each(data.PrizeInfos, function (i, n) {
html += '<li><span class="publicity-num">' + (i + 1) + '.</span>集 <b>' + n.ShareCount + '</b> 个分享获 <b>' + n.PrizeContent + ' </b>' + (!n.IsLimitPrizeCount ? '' : '共' + n.LimitPrizeCount + '份') + '</li>';
});
html += '<li class="publicity-title publicity-topline">活动时间</li>';
html += '<li>' + active.dateFormat(startDate) + ' — ' + active.dateFormat(endDate) + '</li>';
html += '<li class="publicity-title publicity-topline">兑奖方法</li>';
html += '<li>' + data.ExchangeMethod + '</li>';
html += '<li class="publicity-title publicity-topline">咨询电话</li>';
html += '<li>' + data.Phone + '<a href="tel:' + data.Phone + '" class="publicity-call"><span class="publicity-call-icon"></span> 直接拨打</a></li>';
html += '</ul>';
$('#divPublicityInfo').html(html).slideDown(100);
}
});
} else {
$('#divPublicityInfo').slideDown(100);
}
}
});
$('#divHowContainer').bind('click', function () {
var isExpand = $(this).data('expand') === 'true';
if (isExpand) {
$(this).data('expand', 'false');
$(this).children('.publicity_down').removeClass('publicity_up');
$('#divPublicityHow').slideUp(100);
} else {
$(this).data('expand', 'true');
$(this).children('.publicity_down').addClass('publicity_up');
if ($.trim($('#divPublicityHow').html()) === '') {
var html = '';
html += '<ul class="publicity-expand">';
html += '<li class="clearfix"><div class="publicity-right publicity-pic-1"><span class="publicity-num">1.</span>累集分享个数</div></li>';
html += '<li class="clearfix"><div class="publicity-left publicity-pic-2"><span class="publicity-num">2.</span>选择奖品</div></li>';
html += '<li class="clearfix"><div class="publicity-right publicity-pic-3"><span class="publicity-num">3.</span>获得兑奖码</div></li>';
html += '</ul>';
$('#divPublicityHow').html(html);
}
$('#divPublicityHow').slideDown(100);
}
});
};
//活动日期格式化
active.dateFormat = function (date) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
if (month < 10) {
month = '0' + month;
}
var day = date.getDate();
if (day < 10) {
day = '0' + day;
}
var hour = date.getHours();
if (hour < 10) {
hour = '0' + hour;
}
var minute = date.getMinutes();
if (minute < 10) {
minute = '0' + minute;
}
return year + '.' + month + '.' + day + ' ' + hour + ':' + minute;
};
//加载集分享信息
active.prototype.loadInfo = function () {
var self = this;
$.ajax({
url: '/activev1/loadinfo',
type: 'get',
cache: false,
success: function (data) {
var html = '';
var activityInfo = data.ActivityInfo;
var visitorInfo = data.VisitorInfo;
var nextPrizeCount = data.NextPrizeCount;
html += self.createShareHtml(self.visitor === self.parent, visitorInfo.ChildrenShareCount);
html += self.createLightHtml(visitorInfo.ChildrenShareCount, nextPrizeCount);
html += self.createSurplusHtml(activityInfo.ActivityStat === self.ActivityStat.Over, activityInfo.LeaveTime);
html += self.createPrizeHtml(self.visitor === self.parent, activityInfo, visitorInfo);
$('#divVisitor').html(html);
self.bindSelect();
self.bindExchange();
self.BindRemind();
}
});
};
//生成分享数的html代码
active.prototype.createShareHtml = function (isSelf, shareCount) {
return '<div class="v-share">' + (isSelf ? '您' : '该用户') + '已集<span class="v-share-count">' + shareCount + '</span>个分享</div>';
};
//生成电灯效果的html代码
active.prototype.createLightHtml = function (childrenShareCount, nextPrizeCount) {
var html = '<div class="v-share-icon"><div class="v-share-icon-container">';
if (nextPrizeCount === 0) {
for (var i = 0; i < childrenShareCount; i++) {
html += '<span class="v-share-light-color"></span>';
}
} else {
for (var j = 0; j < nextPrizeCount; j++) {
if (childrenShareCount > j) {
html += '<span class="v-share-light-color"></span>';
} else {
html += '<span class="v-share-light-gray"></span>';
}
}
}
html += '</div></div>';
return html;
};
//生成活动剩余时间的html代码
active.prototype.createSurplusHtml = function (isOver, leaveTime) {
var html = '<div class="v-share-surplus">活动剩余时间:';
if (isOver) {
html += '<span class="visitor_over_time">0</span>天<span class="visitor_over_time">0</span>小时<span class="visitor_over_time">0</span>分钟';
} else {
html += leaveTime;
}
html += '</div>';
return html;
};
//生成工活动奖品信息的html代码
active.prototype.createPrizeHtml = function (isSelf, activityInfo, visitorInfo) {
var html = '';
var self = this;
if (isSelf) {
if (visitorInfo.Abnormal === "异常") {
html += '<div class="v-prize-code">';
html += '您涉嫌采用非正常方式集分享数量,本次兑奖资格被取消,如需申诉请致电我公司法务部门,直线电话:0512-69373652';
html += '</div>';
return html;
}
if (visitorInfo.IsGetPrize) {
html += '<div class="v-prize-code">';
html += '<p>您已获得</p>';
html += '<p>' + visitorInfo.GetPrizeInfo.PrizeContent + '</p>';
html += '<p>领奖密码:' + visitorInfo.PrizeCode + '</p>';
html += '</div>';
return html;
}
if (activityInfo.ActivityStat === self.ActivityStat.Over) {
html += '<div>';
html += '<p>活动已结束</p>';
html += '</div>';
return html;
}
}
html = '<div class="v-prize-get clearfix"><span class="v-prize-get-tip">' + (isSelf ? '您' : '该用户') + '已获得:</span>' + (isSelf ? '<a href="javascript:void(0);" class="v-prize-get-remind" id="btnRemind" data-loading-text="正在加载...">获奖提醒</a>' : '') + '</div>';
var prizeInfos = activityInfo.PrizeInfos;
var hasSet = false;
var prizeTemps = [];
var i;
for (i = prizeInfos.length - 1; i >= 0; i--) {
var prizeTempHtml = '';
var isCanGetPrize = visitorInfo.ChildrenShareCount >= prizeInfos[i].ShareCount;
var surplusPrizeCount = (prizeInfos[i].IsLimitPrizeCount ? '剩余' + prizeInfos[i].SurplusPrizeCount + '份' : '');
if (prizeInfos[i].IsLimitPrizeCount) {
isCanGetPrize = isCanGetPrize && prizeInfos[i].SurplusPrizeCount;
}
if (isSelf) {
if (isCanGetPrize) {
if (!hasSet) {
hasSet = true;
prizeTempHtml = '<ul class="v-prize-item-selected clearfix" data-id="' + prizeInfos[i].Id + '" data-name="' + prizeInfos[i].PrizeContent + '">'
+ '<li class="v-prize-select-iconcontainer"><span class="v-prize-select-icon"></span></li>'
+ '<li class="v-prize-item-name">' + prizeInfos[i].PrizeContent + '</li>'
+ '<li class="v-prize-item-surplus">' + surplusPrizeCount + '</li>'
+ '</ul>';
$('#lblPrize').html(prizeInfos[i].PrizeContent);
} else {
prizeTempHtml += '<ul class="v-prize-item-unselect clearfix" data-id="' + prizeInfos[i].Id + '" data-name="' + prizeInfos[i].PrizeContent + '">'
+ '<li class="v-prize-select-iconcontainer"><span class="v-prize-select-icon"></span></li>'
+ '<li class="v-prize-item-name">' + prizeInfos[i].PrizeContent + '</li>'
+ '<li class="v-prize-item-surplus">' + surplusPrizeCount + '</li>'
+ '</ul>';
}
} else {
prizeTempHtml += '<ul class="v-prize-item-disabled clearfix">'
+ '<li class="v-prize-select-iconcontainer"><span class="v-prize-select-icon"></span></li>'
+ '<li class="v-prize-item-name">' + prizeInfos[i].PrizeContent + '</li>'
+ '<li class="v-prize-item-surplus">' + surplusPrizeCount + '</li>'
+ '</ul>';
}
} else {
if (isCanGetPrize && !hasSet) {
hasSet = true;
prizeTempHtml += '<ul class="v-prize-item-selected-disabled clearfix">'
+ '<li class="v-prize-select-iconcontainer"><span class="v-prize-select-icon"></span></li>'
+ '<li class="v-prize-item-name">' + prizeInfos[i].PrizeContent + '</li>'
+ '<li class="v-prize-item-surplus">' + surplusPrizeCount + '</li>'
+ '</ul>';
} else {
prizeTempHtml += '<ul class="v-prize-item-disabled clearfix">'
+ '<li class="v-prize-select-iconcontainer"><span class="v-prize-select-icon"></span></li>'
+ '<li class="v-prize-item-name">' + prizeInfos[i].PrizeContent + '</li>'
+ '<li class="v-prize-item-surplus">' + surplusPrizeCount + '</li>'
+ '</ul>';
}
}
prizeTemps.push(prizeTempHtml);
}
for (i = prizeInfos.length - 1; i >= 0; i--) {
html += prizeTemps[i];
}
if (isSelf) {
if (hasSet) {
html += '<div><button type="button" id="v-prize-get-enable" class="btn-block v-prize-get-enable" data-toggle="modal" >立即兑奖</button></div>';
} else {
html += '<div><button type="button" class="btn-block v-prize-get-disable">立即兑奖</button></div>';
}
}
return html;
};
//绑定奖品选择事件
active.prototype.bindSelect = function () {
$('#divVisitor').on('click', '.v-prize-item-unselect', function () {
$('#divVisitor .v-prize-item-selected').removeClass('v-prize-item-selected').addClass('v-prize-item-unselect');
$(this).removeClass('v-prize-item-unselect').addClass('v-prize-item-selected');
$('#lblPrize').html($(this).data('name'));
});
//绑定立即兑奖事件
$('#v-prize-get-enable').on('click', function () {
$.ajax({
url: '/activev1/isAbnormal',
type: 'post',
dataType: 'text',
data: { 'pid': $('#divVisitor .v-prize-item-selected').data('id') },
success: function (data) {
if (data === 'True') {
$('#divAbnormal').modal('show');
}
else {
$('#divExchange').modal('show');
}
}, error: function () {
alert('服务器繁忙,请稍后再试');
}
});
});
};
//绑定兑奖事件
active.prototype.bindExchange = function () {
var self = this;
$('#btnExchangeSubmit').bind('click', function () {
var $button = $(this);
$button.button('loading');
$.ajax({
url: '/activev1/StartExchange',
type: 'post',
dataType: 'text',
data: { 'pid': $('#divVisitor .v-prize-item-selected').data('id') },
success: function (data) {
$button.button('reset');
if (data === 'True') {
$('#divExchange').modal('hide');
self.loadInfo();
}
}, error: function () {
$button.button('reset');
alert('服务器繁忙,请稍后再试');
}
});
});