aeline
2020-06-30 008058dbb500a130fa533247e49eec439f7e5bba
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
//
//  GeneralWebController.m
//  MIduo
//
//  Created by 重庆迈尖科技有限公司 on 2019/9/28.
//  Copyright © 2019 yeshi. All rights reserved.
//
 
#import "ShonpingShareViewController.h"
#import "SureWebViewController.h"
#import "SearchDetailMainController.h"
#import "InvitationFriendsViewController.h"
#import "NoCouponNoRebateController.h"
 
#import <WebKit/WebKit.h>
#import <sys/utsname.h>
#import <AdSupport/AdSupport.h>
#import "CZBInfoManager.h"
 
#import "SAMKeychain.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import "GTMBase64.h"
 
#import "SJDynamicShareView.h"
#import "WebMorePopView.h"
 
#import "HZPhotoBrowser.h"
 
@interface ShonpingShareViewController () <WKNavigationDelegate, WKUIDelegate, WKScriptMessageHandler, NewLoginViewDelegate>
 
@property (nonatomic, strong) UIButton *closeButton;
@property (nonatomic, strong) UIButton *moreShareButton;
 
/// 导航栏的下的灰线
@property (nonatomic, strong) UIView *navGaryLine;
@property (nonatomic, strong) WKWebView *webView;
@property (nonatomic, strong) UIProgressView *progressView;
 
@property (nonatomic, strong) SJDynamicShareView *shareAppView;
@property (nonatomic, nullable, strong) WebMorePopView *webMorePopView;
 
@property (nonatomic, strong) NSMutableDictionary *shareDictionary;
 
@property (nonatomic, nullable, strong) NSMutableArray *dataMutArr;
@property (nonatomic, nullable, strong) NSMutableArray *newAddmMutArr;
@property (nonatomic, nullable, strong) NSArray *gudingArr;
 
@property (nonatomic, strong) NSMutableArray *tempOldArr;
 
@property (nonatomic, strong) NSDictionary *shareDatasource;
/// 分享链接
@property (nonatomic, nullable, copy) NSString *urlShare;
/// 分享名字
@property (nonatomic, nullable, copy) NSString *urlName;
 
@property (nonatomic, assign) BOOL goodsDetail; //:true是否需要拦截商品详情
 
@property (nonatomic, assign) BOOL isBaichuan;
/// 网页是否加载完成
@property (nonatomic, assign) BOOL isWebViewLoad;
 
@property (nonatomic, nullable, strong) NSMutableArray *arrayShareImage;
/// 是否下载多张图片
@property (nonatomic, assign) BOOL isDownMoreImg;
@end
 
@implementation ShonpingShareViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupDataConfig];
    [self setupNave];
    [self setupView];
    [self webViewloadURLType];
}
 
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    
    [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
    [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
    // addScriptMessageHandler 很容易导致循环引用
    // 控制器 强引用了WKWebView,WKWebView copy(强引用了)configuration, configuration copy (强引用了)userContentController
    // userContentController 强引用了 self (控制器)
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"toast"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpGoodsSplash"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpGoodsSplashWithFrom"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpGoodsDetail"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpKeFu"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpBaiChuan"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpPage"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpPageWithFinishCurrentPage"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"umEventCount"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"umEventCompute"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"hiddenTopMenuCloseBtn"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"showSharePanel"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"addMenu"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"copyText"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpSearch"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpInvite"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"login"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"setTitle"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"showLoading"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"hideLoading"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"finishPage"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpJDGoodsDetailWithFrom"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpPDDGoodsDetailWithFrom"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareLink"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareImg"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"savePicture"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpJD"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"tbAuth"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareText"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"clearClipboard"];
    
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"jumpWXXCX"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareWXXCX"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"shareImgs"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"savePictures"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"showimgs"];
    
    if (_isWebViewLoad) {
        NSString *jsFounction = @"yestvcallback.resume()";
        [self.webView evaluateJavaScript:jsFounction completionHandler:^(id object, NSError * _Nullable error) {
            //NSLog(@"obj:%@---error:%@", object, error);
        }];
    }
}
 
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.webView removeObserver:self forKeyPath:@"title"];
    [self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
    // 因此这里要记得移除handlers
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"toast"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpGoodsSplash"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpGoodsSplashWithFrom"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpGoodsDetail"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpKeFu"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpBaiChuan"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpPage"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpPageWithFinishCurrentPage"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"umEventCount"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"umEventCompute"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"hiddenTopMenuCloseBtn"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"showSharePanel"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"addMenu"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"copyText"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpSearch"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpInvite"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"login"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"setTitle"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"showLoading"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"hideLoading"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"finishPage"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpJDGoodsDetailWithFrom"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpPDDGoodsDetailWithFrom"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareLink"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareImg"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"savePicture"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpJD"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"tbAuth"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareText"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"clearClipboard"];
    
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"jumpWXXCX"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareWXXCX"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"shareImgs"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"savePictures"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"showimgs"];
}
 
- (void)setupNave {
    UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    backbutton.frame = CGRectMake(0, 0, 32, 30);
    [backbutton setImage:[UIImage imageNamed:@"all_back"] forState:UIControlStateNormal];
    [backbutton setTitle:@"    " forState:UIControlStateNormal];
    [backbutton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:backbutton];
    
    self.closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.closeButton.frame = CGRectMake(0, 0, 32, 30);
    [self.closeButton setTitle:@"    " forState:UIControlStateNormal];
    [self.closeButton setImage:[UIImage imageNamed:@"new_cancel"] forState:UIControlStateNormal];
    [self.closeButton addTarget:self action:@selector(closeItem:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *closeItem = [[UIBarButtonItem alloc] initWithCustomView:self.closeButton];
    
    self.navigationItem.leftBarButtonItems = @[backItem,closeItem];
    
    self.moreShareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.moreShareButton.frame = CGRectMake(0, 0, 30, 30);
    [self.moreShareButton setImage:[UIImage imageNamed:@"更多___up"] forState:UIControlStateNormal];
    [self.moreShareButton addTarget:self action:@selector(shareTaped:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:self.moreShareButton];
    
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:FLQNewNavigationTitleColor, NSFontAttributeName:[UIFont boldSystemFontOfSize:FLQNewNavigationTitleFont]};
    self.navigationController.navigationBar.barTintColor = FLQNewNavigationBarColor;
    
    self.view.backgroundColor = XYRBackgroundColor;
}
 
- (void)setupDataConfig {
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.isWebViewLoad = NO;
    self.clipboard = YES;
    
    self.shareDictionary = @{}.mutableCopy;
    if (self.dataDictionary[@"paramsJSON"][@"url"]) {
        NSString * cleanString = self.dataDictionary[@"paramsJSON"][@"url"];
        self.urlString = cleanString;
        
    } else if (self.dataDictionary[@"url"]) {
        NSString * cleanString = self.dataDictionary[@"url"];
        self.urlString = cleanString;
    }
    
    if (self.dataDictionary[@"paramsJSON"]) {
        BOOL clipboard = [self.dataDictionary[@"paramsJSON"][@"clipboard"] boolValue];
        self.clipboard = clipboard;
        [YTHsharedManger startManger].clipboard = clipboard;
        
    } else if (self.dataDictionary) {
        BOOL clipboard = [self.dataDictionary[@"clipboard"] boolValue];
        self.clipboard = clipboard;
        [YTHsharedManger startManger].clipboard = clipboard;
    }
    
    if (self.dataDictionary[@"paramsJSON"][@"title"]) {
        NSString * cleanString = self.dataDictionary[@"paramsJSON"][@"title"];
        self.navaTitle = cleanString;
        
    } else if (self.dataDictionary[@"title"]) {
        NSString * cleanString = self.dataDictionary[@"title"];
        self.navaTitle = cleanString;
    }
    // 去掉空格和换行
    self.urlString = [self removeSpaceAndNewline:_urlString];
    //监听UIWindow显示
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(beginFullScreen) name:UIWindowDidBecomeVisibleNotification object:nil];
    //监听UIWindow隐藏
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(windowDidBecomeHidden:) name:UIWindowDidBecomeHiddenNotification object:nil];
}
 
- (void)beginFullScreen {
    
}
 
- (void)windowDidBecomeHidden:(NSNotification *)noti {
    UIWindow *win = (UIWindow *)noti.object;
    if (win) {
        UIViewController *rootVC = win.rootViewController;
        NSArray<__kindof UIViewController *> *vcs = rootVC.childViewControllers;
        if([vcs.firstObject isKindOfClass:NSClassFromString(@"AVPlayerViewController")]){
            [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
        }
    }
}
 
- (void)webViewloadURLType {
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (self.urlString) {
        [params setObject:self.urlString forKey:@"url"];
    }
    @weakify(self)
    [JYNetWorking Post:[NSString stringWithFormat:@"%@/%@",domainHTTP2,@"config/getWebConfig"] param:params success:^(NSDictionary *object)
     {
        @strongify(self)
        @weakify(self)
        dispatch_async(dispatch_get_main_queue(), ^{
            @strongify(self)
            if ([object[@"code"] integerValue] == 0) {
                self.isBaichuan = [object[@"data"][@"baichuan"] boolValue];
                self.goodsDetail = [object[@"data"][@"goodsDetail"] boolValue];
                if (self.isBaichuan) {
                    [self loadALiBaiChuan];
                    
                } else {
                    [self initLoadWebView];
                }
                
            } else {
                [self initLoadWebView];
            }
        });
        
    } fail:^(id object) {
        @strongify(self)
        [self initLoadWebView];
    }];
}
 
- (void)loadALiBaiChuan {
    [self.albcServiceManager pushOpenByUrl:self.urlString identity:nil webView:_webView parentController:self.navigationController taoKeParams:nil];
}
 
- (void)setupView {
    [self.view addSubview:self.navGaryLine];
    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
    WKPreferences *preferences = [WKPreferences new];
    preferences.javaScriptCanOpenWindowsAutomatically = YES;
    configuration.preferences = preferences;
    
    self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - kNavigationBarH - kStatusBarH) configuration:configuration];
    self.webView.backgroundColor = XYRBackgroundColor;
    self.webView.navigationDelegate = self;
    self.webView.UIDelegate = self;
    
    [self.view addSubview:self.webView];
    
    [self initProgressView];
}
 
- (void)initLoadWebView {
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]];
    [CZBInfoManager setUserAgent:@"blksIOS" webView:self.webView completion:^{
        [self.webView loadRequest:request];
        
    }];
    [CZBInfoManager registerWebView:self.webView];
    
    
}
 
- (void)initProgressView {
    CGFloat kScreenWidth = [[UIScreen mainScreen] bounds].size.width;
    UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1)];
    progressView.tintColor = XYRMainColor;
    progressView.trackTintColor = UICOLOR_FROM_RGB(0xe0e0e0, 1.0);
    [self.view addSubview:progressView];
    self.progressView = progressView;
}
 
- (void)dealloc {
    NSLog(@"%s",__FUNCTION__);
}
 
#pragma mark - event
- (void)back:(UIButton *)sender
{
    if ([self.webView canGoBack]) {
        [self.webView goBack];
        
    } else {
        !_shonpingShareBack?:_shonpingShareBack();
        if ([self.shonpingSharedelegate respondsToSelector:@selector(noticeRewardCouponsViewBack)]) {
            [self.shonpingSharedelegate noticeRewardCouponsViewBack];
        };
        [self.navigationController popViewControllerAnimated:YES];
    }
}
 
- (void)shareTaped:(UIButton *)sender {
    [self.dataMutArr removeAllObjects];
    
    if (self.newAddmMutArr.count != 0) {
        [self.dataMutArr addObjectsFromArray:self.newAddmMutArr];
    }
    [self.dataMutArr addObjectsFromArray:self.gudingArr];
    
    self.webMorePopView = [[WebMorePopView alloc] initShareRecordPopView:self.dataMutArr];
    @weakify(self)
    self.webMorePopView.selectIndex = ^(NSInteger index) {
        @strongify(self)
        NSString *performJs = self.dataMutArr[index][@"js"];
        if ([performJs isEqualToString:@"refresh"]) {
            [self.webView reload];
            
        } else if ([performJs isEqualToString:@"kefu"]) {
            [CustomerServiceManage pushinitMQ:@"web"];
            
        } else {
            @weakify(self)
            dispatch_async(dispatch_get_main_queue(), ^{
                @strongify(self)
                [self.webView evaluateJavaScript:performJs completionHandler:^(id _Nullable result, NSError * _Nullable error) {
                    NSLog(@"result:%@,error:%@",result,error);
                }];
            });
        }
    };
    [self.webMorePopView show];
}
 
- (void)closeItem:(UIButton *)sender {
    !_shonpingShareBack?:_shonpingShareBack();
    if ([self.shonpingSharedelegate respondsToSelector:@selector(noticeRewardCouponsViewBack)]) {
        [self.shonpingSharedelegate noticeRewardCouponsViewBack];
    };
    [self.navigationController popViewControllerAnimated:YES];
}
 
#pragma mark - private method
/// 获取用户ID
- (NSString *)getUid {
    NSString *uid = [NSString stringWithFormat:@"%@",[ALUserInfoServiceManger fetchUID]];
    if(![ALUserInfoServiceManger fetchUID]){
        uid = @"0";
    }
    return uid;
}
- (NSString *)getVersion {
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    return version;
}
 
- (NSString *)getSign:(NSString *)stringJS {
    if (!stringJS && [stringJS isEqualToString:@""]) {
        return @"";
    }
    NSString *MD5String = [NSString md5:[NSString stringWithFormat:@"%@@?,223Hbb88lll",stringJS]];
    return MD5String;
}
 
- (NSString *)getRequestBaseParams:(NSString *)stringJS {
    NSDictionary *tempParms = nil;
    if (stringJS) {
        // 将JSON字符串转化为NSData类型
        NSData *data = [stringJS dataUsingEncoding:NSUTF8StringEncoding];
        tempParms = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    }
    NSString *device = [FileSignature fetchUUID];
    NSString *AppSecre = @"23649898";
    NSString *apiversion = @"1";
    NSString *platform = @"ios";
    NSString *appid = @"24567001";
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:tempParms];
    
    [dic setObject:AppSecre forKey:@"appkey"];
    [dic setObject:device forKey:@"device"];
    [dic setObject:Package forKey:@"packages"];
    [dic setObject:Version forKey:@"version"];
    [dic setObject:apiversion forKey:@"apiversion"];
    [dic setObject:platform forKey:@"platform"];
    [dic setObject:appid forKey:@"appid"];
    [dic setObject:[FileSignature deviceType] forKey:@"deviceType"];
    [dic setObject:[[UIDevice currentDevice] systemVersion] forKey:@"osVersion"];
    [dic setObject:@"appstore" forKey:@"channel"];
    if ([ALUserInfoServiceManger fetchUID]) {
        [dic setObject:[ALUserInfoServiceManger fetchUID] forKey:@"uid"];
    }
    // 用户是否打开了广告标识符
    BOOL isIDFA = [[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled];
    if (isIDFA) {
        [dic setObject:[self getIDFA] forKey:@"idfa"];
    }
    //现在的时间
    NSTimeInterval timeNow = [[NSDate date] timeIntervalSince1970];
    long long int date = (long long int)timeNow*1000;
    NSString *timeStr=[NSString stringWithFormat:@"%lld",date];
    [dic setObject:timeStr forKey:@"time"];
    
    NSString *sign = [self sortingDictionaryWithdic:dic];
    [dic setValue:sign forKey:@"sign"];
    
    NSString *res = [NSString muiReactiveSendPersonInfo:dic];
    return res;
}
 
- (void)toast:(NSString *)jsStringN
{
    dispatch_async(dispatch_get_main_queue(), ^{
        if (jsStringN) {
            [JRToast showWithText:jsStringN bottomOffset:kToolBarH + 15 duration:1.5];
        }
    });
}
 
- (void)jumpGoodsSplash:(NSString *)jsStringN {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        NSDictionary *dic = @{@"type":@"new",@"id":[NSString stringWithFormat:@"%@",jsStringN]};
        [self pushjumpGoodsSplashs:dic];
    });
}
 
- (void)jumpGoodsSplashWithFrom:(NSDictionary *)dictionaryJS {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        NSString *idString = [NSString stringWithFormat:@"%@",dictionaryJS[@"id"]];
        NSString *from = dictionaryJS[@"from"];
        NSDictionary *dic = @{@"type":@"new",@"id":idString,@"from":from?:@""};
        [self pushjumpGoodsSplashs:dic];
    });
}
 
- (void)jumpGoodsDetail:(NSString *)jsStringN {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        NSDictionary *dic = @{@"type":@"old",@"id":[NSString stringWithFormat:@"%@",jsStringN]};
        [self pushjumpGoodsSplashs:dic];
    });
}
 
- (void)pushjumpGoodsSplashs:(NSDictionary *)dictionaryData {
    NSString *type = dictionaryData[@"type"];
    NSString *goodID = dictionaryData[@"id"];
    NSString *fome = dictionaryData[@"from"];
    
    if ([type isEqualToString:@"new"]) {
        GoodDeTrViewController *goodsDetailVC = [[GoodDeTrViewController alloc]init];
        goodsDetailVC.goodsID = goodID;
        goodsDetailVC.from = fome;
        goodsDetailVC.goodsType = 1;
        [self .navigationController pushViewController:goodsDetailVC animated:YES];
        
    } else {
        SureWebViewController *webView = [[SureWebViewController alloc] init];
        webView.goodsId = goodID;
        webView.canDownRefresh = YES;
        webView.isGoodsDetail = YES;
        [self.navigationController pushViewController:webView animated:YES];
    }
}
 
- (void)jumpKeFu:(NSString *)jsStringN {
    dispatch_async(dispatch_get_main_queue(), ^{
        [CustomerServiceManage pushinitMQ:jsStringN];
    });
}
 
- (void)jumpBaiChuan:(NSDictionary *)dictionaryJS {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        NSData *data = [dictionaryJS
                        [@"tbPid"] dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *tempParms = nil;
        if (data) {
            tempParms = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        }
        
        NSString *goodId = dictionaryJS[@"id"];
        NSString *url = dictionaryJS[@"url"];
        
        AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
        if (tempParms) {
            taokeParams.pid = tempParms[@"pid"]; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
            taokeParams.adzoneId = tempParms[@"adZoneId"];
            taokeParams.extParams = @{@"taokeAppkey":tempParms[@"appKey"]};
            
        } else {
            taokeParams = nil;
        }
        
        if (url && ![url isEqualToString:@""]) {
            [self.albcServiceManager pushOpenByUrl:url identity:nil webView:nil parentController:self.navigationController taoKeParams:taokeParams];
            
        } else {
            id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage:[NSString stringWithFormat:@"%@",goodId]];
            [self.albcServiceManager pushOpenByBizCode:@"detail" page:page webView:nil parentController:self.navigationController taoKeParams:taokeParams];
        }
    });
}
 
- (void)jumpPage:(NSDictionary *)dictionaryJS {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        NSError *error;
        NSData *jsonData = [dictionaryJS[@"params"] dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
        NSDictionary *dic = nil;
        if (jsonDic) {
            dic = @{@"pageClassName" : dictionaryJS[@"controller"], @"paramsJSON" : jsonDic};
            
        } else {
            dic = @{@"pageClassName" : dictionaryJS[@"controller"]};
        }
        if([[dic[@"paramsJSON"] allKeys] count] <= 0) {
            [self pushAnyInterfaceController:dic[@"pageClassName"] parms:nil];
            return ;
        }
        [self pushAnyInterfaceController:dic[@"pageClassName"] parms:dic];
    });
}
 
- (void)jumpPageWithFinishCurrentPage:(NSDictionary *)dictionaryJS {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        NSError *error;
        NSData *jsonData = [dictionaryJS[@"params"] dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
        NSDictionary *dic = nil;
        if (jsonDic) {
            dic = @{@"pageClassName" : dictionaryJS[@"controller"], @"paramsJSON" : jsonDic};
            
        } else {
            dic = @{@"pageClassName" : dictionaryJS[@"controller"]};
        }
        [self pushAnyInterfaceController:dic[@"pageClassName"] parms:dic];
        NSMutableArray *navigationVcMut = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
        for (int i = 0; i < navigationVcMut.count; i++) {
            if (i == navigationVcMut.count - 2) {
                [navigationVcMut removeObjectAtIndex:i];
                self.navigationController.viewControllers = navigationVcMut;
                break;
            }
        }
    });
}
 
- (void)umEventCount:(NSDictionary *)dictionaryJS {
    NSDictionary *dic = @{@"eventId":dictionaryJS[@"key"],@"paramsJSON":dictionaryJS[@"params"]};
    NSString *eventId = dic[@"eventId"];
    NSString *paramsJSON = dic[@"paramsJSON"];
    NSDictionary *dic1 = [self dictionaryWithJsonString:paramsJSON];
    [MobClick event:eventId attributes:dic1];
}
 
- (void)umEventCompute:(NSDictionary *)dictionaryJS {
    NSDictionary *dic = @{@"eventId":dictionaryJS[@"key"],@"paramsJSON":dictionaryJS[@"params"],@"du":[NSString stringWithFormat:@"%@",dictionaryJS[@"du"]]};
    NSString *eventId = dic[@"eventId"];
    NSString *paramsJSON = dic[@"paramsJSON"];
    int du = [dic[@"du"] intValue];
    NSDictionary *dic1 = [self dictionaryWithJsonString:paramsJSON];
    [MobClick event:eventId attributes:dic1 counter:du];
}
 
- (void)hiddenTopMenuCloseBtn {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        self.closeButton.hidden = YES;
    });
}
 
- (void)showSharePanel {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        [self.shareDictionary setObject:self.urlShare forKey:@"url"];
        self.shareAppView = [[SJDynamicShareView alloc] initShareAppView];
        @weakify(self)
        self.shareAppView.haveIndex = ^(NSString *type) {
            @strongify(self)
            [self.shareAppView dismiss];
            self.shareAppView = nil;
            
            if ([type isEqualToString:@"微信好友"]) {
                [self shareWebToPlatformType:UMSocialPlatformType_WechatSession withtype:SSDKPlatformSubTypeWechatSession];
                
            } else if ([type isEqualToString:@"朋友圈"]) {
                [self shareWebToPlatformType:UMSocialPlatformType_WechatTimeLine withtype:SSDKPlatformSubTypeWechatTimeline];
                
            } else if ([type isEqualToString:@"新浪微博"]) {
                [self shareWebToPlatformType:UMSocialPlatformType_Sina withtype:SSDKPlatformTypeSinaWeibo];
                
            } else if ([type isEqualToString:@"QQ好友"]) {
                [self shareWebToPlatformType:UMSocialPlatformType_QQ withtype:SSDKPlatformSubTypeQQFriend];
                
            } else if ([type isEqualToString:@"QQ空间"]) {
                [self shareWebToPlatformType:UMSocialPlatformType_Qzone withtype:SSDKPlatformSubTypeQZone];
            }
        };
        [self.shareAppView show];
    });
}
 
/// 分享
/// @param platformType 类型
/// @param shareType 类型
- (void)shareWebToPlatformType:(UMSocialPlatformType)platformType withtype:(SSDKPlatformType) shareType {
    SSDKContentType type = SSDKContentTypeAuto;
    type = SSDKContentTypeWebPage;
    if (shareType == SSDKPlatformSubTypeWechatTimeline || shareType == SSDKPlatformSubTypeWechatSession) {
        if (![WXApi isWXAppInstalled]) {
            [JRToast showWithText:@"微信未安装" bottomOffset:kToolBarH duration:1.5];
            return;
        }
    }
    
    if ( SSDKPlatformSubTypeQQFriend == shareType || shareType == SSDKPlatformSubTypeQZone ) {
        if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
            [JRToast showWithText:@"QQ未安装" bottomOffset:kToolBarH duration:1.5];
            return;
        }
    }
    
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:@"" images:[UIImage imageNamed:@"聊天小程序头像"] url:self.shareDictionary[@"url"] title:self.shareDictionary[@"name"] type:type];
    
    //进行分享
    [ShareSDK share:shareType //传入分享的平台类型
         parameters:shareParams
     onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { // 回调处理....}];
        switch (state) {
            case SSDKResponseStateSuccess:
            {
                break;
            }
            case SSDKResponseStateFail:
            {
                break;
            }
            default:
                break;
        }
    }];
}
 
- (void)addMenu:(NSString *)arraryJS {
    NSArray *array = nil;
    
    @try {
        NSData *jsonData = [arraryJS dataUsingEncoding:NSUTF8StringEncoding];
        array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
        
    } @catch (NSException *exception) {
       
        
    } @finally {
        if (!array) {
            array = (NSArray *)arraryJS;
        }
    }
    
    
    if (![self isHaveValue:array]) {
        return;
    }
    [self.newAddmMutArr removeAllObjects];
    for (NSDictionary *dictionary in array) {
        NSDictionary *dics = @{@"iconName":dictionary[@"name"],@"iconImage":dictionary[@"icon"],@"js":dictionary[@"js"]};
        [self.newAddmMutArr addObject:dics];
    }
}
 
- (void)copyText:(NSString *)jsStringN {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.commonMethodManage setPasteboardContent:jsStringN title:nil];
    });
}
 
- (void)jumpSearch:(NSString *)jsStringN {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        SearchDetailMainController *searchVc = [[SearchDetailMainController alloc] init];
        searchVc.searchKey = jsStringN;
        @weakify(self)
        searchVc.searchSelect = ^(NSString * _Nonnull searchstring, NSInteger goodsTypes) {
            @strongify(self)
            [self cacheHistorySearch:searchstring goodsTypes:goodsTypes];
        };
        [self.navigationController pushViewController:searchVc animated:YES];
    });
}
/// 储存搜索纪录
/// @param text 关键字
/// @param goodsTypes 类型
- (void)cacheHistorySearch:(NSString *)text goodsTypes:(NSInteger)goodsTypes {
    self.plist.dataName = [self fetchplistNames:goodsTypes];
    [self.tempOldArr removeAllObjects];
    [self.tempOldArr addObjectsFromArray:[self.plist readFile][0]];
    
    for (NSString *name in self.tempOldArr) {
        if ([name isEqualToString:text]) {
            [self.tempOldArr removeObject:name];
            break;
        }
    }
    [self.tempOldArr insertObject:text atIndex:0];
    
    if (self.tempOldArr.count > 10) {
        [self.tempOldArr removeObjectAtIndex:self.tempOldArr.count - 1];
    }
    
    self.plist.dataName = [self fetchplistNames:goodsTypes];
    [self.plist writeFileWithData:self.tempOldArr];
}
 
- (NSString *)fetchplistNames:(NSInteger)goodsTypes {
    NSString *name = nil;
    if (goodsTypes == 1) {
        name = @"historyTBSearchList";
        
    } else if (goodsTypes == 2) {
        name = @"historyJDSearchList";
        
    } else if (goodsTypes == 3) {
        name = @"historyPDDSearchList";
    }
    return name;
}
 
- (void)jumpInvite {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        InvitationFriendsViewController *invitationFriendsVc = [[InvitationFriendsViewController alloc] init];
        invitationFriendsVc.isRequestAPI = YES;
        [self.navigationController pushViewController:invitationFriendsVc animated:YES];
    });
}
 
- (void)login {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        [JRToast showWithText:@"请先登录板栗快省账号" bottomOffset:kToolBarH duration:1.2f];
        NewLoginViewController *loginVc = [[NewLoginViewController alloc] init];
        loginVc.delegate = self;
        loginVc.rootVc = self;
        loginVc.vcName = @"webLogin";
        [self.navigationController pushViewController:loginVc animated:YES];
    });
}
 
- (void)noticeMineBackEvent:(NSString *)vcName {
    if ([vcName isEqualToString:@"webLogin"]) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"noticeMessageVcUpdateData" object:nil];
        [self.messageManger getMessage];
    }
}
 
- (void)setTitles:(NSString *)jsStringN {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        NSString *title = jsStringN;
        self.urlName = title;
        self.title = title;
        [self.shareDictionary setObject:self.urlName forKey:@"name"];
    });
}
 
- (void)showLoading {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        [self.view makeToastActivity:CSToastPositionCenter];
    });
}
 
- (void)hideLoading {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        [self.view hideToastActivity];
    });
}
 
- (void)finishPage
{
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        [self.navigationController popViewControllerAnimated:YES];
    });
}
 
- (void)jumpJDGoodsDetailWithFrom:(NSDictionary *)dictionaryJS
{
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        NSString *goodsId = dictionaryJS[@"id"];
        NSString *from = dictionaryJS[@"from"];
        JDGoodsDetailController *goodsDetailVC = [[JDGoodsDetailController alloc]init];
        goodsDetailVC.goodsID = goodsId;
        goodsDetailVC.from = from;
        goodsDetailVC.goodsType = 2;
        [self .navigationController pushViewController:goodsDetailVC animated:YES];
    });
}
 
- (void)jumpPDDGoodsDetailWithFrom:(NSDictionary *)dictionaryJS
{
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        NSString *goodsId = dictionaryJS[@"id"];
        NSString *from = dictionaryJS[@"from"];
        PDDGoodsDetailController *goodsDetailVC = [[PDDGoodsDetailController alloc]init];
        goodsDetailVC.goodsID = goodsId;
        goodsDetailVC.from = from;
        goodsDetailVC.goodsType = 3;
        [self .navigationController pushViewController:goodsDetailVC animated:YES];
    });
}
 
- (void)shareLink:(NSDictionary *)dictionaryJS {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        if ([dictionaryJS[@"type"] integerValue] == 1) {
            [self shareWebPageType:SSDKPlatformSubTypeWechatSession dictionaryData:dictionaryJS types:0];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 2) {
            [self shareWebPageType:SSDKPlatformSubTypeWechatTimeline dictionaryData:dictionaryJS types:0];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 3) {
            [self shareWebPageType:SSDKPlatformSubTypeQQFriend dictionaryData:dictionaryJS types:0];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 4) {
            [self shareWebPageType:SSDKPlatformSubTypeQZone dictionaryData:dictionaryJS types:0];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 5) {
            [self shareWebPageType:SSDKPlatformTypeSinaWeibo dictionaryData:dictionaryJS types:0];
        }
    });
}
 
- (void)shareImg:(NSDictionary *)dictionaryJS {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        if ([dictionaryJS[@"type"] integerValue] == 1) {
            [self shareWebPageType:SSDKPlatformSubTypeWechatSession dictionaryData:dictionaryJS types:1];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 2) {
            [self shareWebPageType:SSDKPlatformSubTypeWechatTimeline dictionaryData:dictionaryJS types:1];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 3) {
            [self shareWebPageType:SSDKPlatformSubTypeQQFriend dictionaryData:dictionaryJS types:1];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 4) {
            [self shareWebPageType:SSDKPlatformSubTypeQZone dictionaryData:dictionaryJS types:1];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 5) {
            [self shareWebPageType:SSDKPlatformTypeSinaWeibo dictionaryData:dictionaryJS types:1];
        }
    });
}
 
- (void)shareText:(NSDictionary *)dictionaryJS {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        if ([dictionaryJS[@"type"] integerValue] == 1) {
            [self shareWebPageType:SSDKPlatformSubTypeWechatSession dictionaryData:dictionaryJS types:2];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 2) {
            [self shareWebPageType:SSDKPlatformSubTypeWechatTimeline dictionaryData:dictionaryJS types:2];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 3) {
            [self shareWebPageType:SSDKPlatformSubTypeQQFriend dictionaryData:dictionaryJS types:2];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 4) {
            [self shareWebPageType:SSDKPlatformSubTypeQZone dictionaryData:dictionaryJS types:2];
            
        } else if ([dictionaryJS[@"type"] integerValue] == 5) {
            [self shareWebPageType:SSDKPlatformTypeSinaWeibo dictionaryData:dictionaryJS types:2];
        }
    });
}
 
- (void)savePicture:(NSString *)stringJS {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:stringJS]]];
        UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
    });
}
 
- (void)savedPhotoImage:(UIImage*)image didFinishSavingWithError :(NSError *)error contextInfo: (void *)contextInfo {
    if (_isDownMoreImg) {
        if (error) {
            
        } else {
            [_arrayShareImage removeObjectAtIndex:0];
        }
        [self saveToAlbumNext];
        
    } else {
        if (!error) {
            ALToastCenter(@"图片保存到相册成功");
        }
    }
}
 
/// 分享
/// @param shareType 分享类型
/// @param dictionaryData 分享数据
/// @param types 0-link 1-图片 2-纯文字 3-多图片
- (void)shareWebPageType:(SSDKPlatformType)shareType dictionaryData:(id)dictionaryData types:(NSInteger)types {
    
    SSDKContentType type = SSDKContentTypeAuto;
    if (shareType == SSDKPlatformSubTypeWechatTimeline || shareType == SSDKPlatformSubTypeWechatSession) {
        if (![WXApi isWXAppInstalled]) {
            [JRToast showWithText:@"微信未安装" bottomOffset:kToolBarH duration:1.5f];
            return;
        }
    }
    
    if ( SSDKPlatformSubTypeQQFriend == shareType || shareType == SSDKPlatformSubTypeQZone ) {
        if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
            [JRToast showWithText:@"QQ未安装" bottomOffset:kToolBarH duration:1.5f];
            return;
        }
    }
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    if (types == 0) {
        [shareParams SSDKSetupShareParamsByText:dictionaryData[@"content"] images:dictionaryData[@"img"] url:dictionaryData[@"url"] title:dictionaryData[@"title"] type:type];
        
    } else  if (types == 1) {
        [shareParams SSDKSetupShareParamsByText:nil images:dictionaryData[@"url"] url:nil title:nil type:type];
        
    } else if (types == 2) {
        [shareParams SSDKSetupShareParamsByText:dictionaryData[@"text"] images:nil url:nil title:nil type:type];
        
    } else if (types == 3) {
        [shareParams SSDKSetupShareParamsByText:nil images:(NSArray *)dictionaryData url:nil title:nil type:type];
    }
    
    //进行分享
    [ShareSDK share:shareType //传入分享的平台类型
         parameters:shareParams
     onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) { // 回调处理....}];
        switch (state) {
            case SSDKResponseStateSuccess:
            {
                break;
            }
            case SSDKResponseStateFail:
            {
                break;
            }
            default:
                break;
        }
    }];
}
 
- (NSString *)screeningTbId:(NSString *)url {
    if ([url rangeOfString:@"//detail.m.tmall.com/item.htm?"].location != NSNotFound ||
        [url rangeOfString:@"//h5.m.taobao.com/awp/core/detail.htm?"].location != NSNotFound ||
        [url rangeOfString:@"//detail.m.tmall.hk/item.htm?"].location != NSNotFound ||
        [url rangeOfString:@"//detail.m.tmall.com/templatesNew/index?"].location != NSNotFound) {
        
        NSString *goodsDetailId = nil;
        NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
        NSArray *andSegmentationArr = [questionSegmentationArr[1] componentsSeparatedByString:@"&"];
        
        for (NSString *temp in andSegmentationArr) {
            if ([temp hasPrefix:@"id="]) {
                NSArray *goodsIdArr = [temp componentsSeparatedByString:@"="];
                goodsDetailId = goodsIdArr[1];
                break;
            }
        }
        return  goodsDetailId;
        
    } else if ([url rangeOfString:@"//ju.taobao.com/m/jusp/alone/detailwap/mtp.htm?"].location != NSNotFound) {
        
        NSString *goodsDetailId = nil;
        NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
        NSArray *andSegmentationArr = [questionSegmentationArr[1] componentsSeparatedByString:@"&"];
        
        for (NSString *temp in andSegmentationArr) {
            if ([temp hasPrefix:@"item_id="]) {
                NSArray *goodsIdArr = [temp componentsSeparatedByString:@"="];
                goodsDetailId = goodsIdArr[1];
                break;
            }
        }
        return goodsDetailId;
    }
    return nil;
}
 
- (NSString *)screeningJdId:(NSString *)url {
    if ([url rangeOfString:@"https://item.m.jd.com/product/"].location != NSNotFound ||
        [url rangeOfString:@"http://item.m.jd.com/product/"].location != NSNotFound ||
        [url rangeOfString:@"https://item.jd.com/"].location != NSNotFound ||
        [url rangeOfString:@"http://item.jd.com/"].location != NSNotFound) {
        
        NSString *goodsDetailId = nil;
        NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
        NSArray *andSegmentationArr = [questionSegmentationArr[0] componentsSeparatedByString:@"/"];
        NSArray *indexArr = [andSegmentationArr[andSegmentationArr.count - 1] componentsSeparatedByString:@"."];
        goodsDetailId = indexArr[0];
        return  goodsDetailId;
        
    } else if ([url rangeOfString:@"https://item.m.jd.com/ware/view.action?"].location != NSNotFound) {
        
        NSString *goodsDetailId = nil;
        NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
        NSArray *andSegmentationArr = [questionSegmentationArr[1] componentsSeparatedByString:@"&"];
        
        for (NSString *temp in andSegmentationArr) {
            if ([temp hasPrefix:@"wareId="]) {
                NSArray *goodsIdArr = [temp componentsSeparatedByString:@"="];
                goodsDetailId = goodsIdArr[1];
                break;
            }
        }
        return  goodsDetailId;
    }
    return  nil;
}
 
- (NSString *)screeningPddId:(NSString *)url {
    if ([url rangeOfString:@"://mobile.yangkeduo.com/goods.html?"].location != NSNotFound ||
        [url rangeOfString:@"yangkeduo.com/duo_coupon_landing.html?"].location != NSNotFound ||
        [url rangeOfString:@"://mobile.yangkeduo.com/goods2.html?"].location != NSNotFound) {
        
        NSString *goodsDetailId = nil;
        NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
        NSArray *andSegmentationArr = [questionSegmentationArr[1] componentsSeparatedByString:@"&"];
        
        for (NSString *temp in andSegmentationArr) {
            if ([temp hasPrefix:@"goods_id="]) {
                NSArray *goodsIdArr = [temp componentsSeparatedByString:@"="];
                goodsDetailId = goodsIdArr[1];
                break;
            }
        }
        return  goodsDetailId;
    }
    return  nil;
}
 
- (BOOL)isPureInt:(NSString*)string {
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return[scan scanInt:&val] && [scan isAtEnd];
}
 
- (NSString *)screeningWPHId:(NSString *)url {
    if (([url rangeOfString:@".vip.com/"].location != NSNotFound &&
         [url rangeOfString:@"detail-"].location != NSNotFound) ||
        [url rangeOfString:@"product-"].location != NSNotFound) {
        
        if ([self.from isEqualToString:@"goodsDetail"]) {
            return nil;
        }
        
        NSString *goodsDetailId = nil;
        NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
        NSArray *andSegmentationArr = [questionSegmentationArr[0] componentsSeparatedByString:@"-"];
        
        for (NSString *temp in andSegmentationArr) {
            if ([temp hasSuffix:@".html"]) {
                goodsDetailId = [temp stringByReplacingOccurrencesOfString:@".html" withString:@""];
                if ([self isPureInt:goodsDetailId]) {
                    break;
                    
                } else {
                    goodsDetailId = nil;
                }
            }
        }
        return  goodsDetailId;
    }
    return  nil;
}
 
- (NSString *)screeningSNId:(NSString *)url {
    if (([url rangeOfString:@"suning.com/"].location != NSNotFound &&
         [url rangeOfString:@"suning.com/product/"].location != NSNotFound) ||
        [url rangeOfString:@"product.suning.com/"].location != NSNotFound) {
        
        if ([self.from isEqualToString:@"goodsDetail"]) {
            return nil;
        }
        
        NSMutableString *goodsDetailId = [[NSMutableString alloc] init];
        
        NSArray *questionSegmentationArr = [url componentsSeparatedByString:@"?"];
        NSArray *andSegmentationArr = [questionSegmentationArr[0] componentsSeparatedByString:@"/"];
        
        for (NSString *temp in andSegmentationArr) {
            NSString *tempName = [temp stringByReplacingOccurrencesOfString:@".html" withString:@""];
            
            if ([self isPureInt:tempName]) {
                [goodsDetailId appendString:tempName];
            }
        }
        return  goodsDetailId;
    }
    return  nil;
}
 
- (void)jumpJD:(NSDictionary *)dictionary {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        [self pushJingDong:YES jumpLink:dictionary[@"url"]];
    });
}
 
- (void)tbAuth:(NSDictionary *)dictionary {
    @weakify(self)
    dispatch_async(dispatch_get_main_queue(), ^{
        @strongify(self)
        [self.albcServiceManager pushAuthOpenByUrl:dictionary[@"url"] identity:nil parentController:self.navigationController];
    });
}
 
- (void)clearClipboard {
    [self.commonMethodManage clearClipboard];
}
 
//跳转微信小程序
- (void)jumpWXXCX:(NSDictionary *)dictionary {
    [self.commonMethodManage launchMiniProgramWithUserName:dictionary[@"userName"] path:dictionary[@"path"] type:0];
}
 
- (void)shareWXXCX:(NSDictionary *)dictionary {
    
}
 
- (void)shareImgs:(NSDictionary *)dictionary {
    NSString *jsonString = dictionary[@"imgUrls"];
    if (!jsonString) return;
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    
    NSMutableArray *mutArr = [[NSMutableArray alloc] init];
    
    dispatch_async(dispatch_get_global_queue(0,0),^{
        for (NSString *string in array) {
            UIImage *iamge = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:string]]];
            [mutArr addObject:iamge];
        }
        @weakify(self)
        dispatch_async(dispatch_get_main_queue(),^{
            @strongify(self)
            UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:mutArr applicationActivities:nil];
            activityVC.excludedActivityTypes = @[UIActivityTypeAirDrop,UIActivityTypeMessage,UIActivityTypeMail];
            activityVC.modalInPopover = YES;
            activityVC.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
                if (completed == YES) {
                    NSLog(@"completed");
                    
                } else {
                    NSLog(@"cancel");
                }
            };
            //4、调用控制器
            [self presentViewController:activityVC animated:YES completion:nil];
        });
    });
}
 
- (void)savePictures:(NSString *)string {
    if (!string) return;
    NSData *jsonData = [string dataUsingEncoding:NSUTF8StringEncoding];
    NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    
    [self.view makeToastActivity:CSToastPositionCenter];
    self.view.userInteractionEnabled = NO;
    self.isDownMoreImg = YES;
    [self.arrayShareImage removeAllObjects];
    @weakify(self)
    dispatch_async(dispatch_get_global_queue(0,0),^{
        @strongify(self)
        for (NSString *string in array) {
            UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:string]]];
            [self.arrayShareImage addObject:image];
        }
        @weakify(self)
        dispatch_async(dispatch_get_main_queue(),^{
            @strongify(self)
            [self saveToAlbumNext];
        });
    });
}
 
/// 保存相册
-(void)saveToAlbumNext {
    if (_arrayShareImage.count > 0) {
        UIImage *image = _arrayShareImage[0];
        UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
        
    } else {
        [self allDone];
        [self.view hideToastActivity];
        self.view.userInteractionEnabled = YES;
    }
}
 
- (void)allDone {
    ALToastCenter(@"分享图保存成功");
}
 
- (void)showimgs:(NSDictionary *)dictionary {
    NSData *jsonData = [dictionary[@"imgList"] dataUsingEncoding:NSUTF8StringEncoding];
    NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    
    NSMutableArray *arrayImgs = [[NSMutableArray alloc] init];
    for (NSDictionary *dictionary in array) {
        [arrayImgs addObject:dictionary[@"url"]];
    }
    int index = 0;
    if (dictionary[@"position"]) {
        index  = [dictionary[@"position"] intValue];
    }
    HZPhotoBrowser *browser = [[HZPhotoBrowser alloc] init];
    browser.isFullWidthForLandScape = YES;
    browser.isNeedLandscape = NO;
    browser.currentImageIndex = index;
    browser.imageArray = arrayImgs;
    [browser show];
}
 
/**
 * 拦截网页中的商品
 */
- (void)interceptWebGoods:(NSString *)goodsDetailId goodsType:(NSString *)goodsType {
    @weakify(self)
    [[ALNetWorking startInterface] Post:[NSString stringWithFormat:@"%@/%@",domainHTTP2,@"goods/isGoodsExtend"] param:@{@"goodsId":goodsDetailId,@"goodsType":goodsType} success:^(NSDictionary *object) {
        @strongify(self)
        @weakify(self)
        dispatch_async(dispatch_get_main_queue(), ^{
            @strongify(self)
            if ([object[@"code"] integerValue] == 0) {
                if ([object[@"data"][@"extend"] boolValue]) {
                    [self.commonMethodManage pushGoodsinfoDetail:goodsDetailId from:@"baichuanweb" goodsType:[goodsType integerValue]];
                    
                } else {
                    NoCouponNoRebateController *noCouponNoRebateVc = [[NoCouponNoRebateController alloc] init];
                    noCouponNoRebateVc.urlString = object[@"data"][@"url"];
                    [self.navigationController pushViewController:noCouponNoRebateVc animated:YES];
                }
            }
        });
        
    } fail:^(id object) {
        
    }];
}
 
#pragma mark - KVO
// 计算wkWebView进度条
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    
    if (object == self.webView && [keyPath isEqualToString:@"estimatedProgress"]) {
        CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
        if (newprogress == 1) {
            [self.progressView setProgress:1.0 animated:YES];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                self.progressView.hidden = YES;
                [self.progressView setProgress:0 animated:NO];
            });
            
        }else {
            self.progressView.hidden = NO;
            [self.progressView setProgress:newprogress animated:YES];
        }
        
    } else if ([keyPath isEqualToString:@"title"]) {//网页title
        if (object == self.webView) {
            if (self.navaTitle) {
                self.urlName = self.navaTitle;
                self.title = self.navaTitle;
                
            } else {
                self.urlName = self.webView.title;
                self.title = self.webView.title;
            }
            [self.shareDictionary setObject:self.urlName forKey:@"name"];
            
        } else {
            [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
        }
        
    } else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}
 
#pragma mark - WKScriptMessageHandler
// 决定导航的动作,通常用于处理跨域的链接能否导航。
// WebKit对跨域进行了安全检查限制,不允许跨域,因此我们要对不能跨域的链接单独处理。
// 但是,对于Safari是允许跨域的,不用这么处理。
// 这个是决定是否Request
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    // 在发送请求之前,决定是否跳转
    NSString * urlStr = navigationAction.request.URL.absoluteString;
    
    if ([urlStr hasPrefix:@"itms-appss://"]) {
        if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
            [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
            decisionHandler(WKNavigationActionPolicyCancel);
            return;
        }
    }
    
    if ([urlStr hasPrefix:@"pinduoduo://"]) {
        if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
            [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
            decisionHandler(WKNavigationActionPolicyCancel);
            return;
        }
    }
    
    if ([urlStr hasPrefix:@"suning://"]) {
        if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
            [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
            decisionHandler(WKNavigationActionPolicyCancel);
            return;
        }
    }
    
    if ([urlStr hasPrefix:@"vipshop://"]) {
        if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
            [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
            decisionHandler(WKNavigationActionPolicyCancel);
            return;
        }
    }
    
    if ([urlStr rangeOfString:@"shop.banliapp.com://"].location != NSNotFound) {
        // 设置webView的头部参数Referer
        if (!navigationAction.request.allHTTPHeaderFields[@"Referer"]) {
            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:navigationAction.request.URL];
            [request setValue:@"shop.banliapp.com://" forHTTPHeaderField:@"Referer"];
            [webView loadRequest:request];
        }
    }
    
    if ([urlStr rangeOfString:@"shop.banliapp.com://"].location != NSNotFound) {
        [webView goBack];
        NSString *urlSecond = [navigationAction.request.URL.absoluteString stringByReplacingOccurrencesOfString:@"shop.banliapp.com://" withString:@"http://"];
        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlSecond]]];
        decisionHandler(WKNavigationActionPolicyCancel);
        return;
    }
    
    // 拦截微信支付
    if ([urlStr rangeOfString:@"weixin://wap/pay?"].location != NSNotFound) {
        if ([WXApi isWXAppInstalled]) {
            if (@available(iOS 10.0, *)) { // 10.0以上的版本
                if([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
                    [[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:nil];
                }
                
            } else { // 10.0以下的版本
                if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:)]) {
                    [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
                }
            }
            
        } else {
            [JRToast showWithText:@"尚未安装微信" bottomOffset:kToolBarH + 15 duration:1.2f];
        }
        decisionHandler(WKNavigationActionPolicyCancel);
        return;
    }
    
    BOOL isAllow = [CZBInfoManager webView:webView decidePolicyForNavigationAction:navigationAction];
    if (!isAllow) {
        WKNavigationActionPolicy actionPolicy = isAllow ? WKNavigationActionPolicyAllow:WKNavigationActionPolicyCancel;
        decisionHandler(actionPolicy);
        return;
    }
    
    if (![urlStr hasPrefix:@"http"]) {
        decisionHandler(WKNavigationActionPolicyCancel);
        return;
    }
    
    if ([urlStr rangeOfString:@"yestv://"].location !=NSNotFound || [urlStr rangeOfString:@"fanli://"].location !=NSNotFound ) {
        NSArray *array = [urlStr componentsSeparatedByString:@"#"];
        if ([array[0] isEqualToString:@"yestv://copy"]) {
            NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:array[1] options:0];
            NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
            [self.commonMethodManage setPasteboardContent:decodedString title:@"复制成功!"];
            
        } else if ([array[0] isEqualToString:@"yestv://setShareBtn"]) {
            
        } else if ([array[0] isEqualToString:@"yestv://toast"]) {
            ALToastBottom([GTMBase64 decodeBase64String:array[1]]);
        }
    }
    
    if (self.goodsDetail) {
        NSString *tbId = [self screeningTbId:urlStr];
        NSString *jdId = [self screeningJdId:urlStr];
        NSString *pddId = [self screeningPddId:urlStr];
        NSString *wphId = [self screeningWPHId:urlStr];
        NSString *snId = [self screeningSNId:urlStr];
        
        if (tbId) {
            [self interceptWebGoods:tbId goodsType:@"1"];
            
        } else if (jdId) {
            [self interceptWebGoods:jdId goodsType:@"2"];
            
        } else if (pddId) {
            [self interceptWebGoods:pddId goodsType:@"3"];
            
        } else if (wphId) {
            [self interceptWebGoods:wphId goodsType:@"4"];
            
        } else if (snId) {
            [self interceptWebGoods:snId goodsType:@"5"];
            
        }
        
        if (tbId || jdId || pddId || wphId || snId) {
            decisionHandler(WKNavigationActionPolicyCancel);
            return;
        }
    }
    
    if (navigationAction.targetFrame == nil) {
        [webView loadRequest:navigationAction.request];
    }
    decisionHandler(WKNavigationActionPolicyAllow);
    
}
 
// 根据客户端受到的服务器响应头以及response相关信息来决定是否可以跳转
- (void)webView:(WKWebView *)webView
decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse
decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
    // 在收到响应后,决定是否跳转和发送请求之前那个允许配套使用
    decisionHandler(WKNavigationResponsePolicyAllow);
}
 
//用于授权验证的API,与AFN、UIWebView的授权验证API是一样的 需要响应身份验证时调用 同样在block中需要传入用户身份凭证
- (void)webView:(WKWebView *)webView
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *__nullable credential))completionHandler {
    
    completionHandler(NSURLSessionAuthChallengePerformDefaultHandling ,nil);
}
 
// 页面开始加载时调用
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
    if (!self.navaTitle) {
        self.title = @"网页加载中...";
        
    } else {
        self.title = self.navaTitle;
    }
}
 
// 当main frame接收到服务重定向时调用
- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
    // 接收到服务器跳转请求之后调用
}
 
// 页面加载失败时调用
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
    if (![self socketReachabilityTest]) {
        if (!self.navaTitle) {
            self.title = @"网页无法打开";
            
        } else {
            self.title = self.navaTitle;
        }
    }
}
 
// 当内容开始返回时调用
- (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation {
    
}
 
// 页面加载完成之后调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
    NSString *urlRequestString = webView.URL.absoluteString;
    self.urlShare = urlRequestString;
    
    if (self.navaTitle) { // 设置标题
        self.urlName = self.navaTitle;
        self.title = self.navaTitle;
        
    } else {
        self.urlName = self.webView.title;
        self.title = self.webView.title;
    }
    [self.shareDictionary setObject:self.urlName forKey:@"name"];
    
    self.isWebViewLoad = YES;
}
// 当main frame最后下载数据失败时,会回调
- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
    
}
 
// 当web content处理完成时,会回调 进程被终止时调用
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
    
}
 
#pragma mark - UIDelegate
// JS端调用prompt函数时,会触发此代理方法。
- (void)webView:(WKWebView *)webView
runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt
    defaultText:(nullable NSString *)defaultText
initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * __nullable result))completionHandler {
    
    NSError *err = nil;
    NSData *dataFromString = [prompt dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *payload = [NSJSONSerialization JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:&err];
    if (!err)
    {
        NSString *type = [payload objectForKey:@"type"];
        if (type && [type isEqualToString:@"getUid"]){
            NSString *returnValue = [self getUid];
            completionHandler(returnValue);
            
        } else if (type && [type isEqualToString:@"getVersion"]){
            NSString *returnValue = [self getVersion];
            completionHandler(returnValue);
            
        } else if (type && [type isEqualToString:@"getSign"]){
            NSString *params = [payload objectForKey:@"params"];
            NSString *returnValue = [self getSign:params];
            completionHandler(returnValue);
            
        } else if (type && [type isEqualToString:@"getRequestBaseParams"]){
            NSString *params = [payload objectForKey:@"params"];
            NSString *returnValue = [self getRequestBaseParams:params];
            completionHandler(returnValue);
            
        }
    }
}
 
#pragma mark - WKScriptMessageHandler
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
    //message.body  --  Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
    NSLog(@"body:%@",message.body);
    if ([message.name isEqualToString:@"toast"]) {
        [self toast:message.body];
        
    } else if ([message.name isEqualToString:@"jumpGoodsSplash"]) {
        [self jumpGoodsSplash:message.body];
        
    } else if ([message.name isEqualToString:@"jumpGoodsSplashWithFrom"]) {
        [self jumpGoodsSplashWithFrom:message.body];
        
    } else if ([message.name isEqualToString:@"jumpGoodsDetail"]) {
        [self jumpGoodsDetail:message.body];
        
    } else if ([message.name isEqualToString:@"jumpKeFu"]) {
        [self jumpKeFu:message.body];
        
    } else if ([message.name isEqualToString:@"jumpBaiChuan"]) {
        [self jumpBaiChuan:message.body];
        
    } else if ([message.name isEqualToString:@"jumpPage"]) {
        [self jumpPage:message.body];
        
    } else if ([message.name isEqualToString:@"jumpPageWithFinishCurrentPage"]) {
        [self jumpPageWithFinishCurrentPage:message.body];
        
    } else if ([message.name isEqualToString:@"umEventCount"]) {
        [self umEventCount:message.body];
        
    } else if ([message.name isEqualToString:@"umEventCompute"]) {
        [self umEventCompute:message.body];
        
    } else if ([message.name isEqualToString:@"hiddenTopMenuCloseBtn"]) {
        [self hiddenTopMenuCloseBtn];
        
    } else if ([message.name isEqualToString:@"showSharePanel"]) {
        [self showSharePanel];
        
    } else if ([message.name isEqualToString:@"addMenu"]) {
        [self addMenu:message.body];
        
    } else if ([message.name isEqualToString:@"copyText"]) {
        [self copyText:message.body];
        
    } else if ([message.name isEqualToString:@"jumpSearch"]) {
        [self jumpSearch:message.body];
        
    } else if ([message.name isEqualToString:@"jumpInvite"]) {
        [self jumpInvite];
        
    } else if ([message.name isEqualToString:@"login"]) {
        [self login];
        
    } else if ([message.name isEqualToString:@"setTitle"]) {
        [self setTitle:message.body];
        
    } else if ([message.name isEqualToString:@"showLoading"]) {
        [self showLoading];
        
    } else if ([message.name isEqualToString:@"hideLoading"]) {
        [self hideLoading];
        
    } else if ([message.name isEqualToString:@"finishPage"]) {
        [self finishPage];
        
    } else if ([message.name isEqualToString:@"jumpJDGoodsDetailWithFrom"]) {
        [self jumpJDGoodsDetailWithFrom:message.body];
        
    } else if ([message.name isEqualToString:@"jumpPDDGoodsDetailWithFrom"]) {
        [self jumpPDDGoodsDetailWithFrom:message.body];
        
    } else if ([message.name isEqualToString:@"shareLink"]) {
        [self shareLink:message.body];
        
    } else if ([message.name isEqualToString:@"shareImg"]) {
        [self shareImg:message.body];
        
    } else if ([message.name isEqualToString:@"savePicture"]) {
        [self savePicture:message.body];
        
    } else if ([message.name isEqualToString:@"jumpJD"]) {
        [self jumpJD:message.body];
        
    } else if ([message.name isEqualToString:@"tbAuth"]) {
        [self tbAuth:message.body];
        
    } else if ([message.name isEqualToString:@"shareText"]) {
        [self shareText:message.body];
        
    } else if ([message.name isEqualToString:@"clearClipboard"]) {
        [self clearClipboard];
        
    } else if ([message.name isEqualToString:@"jumpWXXCX"]) {
        [self jumpWXXCX:message.body];
        
    } else if ([message.name isEqualToString:@"shareWXXCX"]) {
        [self shareWXXCX:message.body];
        
    } else if ([message.name isEqualToString:@"shareImgs"]) {
        [self shareImgs:message.body];
        
    }  else if ([message.name isEqualToString:@"savePictures"]) {
        [self savePictures:message.body];
        
    } else if ([message.name isEqualToString:@"showimgs"]) {
        [self showimgs:message.body];
    }
}
 
- (NSString *)getIDFA {
    SEL advertisingIdentifierSel = sel_registerName("advertisingIdentifier");
    SEL UUIDStringSel = sel_registerName("UUIDString");
    
    ASIdentifierManager *manager = [ASIdentifierManager sharedManager];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    if([manager respondsToSelector:advertisingIdentifierSel]) {
        
        id UUID = [manager performSelector:advertisingIdentifierSel];
        
        if([UUID respondsToSelector:UUIDStringSel]) {
            
            return [UUID performSelector:UUIDStringSel];
        }
    }
#pragma clang diagnostic pop
    return nil;
}
 
- (NSString *)sortingDictionaryWithdic:(NSDictionary *)dic {
    NSMutableArray *array = @[].mutableCopy;
    for (NSInteger index = 0; index < dic.allKeys.count; index ++) {
        [array addObject:[NSString stringWithFormat:@"%@=%@",dic.allKeys[index],dic.allValues[index]]];
    }
    NSArray *resultArray = [array sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        /*
         排序结果
         NSComparisonResult resuest = [obj1 compare:obj2];为从小到大,即升序;
         NSComparisonResult resuest = [obj2 compare:obj1];为从大到小,即降序;
         注意:compare方法是区分大小写的,即按照ASCII排序
         */
        //排序操作
        NSComparisonResult resuest = [obj1 compare:obj2];
        return resuest;
    }];
    
    NSString *resultString = @"";
    for (NSInteger index = 0; index < resultArray.count; index ++) {
        if (index == 0) {
            resultString = [NSString stringWithFormat:@"%@",resultArray[index]];
            continue;
        }
        resultString = [NSString stringWithFormat:@"%@&%@",resultString,resultArray[index]];
    }
    
    resultString = [resultString stringByAppendingString:@"&buXiNjie2017!"];
    resultString = [NSString md5:resultString];
    return resultString;
}
 
- (NSString *)convertToJsonData:(NSDictionary *)dict {
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString;
    if (!jsonData) {
        NSLog(@"%@",error);
        
    } else {
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    return jsonString;
}
 
- (UIView *)navGaryLine {
    if (!_navGaryLine) {
        _navGaryLine = [[UIView alloc] init];
        _navGaryLine.frame = CGRectMake(0, 0, SCREEN_WIDTH, 0.5);
        _navGaryLine.backgroundColor = UIColorFromRGBValue(0xe0e0e0);
    }
    return _navGaryLine;
}
 
- (NSMutableArray *)dataMutArr {
    if (!_dataMutArr) {
        _dataMutArr = [[NSMutableArray alloc] init];
    }
    return _dataMutArr;
}
 
- (NSMutableArray *)newAddmMutArr {
    if (!_newAddmMutArr) {
        _newAddmMutArr = [[NSMutableArray alloc] init];
    }
    return _newAddmMutArr;
}
 
- (NSArray *)gudingArr {
    if (!_gudingArr) {
        _gudingArr = @[@{@"iconName" : @"刷新", @"iconImage" : @"web_refresh",@"js":@"refresh"},
                       @{@"iconName" : @"人工客服", @"iconImage" : @"web_rengong",@"js":@"kefu"}];
    }
    return _gudingArr;
}
 
- (NSMutableArray *)tempOldArr {
    if (!_tempOldArr) {
        _tempOldArr = [[NSMutableArray alloc] init];
    }
    return _tempOldArr;
}
 
- (NSMutableArray *)arrayShareImage {
    if (!_arrayShareImage) {
        _arrayShareImage = [[NSMutableArray alloc] init];
    }
    return _arrayShareImage;
}
 
@end