JYNewMineViewController.m 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  1. //
  2. // JYNewSearchViewController.m
  3. // JianYuIOS
  4. //
  5. // Created by apple on 2020/6/5.
  6. // Copyright © 2020 lixianglan. All rights reserved.
  7. //
  8. #import "JYNewMineViewController.h"
  9. #import <WebKit/WebKit.h>
  10. #import "JYTabBarController.h"
  11. #import <CoreLocation/CoreLocation.h>
  12. /*
  13. afterPageInit 报异常
  14. afterClickBack 侧滑返回 首页-
  15. 分享回调报异常
  16. 不能支付
  17. */
  18. @interface JYNewMineViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,SKProductsRequestDelegate,WBFaceVerifyCustomerServiceDelegate,ZKClipboardViewDelegate>
  19. {
  20. CGPoint startTouch;
  21. BOOL _isMoving;
  22. BOOL isExistNoNewWork;
  23. }
  24. @property (nonatomic, strong) UIProgressView *progressView;
  25. @property (nonatomic, strong) WKWebView *webView;
  26. @property(nonatomic, assign)BOOL updateNotify;
  27. @property(nonatomic, strong)NoNetView *noNetView;
  28. @property(nonatomic, strong)NoNetView *failNetView;
  29. @property(nonatomic, strong)UIPanGestureRecognizer *recognizer;
  30. @property(nonatomic, strong)ZKClipboardView *clipboardView;
  31. @property(nonatomic, strong)ZKFaceVerifyMsgView *verifyMsgView;
  32. @end
  33. NSString *const new_kInitVector_4 = @"1389461544135476";
  34. size_t const new_kKeySize_4 = kCCKeySizeAES128;
  35. NSString *const new_AesKey_4 = @"mGlAgnIBB8bx2nch";
  36. @implementation JYNewMineViewController
  37. -(void)viewWillAppear:(BOOL)animated
  38. {
  39. [super viewWillAppear:animated];
  40. [self.navigationController setNavigationBarHidden:YES animated:animated];
  41. if([GlobalData shareInstance].mineIsRed) {
  42. [GlobalData shareInstance].mineIsRed = NO;
  43. [self webViewFirstRequest];
  44. }
  45. }
  46. //弹框
  47. -(ZKFaceVerifyMsgView *)verifyMsgView
  48. {
  49. if(!_verifyMsgView) {
  50. _verifyMsgView = [[ZKFaceVerifyMsgView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 150)];
  51. _verifyMsgView.titleName = @"温馨提示";
  52. }
  53. return _verifyMsgView;
  54. }
  55. //进度条
  56. - (UIProgressView *)progressView
  57. {
  58. if (_progressView == nil) {
  59. _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,STATUS_BAR_HEIGHT - 2,WIDTH,2)];
  60. _progressView.tintColor = [UIColor blueColor];
  61. _progressView.trackTintColor = [UIColor whiteColor];
  62. }
  63. return _progressView;
  64. }
  65. //弹框
  66. -(ZKClipboardView *)clipboardView{
  67. if(!_clipboardView) {
  68. _clipboardView = [[ZKClipboardView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 180+90)];
  69. _clipboardView.delegate = self;
  70. }
  71. return _clipboardView;
  72. }
  73. //懒加载
  74. - (WKWebView *)webView
  75. {
  76. if(_webView == nil) {
  77. WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
  78. config.preferences = [[WKPreferences alloc] init];
  79. config.preferences.minimumFontSize = 0;
  80. config.allowsInlineMediaPlayback = YES;
  81. config.preferences.javaScriptEnabled = YES;
  82. config.preferences.javaScriptCanOpenWindowsAutomatically = YES;
  83. //添加消息处理,注意:self指代的是需要遵守WKScriptMessageHandler协议,结束时需要移除
  84. config.userContentController = [[WKUserContentController alloc] init];
  85. //声明协议
  86. NSArray *jsArr = @[@"loginByWeixin",
  87. @"share",
  88. @"saveUserToken",
  89. @"removeUserToken",
  90. @"openSystemNotification",
  91. @"openExternalLink",
  92. @"alert",
  93. @"hiddenBottom",
  94. @"checkLab",
  95. @"loginSuccess",
  96. @"backUrl",
  97. @"clearPushMessage",
  98. @"hideRedSpotOnMenu",
  99. @"showRedSpotOnMenu",
  100. @"wxPay",
  101. @"aliPay",
  102. @"skipCameraWithParam",
  103. @"skipAlbumWithParam",
  104. @"openActivityPage",
  105. @"callPhone",
  106. @"openOtherAppLinks",
  107. @"inPurchasingVip",
  108. @"wirteRight",
  109. @"clearRight",
  110. @"savePic",
  111. @"ocrVerifyService",
  112. @"faceVerifyService",
  113. ];
  114. for (NSString*jsName in jsArr) {
  115. [config.userContentController addScriptMessageHandler:self name:jsName];
  116. }
  117. //高端的自定义配置创建WKWebView
  118. if (iPhoneX) {
  119. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT) configuration:config];
  120. if (@available(iOS 11.0, *)) {
  121. _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  122. }
  123. }else {
  124. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT) configuration:config];
  125. }
  126. _webView.scrollView.bounces = NO;
  127. _webView.UIDelegate = self;
  128. _webView.navigationDelegate = self;
  129. // _webView.allowsBackForwardNavigationGestures = true;
  130. _webView.userInteractionEnabled = YES;
  131. [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  132. }
  133. return _webView;
  134. }
  135. -(void)webViewFirstRequest
  136. {
  137. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/me"];
  138. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  139. NSLog(@"444 :第一次加载:%@",url);
  140. kMainQueue(^{
  141. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  142. })
  143. }
  144. #pragma mark - event response
  145. // 计算wkWebView进度条
  146. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
  147. if (object == self.webView && [keyPath isEqualToString:@"estimatedProgress"]) {
  148. CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
  149. self.progressView.alpha = 1.0f;
  150. [self.progressView setProgress:newprogress animated:YES];
  151. if (newprogress >= 1.0f) {
  152. self.recognizer.enabled = YES;
  153. [UIView animateWithDuration:0.3f
  154. delay:0.3f
  155. options:UIViewAnimationOptionCurveEaseOut
  156. animations:^{
  157. self.progressView.alpha = 0.0f;
  158. }
  159. completion:^(BOOL finished) {
  160. [self.progressView setProgress:0 animated:NO];
  161. }];
  162. }
  163. } else {
  164. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  165. }
  166. }
  167. -(void)initNotification {
  168. //加载通知
  169. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestWebView:) name:kRequestWebViewWithUrl object:nil];
  170. //点击订阅通知
  171. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickSubNotiMethods:) name:ClickSubNotiMethods object:nil];
  172. //点击支付通知
  173. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickPayMethods:) name:ClickPayMethods object:nil];
  174. //支付状态通知
  175. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayWXpayStatus:) name:AlipayWXpayStatus object:nil];
  176. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNotifyState) name:kUpdateNotifyState object:nil];
  177. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(afterReceiveNewMsg) name:kAfterReceiveNewMsg object:nil];
  178. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadWebView) name:kReloadWebVIew object:nil];
  179. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popWebView) name:PopWebView object:nil];
  180. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut:) name:kLoginOut object:nil];
  181. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
  182. //展示底部红的通知
  183. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newsRedPoint:) name:JYNewsRedPoint object:nil];
  184. //接收全新通知
  185. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNonCurVC:) name:RefreshNonCurVC object:nil];
  186. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAllVC:) name:RefreshAllVC object:nil];
  187. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshExpAndMine:) name:RefreshExpAndMine object:nil];
  188. //监听购买结果
  189. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiptData:) name:@"receiptData" object:nil];
  190. //粘贴板-
  191. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateClipboard:) name:UpdateClipboard object:nil];
  192. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openTheClipboard:) name:OpenTheClipboard object:nil];
  193. }
  194. #pragma mark – Gesture Recognizer –
  195. -(void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer
  196. {
  197. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  198. CGRect rect = self.view.bounds;
  199. CGFloat width = CGRectGetWidth(rect);
  200. if (![self.webView canGoBack]||[current_url containsString:@"jyapp/free/login"]) {
  201. NSLog(@"不可返回");
  202. return;
  203. }
  204. if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/me",kHost]]||[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/index",kHost]]||[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/swordfish/historypush",kHost]]||[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/mainSearch",kHost]]){
  205. return;
  206. }
  207. CGPoint touchPoint = [recoginzer locationInView:[UIApplication sharedApplication].keyWindow];
  208. if (recoginzer.state==UIGestureRecognizerStateBegan) {
  209. _isMoving = YES;
  210. startTouch = touchPoint;
  211. } else if (recoginzer.state==UIGestureRecognizerStateEnded||(recoginzer.state==UIGestureRecognizerStatePossible)){
  212. if (touchPoint.x - startTouch.x > width*0.125) {
  213. [UIView animateWithDuration:0.3 animations:^{
  214. if (recoginzer.state==UIGestureRecognizerStateEnded) {
  215. [self moveViewWithX:width];
  216. [self.webView goBack];
  217. }
  218. } completion:^(BOOL finished) {
  219. _isMoving = NO;
  220. [self moveViewWithX:0];
  221. }];
  222. } else {
  223. [UIView animateWithDuration:0.3 animations:^{
  224. [self moveViewWithX:0];
  225. } completion:^(BOOL finished) {
  226. _isMoving = NO;
  227. }];
  228. }
  229. return;
  230. } else if (recoginzer.state==UIGestureRecognizerStateCancelled){
  231. [UIView animateWithDuration:0.3 animations:^{
  232. [self moveViewWithX:0];
  233. } completion:^(BOOL finished) {
  234. _isMoving = NO;
  235. }];
  236. return;
  237. }else {
  238. }
  239. if (_isMoving) {
  240. [self moveViewWithX:touchPoint.x - startTouch.x];
  241. }
  242. }
  243. -(void)moveViewWithX:(float)x
  244. {
  245. CGRect rect = self.view.bounds;
  246. CGFloat width = CGRectGetWidth(rect);
  247. x = x>width?width:x;
  248. x = x<0?0:x;
  249. CGRect frame = self.webView.frame;
  250. frame.origin.x = x;
  251. self.webView.frame = frame;
  252. }
  253. - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
  254. // message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
  255. // NSLog(@"原生收到了js发送过来的消息message.name = %@ message.body = %@",message.name,message.body);
  256. if ([message.name isEqualToString:@"loginByWeixin"]) {
  257. [self jsLoginByWeixin:message.body];
  258. }else if ([message.name isEqualToString:@"share"]) {
  259. [self jsShare:message.body];
  260. }else if ([message.name isEqualToString:@"saveUserToken"]) {
  261. [self jsSaveUserToken:message.body];
  262. }else if ([message.name isEqualToString:@"removeUserToken"]) {
  263. [self jsRemoveUserToken:message.body];
  264. }else if ([message.name isEqualToString:@"openSystemNotification"]) {
  265. [self jsOpenSystemNotification:message.body];
  266. }else if ([message.name isEqualToString:@"openExternalLink"]) {
  267. [self JsOpenExternalLink:message.body];
  268. }else if ([message.name isEqualToString:@"alert"]) {
  269. [self jsAlert:message.body];
  270. }else if ([message.name isEqualToString:@"hiddenBottom"]) {
  271. [self jsHiddenBottom:message.body];
  272. }else if ([message.name isEqualToString:@"checkLab"]) {
  273. [self jsCheckLab:message.body];
  274. }else if ([message.name isEqualToString:@"loginSuccess"]) {
  275. [self jsLoginSuccess:message.body];
  276. }else if ([message.name isEqualToString:@"backUrl"]) {
  277. [self jsBackUrl:message.body];
  278. }else if ([message.name isEqualToString:@"clearPushMessage"]) {
  279. [self jsClearPushMessage:message.body];
  280. }else if ([message.name isEqualToString:@"hideRedSpotOnMenu"]) {
  281. [self jsHideRedSpotOnMenu:message.body];
  282. }else if ([message.name isEqualToString:@"showRedSpotOnMenu"]) {
  283. [self jsShowRedSpotOnMenu:message.body];
  284. }else if ([message.name isEqualToString:@"wxPay"]) {
  285. [self jsWxPay:message.body];
  286. }else if ([message.name isEqualToString:@"aliPay"]) {
  287. [self jsAliPay:message.body];
  288. }else if ([message.name isEqualToString:@"skipCameraWithParam"]) {
  289. [self jsSkipCameraWithParam:message.body];
  290. }else if ([message.name isEqualToString:@"skipAlbumWithParam"]) {
  291. [self jsSkipAlbumWithParam:message.body];
  292. }else if ([message.name isEqualToString:@"openActivityPage"]) {
  293. [self jsOpenActivityPage:message.body];
  294. }else if ([message.name isEqualToString:@"callPhone"]) {
  295. [self jsCallPhone:message.body];
  296. }else if ([message.name isEqualToString:@"openOtherAppLinks"]) {
  297. [self jsOpenOtherAppLinks:message.body];
  298. }else if ([message.name isEqualToString:@"inPurchasingVip"]) {
  299. [self jsInPurchasingVip:message.body];
  300. }else if ([message.name isEqualToString:@"wirteRight"]) {
  301. [self jsWirteRight:message.body];
  302. }else if ([message.name isEqualToString:@"clearRight"]) {
  303. [self jsClearRight:message.body];
  304. }else if ([message.name isEqualToString:@"savePic"]) {
  305. [self jsSavePic:message.body];
  306. }else if ([message.name isEqualToString:@"ocrVerifyService"]) {
  307. [self jsOcrVerifyService:message.body];
  308. }else if ([message.name isEqualToString:@"faceVerifyService"]) {
  309. [self jsFaceVerifyService:message.body];
  310. }else {
  311. }
  312. }
  313. #pragma mark - WKUIDelegate
  314. - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler
  315. {
  316. NSError *err = nil;
  317. NSData *dataFromString = [prompt dataUsingEncoding:NSUTF8StringEncoding];
  318. NSDictionary *paramdict = [NSJSONSerialization JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:&err];
  319. // NSLog(@"拦截%@",paramdict);
  320. if (!err){
  321. NSString *type = [paramdict objectForKey:@"jsName"];
  322. if (type && [type isEqualToString:@"getUserToken"]) {
  323. NSDictionary *dict = @{@"type":@"string",
  324. @"value":[self jsGetUserToken:paramdict]};
  325. completionHandler([self convertToJsonData:dict]);
  326. }else if (type && [type isEqualToString:@"getVersion"]) {
  327. NSDictionary *dict = @{@"type":@"string",
  328. @"value":[self jsGetVersion:paramdict]};
  329. completionHandler([self convertToJsonData:dict]);
  330. }else if (type && [type isEqualToString:@"checkNoticePermission"]) {
  331. NSDictionary *dict = @{@"type":@"int",
  332. @"value":[NSString stringWithFormat:@"%d",[self jsCheckNoticePermission:paramdict]]};
  333. completionHandler([self convertToJsonData:dict]);
  334. }else if (type && [type isEqualToString:@"getPushRid"]) {
  335. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetPushRid:paramdict]};
  336. completionHandler([self convertToJsonData:dict]);
  337. }else if (type && [type isEqualToString:@"isInstallWeixin"]) {
  338. NSDictionary *dict = @{@"type":@"int",
  339. @"value":[NSString stringWithFormat:@"%d",[self jsIsInstallWeixin:paramdict]]};
  340. completionHandler([self convertToJsonData:dict]);
  341. }else if (type && [type isEqualToString:@"getCipherText"]) {
  342. NSDictionary *dict = @{@"type":@"string",
  343. @"value":[self jsGetCipherText:paramdict]};
  344. completionHandler([self convertToJsonData:dict]);
  345. }
  346. else if (type && [type isEqualToString:@"getOtherPushRid"]) {
  347. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetOtherPushRid:paramdict]};
  348. completionHandler([self convertToJsonData:dict]);
  349. }else if (type && [type isEqualToString:@"getPhoneBrand"]) {
  350. NSDictionary *dict = @{@"type":@"string",
  351. @"value":[self jsGetPhoneBrand:paramdict]};
  352. completionHandler([self convertToJsonData:dict]);
  353. }else if (type && [type isEqualToString:@"readRight"]) {
  354. NSDictionary *dict = @{@"type":@"string",
  355. @"value":[self jsReadRight:paramdict]};
  356. completionHandler([self convertToJsonData:dict]);
  357. }else {
  358. completionHandler(@"");
  359. }
  360. }
  361. }
  362. //通过js alert 显示一个警告面板,调用原生会走此方法。
  363. - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
  364. {
  365. NSLog(@"显示一个JavaScript警告面板, message = %@",message);
  366. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  367. [alertController addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  368. completionHandler();
  369. }]];
  370. [self presentViewController:alertController animated:YES completion:nil];
  371. }
  372. //通过 js confirm 显示一个确认面板,调用原生会走此方法。
  373. - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler
  374. {
  375. NSLog(@"运行JavaScript确认面板, message = %@", message);
  376. UIAlertController *action = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  377. [action addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  378. completionHandler(NO);
  379. }] ];
  380. [action addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  381. completionHandler(YES);
  382. }]];
  383. [self presentViewController:action animated:YES completion:nil];
  384. }
  385. #pragma mark - OC调JS交互
  386. -(void)isExitCallToJS:(NSString *)jsStr withMethodName:(NSString *)name{
  387. NSString *jsName = [NSString stringWithFormat:@"function exist(){return !window['%@']};exist()",name];
  388. [_webView evaluateJavaScript:jsName completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  389. // NSLog(@"是否存在 result:%@,error:%@",result,error);
  390. if ([result intValue]==0) {
  391. [self executeCallJS:jsStr];
  392. }else {
  393. NSLog(@"不存在-不存在-不存在-%@",jsStr);
  394. }
  395. }];
  396. }
  397. -(void)executeCallJS:(NSString *)jsStr {
  398. // NSLog(@"OC调JS交互%@:",jsStr);
  399. [_webView evaluateJavaScript:jsStr completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  400. if (error!=nil) {
  401. NSLog(@"result:%@,error:%@",result,error);
  402. // [[LXViewControllerManager shareViewControllerManager]showAlertViewWithMessage: jsStr];
  403. [[GlobalData shareInstance] addOnePlistData:@{
  404. @"detail":[[self stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\nJS异常方法:%@\n%@",jsStr,[error description]]],
  405. @"reqTime":[NSNumber numberWithInt:0],
  406. }];
  407. }
  408. }];
  409. }
  410. - (void)viewDidLoad {
  411. [super viewDidLoad];
  412. // Do any additional setup after loading the view.
  413. NSLog(@"我的初始化");
  414. self.view.backgroundColor = [UIColor whiteColor];
  415. [self.view addSubview:self.webView];
  416. [self.view addSubview:self.progressView];
  417. [self webViewFirstRequest];
  418. [[AFNetworkReachabilityManager sharedManager] startMonitoring];
  419. [self initNotification];
  420. self.recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)];
  421. [self.recognizer delaysTouchesBegan];
  422. [self.view addGestureRecognizer:self.recognizer];
  423. //监听底部栏
  424. [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(bottomFourListening) userInfo:nil repeats:YES];
  425. }
  426. -(void)bottomFourListening {
  427. if(self.tabBarController.selectedIndex == 3) {
  428. [self judgeIsHiddenBottom];
  429. }
  430. }
  431. #pragma mark - WKNavigationDelegate
  432. /* 页面加载完成 */
  433. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
  434. NSLog(@"-----页面加载完成%@",webView.URL.absoluteString);
  435. [self judgeIsHiddenBottom];
  436. [self removeNoNetViews];
  437. [self removeFailNetViews];
  438. [[LXViewControllerManager shareViewControllerManager] hideHud];
  439. [self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
  440. // [self.webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';"completionHandler:nil];
  441. //写数据
  442. // [self writeWKWebData:webView.URL];
  443. }
  444. -(void)writeWKWebData:(NSURL *)url {
  445. //得到NSData 数据
  446. NSData *dataContent = [NSData dataWithContentsOfURL:url];
  447. //NSURLCache 实例化
  448. NSURLCache *cache = [NSURLCache sharedURLCache];
  449. //得到相应
  450. NSURLResponse *response = [[NSURLResponse alloc]initWithURL:url MIMEType:@"text/html" expectedContentLength:0 textEncodingName:@"UTF-8"];
  451. //得到CacheURLResponse
  452. NSCachedURLResponse *cacheResponse = [[NSCachedURLResponse alloc]initWithResponse:response data:dataContent];
  453. //进行存储
  454. [cache storeCachedResponse:cacheResponse forRequest:[NSURLRequest requestWithURL:url]];
  455. }
  456. // 页面开始加载时调用
  457. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
  458. self.recognizer.enabled = NO;
  459. }
  460. // 当内容开始返回时调用
  461. - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
  462. }
  463. // 页面加载失败时调用
  464. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(nonnull NSError *)error{
  465. //加载失败 有网络-弹出页面 , 无网络-记录标记
  466. if ([ZKMethod judegeNetworkIsAvailable]) {
  467. //弹出页面
  468. NSLog(@"页面加载失败-有网络");
  469. [self addFailNetViews];
  470. }else {
  471. //记录标记
  472. NSLog(@"页面加载失败-无网络");
  473. isExistNoNewWork = YES;
  474. }
  475. self.recognizer.enabled = YES;
  476. [[GlobalData shareInstance] addOnePlistData:@{
  477. @"detail":[[self stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\n%@",[error description]]],
  478. @"reqTime":[NSNumber numberWithInt:0],
  479. }];
  480. }
  481. #pragma mark *****JS与OC交互
  482. #pragma mark - WKScriptMessageHandler JS调OC交互
  483. -(void)jsLoginByWeixin:(NSDictionary *)dict {
  484. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装微信 不走友盟
  485. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"微信登录失败,没有安装微信" delay:1.5];
  486. return;
  487. }
  488. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
  489. UMSocialUserInfoResponse *resp = result;
  490. [self dealWXDic:(NSDictionary *)resp.originalResponse];
  491. [[LXViewControllerManager shareViewControllerManager] hideHud];
  492. }];
  493. }
  494. // 处理微信登录获取到的数据
  495. -(void)dealWXDic:(NSDictionary *)dictionary{
  496. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  497. //如果获取到用户信息,即用户点击了“登录”,则进行用户信息获取
  498. if (dictionary.count > 0) {
  499. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dictionary];
  500. if (dic) {
  501. [dic removeObjectForKey:@"privilege"];
  502. [dic removeObjectForKey:@"language"];
  503. double currDouble = [[NSDate date] timeIntervalSince1970];
  504. [dic setObject:[NSNumber numberWithLong:(long)currDouble] forKey:@"createtime"];
  505. // 拼接标志位
  506. NSString *sign = [NSString stringWithFormat:@"city=%@&country=%@&createtime=%@&headimgurl=%@&nickname=%@&openid=%@&province=%@&sex=%@&unionid=%@", dic[@"city"], dic[@"country"], dic[@"createtime"], dic[@"headimgurl"], dic[@"nickname"], dic[@"openid"], dic[@"province"],dic[@"sex"],dic[@"unionid"]];
  507. sign = [LXMD5 md532BitLower:sign];
  508. [dic setObject:sign forKey:@"sign"];
  509. NSString *endStr = [[LXViewControllerManager shareViewControllerManager] getJsonStr:dic];
  510. NSData *data = [endStr dataUsingEncoding:NSUTF8StringEncoding];
  511. endStr = [data base64EncodedStringWithOptions:0];
  512. [self isExitCallToJS:[NSString stringWithFormat:@"loginByWeixinCallBack('%@')", endStr] withMethodName:@"loginByWeixinCallBack"];
  513. }
  514. }
  515. }
  516. -(void)jsShare:(NSDictionary *)dict {
  517. NSString *type = [NSString stringWithFormat:@"%@",dict[@"type"]];
  518. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  519. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  520. NSString *link = [NSString stringWithFormat:@"%@",dict[@"link"]];
  521. UMSocialPlatformType shareType;
  522. if ([type intValue] == 1) { // 微信好友
  523. shareType = UMSocialPlatformType_WechatSession;
  524. }else if ([type intValue] == 2){ /// qq好友
  525. shareType = UMSocialPlatformType_QQ;
  526. }else if ([type intValue] == 3){ // 朋友圈
  527. shareType = UMSocialPlatformType_WechatTimeLine;
  528. }else{
  529. shareType = UMSocialPlatformType_WechatSession;
  530. }
  531. if ([type intValue] == 1 || [type intValue] == 3) {
  532. if ([LXUserDefaults isInstallWeiXin] != 1) {
  533. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装微信" delay:1.5];
  534. return;
  535. }
  536. }
  537. if ([type intValue] == 2) {
  538. if (![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ]) {
  539. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装QQ" delay:1.5];
  540. return;
  541. }
  542. }
  543. //创建分享消息对象
  544. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  545. //创建网页内容对象
  546. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:content thumImage:[UIImage imageNamed:@"logo"]];
  547. //设置网页地址
  548. shareObject.webpageUrl = link;
  549. messageObject.shareObject = shareObject;
  550. //调用分享接口
  551. [[UMSocialManager defaultManager] shareToPlatform:shareType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  552. NSLog(@"%@",error);
  553. if (error) {
  554. if (error.userInfo[@"message"] && [error.userInfo[@"message"] containsString:@"Operation is cancel"]) {
  555. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"取消分享" delay:1];
  556. }else{
  557. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:error.userInfo[@"message"] delay:1];
  558. }
  559. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"0"] withMethodName:@"shareCallBack"];
  560. }else{
  561. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  562. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"1"] withMethodName:@"shareCallBack"];
  563. }else{
  564. UMSocialLogInfo(@"response data is %@",data);
  565. }
  566. }
  567. }];
  568. }
  569. -(void)jsSaveUserToken:(NSDictionary *)dict{
  570. [[LXViewControllerManager shareViewControllerManager] hideHud];
  571. [LXUserDefaults saveToken:[NSString stringWithFormat:@"%@",dict[@"token"]]];
  572. }
  573. -(NSString *)jsGetUserToken:(NSDictionary *)dict{
  574. return [LXUserDefaults token];
  575. }
  576. -(void)jsRemoveUserToken:(NSDictionary *)dict{
  577. [LXUserDefaults clearAll];
  578. }
  579. -(int)jsCheckNoticePermission:(NSDictionary *)dict{
  580. return [LXUserDefaults notifyState];
  581. }
  582. // 跳转到系统设置
  583. -(void)jsOpenSystemNotification:(NSDictionary *)dict{
  584. self.updateNotify = YES;
  585. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  586. }
  587. // 获取推送id
  588. -(NSString *)jsGetPushRid:(NSDictionary *)dict{
  589. return [LXUserDefaults registrationID];
  590. }
  591. // 打开新页面 加载新web
  592. -(void)JsOpenExternalLink:(NSDictionary *)dict{
  593. NSString *url = [NSString stringWithFormat:@"%@",dict[@"url"]];
  594. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  595. if (url) {
  596. if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable || [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown) {
  597. }
  598. JYWKNewWebController *ctr = [[JYWKNewWebController alloc] init];
  599. ctr.url = url;
  600. if (!title || [title isEqualToString:@""]||[title isEqualToString:@"undefined"]) {
  601. ctr.titleShow = nil;
  602. }else{
  603. ctr.titleShow = title;
  604. }
  605. kMainQueue(^{
  606. [self presentViewController:ctr animated:NO completion:nil];
  607. });
  608. }
  609. }
  610. // 获取当前版本号
  611. -(NSString *)jsGetVersion:(NSDictionary *)dict{
  612. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  613. }
  614. -(void)jsAlert:(NSDictionary *)dict{
  615. [[LXViewControllerManager shareViewControllerManager] showAlertViewWithMessage:[NSString stringWithFormat:@"%@",dict[@"content"]]];
  616. }
  617. -(int)jsIsInstallWeixin:(NSDictionary *)dict{
  618. return [LXUserDefaults isInstallWeiXin];
  619. }
  620. -(NSString *)jsGetCipherText:(NSDictionary *)dict{
  621. NSDictionary *objDict = [NSDictionary dictionaryWithDictionary:dict[@"arguments"]];
  622. NSString *phone = [NSString stringWithFormat:@"%@",objDict[@"phone"]];
  623. NSDate *date=[NSDate date];
  624. NSDateFormatter *format1=[[NSDateFormatter alloc] init];
  625. [format1 setDateFormat:@"yyyyMMddhhmmss"];
  626. NSString *dateStr;
  627. dateStr=[format1 stringFromDate:date];
  628. NSString *content = [[NSString stringWithFormat:@"%@_%@",phone,dateStr] stringByAppendingString:[NSString stringWithFormat:@"_%@",[LXMD5 md532BitLower:[NSString stringWithFormat:@"%@&%@",phone,dateStr]]]];
  629. NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
  630. NSUInteger dataLength = contentData.length;
  631. // 为结束符'\\0' +1
  632. char keyPtr[new_kKeySize_4 + 1];
  633. memset(keyPtr, 0, sizeof(keyPtr));
  634. [new_AesKey_4 getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
  635. // 密文长度 <= 明文长度 + BlockSize
  636. size_t encryptSize = dataLength + kCCBlockSizeAES128;
  637. void *encryptedBytes = malloc(encryptSize);
  638. size_t actualOutSize = 0;
  639. NSData *initVector = [new_kInitVector_4 dataUsingEncoding:NSUTF8StringEncoding];
  640. CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
  641. kCCAlgorithmAES,
  642. kCCOptionPKCS7Padding, // 系统默认使用 CBC,然后指明使用 PKCS7Padding
  643. keyPtr,
  644. new_kKeySize_4,
  645. initVector.bytes,
  646. contentData.bytes,
  647. dataLength,
  648. encryptedBytes,
  649. encryptSize,
  650. &actualOutSize);
  651. if (cryptStatus == kCCSuccess) {
  652. // 对加密后的数据进行 base64 编码
  653. return [[NSData dataWithBytesNoCopy:encryptedBytes length:actualOutSize] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  654. }
  655. free(encryptedBytes);
  656. return nil;
  657. }
  658. -(void)jsHiddenBottom:(NSDictionary *)dict{
  659. if(self.tabBarController.selectedIndex == 3) {
  660. if([[NSString stringWithFormat:@"%@",dict[@"hidden"]] integerValue]==0) {
  661. [self hideTabBar];
  662. [self hiddenMethodTabBar];
  663. }else {
  664. [self showTabBar];
  665. [self showMethodTabBar];
  666. }
  667. }
  668. }
  669. -(void)jsCheckLab:(NSDictionary *)dict {
  670. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshNonCurVC object:nil userInfo:nil];
  671. }
  672. //js方法登录成功
  673. -(void)jsLoginSuccess:(NSDictionary *)dict {
  674. NSLog(@"mine登录成功提示");
  675. NSString *status = [NSString stringWithFormat:@"%@",dict[@"status"]];
  676. [GlobalData shareInstance].isReLogin = YES;
  677. if([status isEqualToString:@"S"]) {
  678. kMainQueue(^{
  679. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshAllVC object:nil userInfo:nil];
  680. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  681. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  682. tab.selectedIndex = 0;
  683. //
  684. });
  685. }else {
  686. }
  687. //弹出页面
  688. if ([GlobalData shareInstance].isPasteLogin) {
  689. [GlobalData shareInstance].isPasteLogin = NO;
  690. NSString *content = [UIPasteboard generalPasteboard].string;
  691. [self popPasteVIew:content];
  692. }
  693. }
  694. -(void)jsBackUrl:(NSDictionary *)dict {
  695. NSString *status = [NSString stringWithFormat:@"%@",dict[@"status"]];
  696. NSLog(@"sub返回");
  697. if([status isEqualToString:@"H"]) {
  698. //测试返回首页
  699. kMainQueue(^{
  700. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshAllVC object:nil userInfo:nil];
  701. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  702. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  703. tab.selectedIndex = 0;
  704. });
  705. }
  706. }
  707. -(void)jsClearPushMessage:(NSDictionary *)dict {
  708. kMainQueue(^{
  709. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
  710. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  711. });
  712. }
  713. -(void)jsHideRedSpotOnMenu:(NSDictionary *)dict {
  714. NSString *menu = [NSString stringWithFormat:@"%@",dict[@"menu"]];
  715. if([menu isEqualToString:@"subscribe"]) {
  716. kMainQueue(^{
  717. [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
  718. });
  719. }
  720. if([menu isEqualToString:@"my"]) {
  721. kMainQueue(^{
  722. [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  723. });
  724. }
  725. }
  726. -(void)jsShowRedSpotOnMenu:(NSDictionary *)dict {
  727. NSString *menu = [NSString stringWithFormat:@"%@",dict[@"menu"]];
  728. if([menu isEqualToString:@"subscribe"]) {
  729. kMainQueue(^{
  730. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  731. });
  732. }
  733. if([menu isEqualToString:@"my"]) {
  734. kMainQueue(^{
  735. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  736. });
  737. }
  738. }
  739. -(void)jsWxPay:(NSDictionary *)dict {
  740. NSString *jsonString = [NSString stringWithFormat:@"%@",dict[@"order"]];
  741. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装wx
  742. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先安装微信再进行支付!" delay:1.5];
  743. return;
  744. }
  745. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  746. NSError *err;
  747. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
  748. if(err) {
  749. NSLog(@"json解析失败:%@",err);
  750. return;
  751. }
  752. //吊起微信
  753. PayReq *request = [[PayReq alloc] init] ;
  754. request.openID = dic[@"Appid"];
  755. request.partnerId = dic[@"Partnerid"];
  756. request.prepayId= dic[@"Prepayid"];
  757. request.package = @"Sign=WXPay";
  758. request.nonceStr= dic[@"Noncestr"];
  759. request.timeStamp= [dic[@"Timestamp"] intValue];
  760. request.sign= dic[@"Sign"];
  761. kMainQueue(^{
  762. [WXApi sendReq:request];
  763. });
  764. }
  765. -(void)jsAliPay:(NSDictionary *)dict {
  766. NSString *order = [NSString stringWithFormat:@"%@",dict[@"order"]];
  767. kMainQueue(^{
  768. [[AlipaySDK defaultService] payOrder:order fromScheme:@"jianyuiosapp" callback:nil];
  769. });
  770. }
  771. -(NSString *)jsGetOtherPushRid:(NSDictionary *)dict {
  772. return [LXUserDefaults deviceToken];
  773. }
  774. -(NSString *)jsGetPhoneBrand:(NSDictionary *)dict {
  775. UIDevice *device = [UIDevice currentDevice];
  776. return device.platformString;
  777. }
  778. //拍照上传图片
  779. -(void)jsSkipCameraWithParam:(NSDictionary *)dict {
  780. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  781. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  782. picker.delegate = self;
  783. picker.allowsEditing = YES;
  784. picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  785. dispatch_async(dispatch_get_main_queue(), ^{
  786. [self presentViewController:picker animated:YES completion:nil];
  787. });
  788. }
  789. //相册选择照片
  790. -(void)jsSkipAlbumWithParam:(NSDictionary *)dict {
  791. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  792. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  793. picker.delegate = self;
  794. picker.allowsEditing = YES;
  795. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  796. dispatch_async(dispatch_get_main_queue(), ^{
  797. [self presentViewController:picker animated:YES completion:nil];
  798. });
  799. }
  800. -(void)jsOpenActivityPage:(NSDictionary *)dict {
  801. NSDictionary * infoDic = @{@"url":[NSString stringWithFormat:@"%@",dict[@"url"]],
  802. @"rectype":[NSString stringWithFormat:@"%@",dict[@"rectype"]],
  803. @"openid":[NSString stringWithFormat:@"%@",dict[@"openid"]],
  804. };
  805. //post请求
  806. NSLog(@"%@",[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost]);
  807. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost] parameters:infoDic progress:^(NSProgress *progress) {
  808. NSLog(@"成功:%@",progress);
  809. } success:^(id responseObject) {
  810. NSLog(@"responseObject=%@",responseObject);
  811. } failure:^(NSError *error) {
  812. NSLog(@"error=%@",error);
  813. [[GlobalData shareInstance] addOnePlistData:@{
  814. @"detail":[NSString stringWithFormat:@"message/receive接口:%@",[error description]],
  815. @"reqTime":[NSNumber numberWithInt:0],
  816. }];
  817. }];
  818. }
  819. //拨打电话
  820. -(void)jsCallPhone:(NSDictionary *)dict {
  821. NSString *phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
  822. NSMutableString *tel = [[NSMutableString alloc]initWithFormat:@"telprompt://%@",phone];
  823. if (@available(iOS 10.0, *)) {
  824. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel] options:@{} completionHandler:^(BOOL success) {
  825. }];
  826. } else {
  827. // Fallback on earlier versions
  828. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
  829. }
  830. }
  831. //打开其他app 抖音+快手
  832. -(void)jsOpenOtherAppLinks:(NSDictionary *)dict {
  833. //测试跳转抖音--快手 @"gifshow://" @"snssdk1128://"
  834. NSString *appLink = [NSString stringWithFormat:@"%@",dict[@"appLink"]];
  835. NSString *appName = [NSString stringWithFormat:@"%@",dict[@"appName"]];
  836. NSLog(@"appName:%@",appName);
  837. NSURL *url = [NSURL URLWithString:appLink];
  838. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  839. if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
  840. //iOS 10.0+
  841. NSLog(@"iOS 10+");
  842. if (@available(iOS 10.0, *)) {
  843. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  844. if (!success) {
  845. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  846. }
  847. }];
  848. } else {
  849. // Fallback on earlier versions
  850. [[UIApplication sharedApplication] openURL:url];
  851. }
  852. }else{
  853. NSLog(@"iOS 2~10");
  854. //iOS 2~10
  855. [[UIApplication sharedApplication] openURL:url];
  856. }
  857. }else{
  858. //一般是没有安装
  859. NSLog(@"跳转下载app链接");
  860. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  861. }
  862. }
  863. #pragma mark *****人脸核身
  864. //ocr验证
  865. -(void)jsOcrVerifyService:(NSDictionary *)dict{
  866. NSLog(@"ocr:%@",dict);
  867. NSString *orderNo = [NSString stringWithFormat:@"%@",dict[@"orderNo"]];
  868. NSString *nonce = [NSString stringWithFormat:@"%@",dict[@"nonce"]];
  869. NSString *userId = [NSString stringWithFormat:@"%@",dict[@"userId"]];
  870. NSString *sign = [NSString stringWithFormat:@"%@",dict[@"sign"]];
  871. kMainQueue((^{
  872. WBOCRConfig *config = [WBOCRConfig sharedConfig];
  873. config.needRecordVideo = NO;
  874. config.SDKType = WBOCRSDKTypeIDCardNormal; // 身份证两面识别
  875. [[WBOCRService sharedService] startOCRServiceWithConfig:config version:@"1.0.0" appId:OCRAPPID nonce:nonce userId:userId sign:sign orderNo:orderNo startSucceed:^{
  876. /** SDK服务拉起成功回调 */
  877. NSLog(@"启动SDK成功!!!");
  878. } recognizeSucceed:^(id _Nonnull resultModel, id _Nullable extension) {
  879. /** SDK本次识别成功回调 */
  880. NSLog(@"SDK识别成功!!!");
  881. //调用js - 告知成功
  882. NSString *textJS = [NSString stringWithFormat:@"ocrVerifyResult('%@')",orderNo];
  883. [self isExitCallToJS:textJS withMethodName:@"ocrVerifyResult"];
  884. } failed:^(NSError * _Nonnull error, id _Nullable extension) {
  885. /** SDK异常回调 */
  886. NSLog(@"识别出错!!!"); //200101 用户取消操作
  887. //弹出页面
  888. if (error.code == 200101) {
  889. self.verifyMsgView.descTitle = @"您取消了身份验证";
  890. }else {
  891. self.verifyMsgView.descTitle = @"身份验证失败";
  892. }
  893. [self.verifyMsgView show];
  894. NSString *textJS = [NSString stringWithFormat:@"ocrVerifyResult('%@')",@""];
  895. [self isExitCallToJS:textJS withMethodName:@"ocrVerifyResult"];
  896. }];
  897. }));
  898. }
  899. //人脸核身
  900. -(void)jsFaceVerifyService:(NSDictionary *)dict {
  901. NSLog(@"face:%@",dict);
  902. NSString *orderNo = [NSString stringWithFormat:@"%@",dict[@"orderNo"]];
  903. NSString *nonce = [NSString stringWithFormat:@"%@",dict[@"nonce"]];
  904. NSString *userId = [NSString stringWithFormat:@"%@",dict[@"userId"]];
  905. NSString *sign = [NSString stringWithFormat:@"%@",dict[@"sign"]];
  906. NSString *faceId = [NSString stringWithFormat:@"%@",dict[@"faceId"]];
  907. kMainQueue((^{
  908. [WBFaceVerifyCustomerService sharedInstance].delegate = self;
  909. WBFaceVerifySDKConfig *config = [WBFaceVerifySDKConfig sdkConfig];
  910. config.recordVideo = NO;
  911. config.theme = WBFaceVerifyThemeDarkness;
  912. [[WBFaceVerifyCustomerService sharedInstance] loginInLiveCheckAndCompareWithSourceImageService:userId nonce:nonce sign:sign appid:OCRAPPID orderNo:orderNo apiVersion:@"1.0.0" licence:LICENCE faceType:WBFaceVerifyLivingType_Action faceId:faceId sdkConfig:config success:^{
  913. } failure:^(WBFaceError * _Nonnull error) {
  914. }];
  915. }));
  916. }
  917. #pragma mark - WBFaceVerifyCustomerServiceDelegate
  918. -(void)wbfaceVerifyCustomerServiceDidFinishedWithFaceVerifyResult:(WBFaceVerifyResult *)faceVerifyResult{
  919. if (faceVerifyResult.isSuccess) {
  920. NSLog(@"活体检测成功:%@",faceVerifyResult.orderNo);
  921. NSString *textJS = [NSString stringWithFormat:@"faceVerifyResult('%@')",faceVerifyResult.orderNo];
  922. [self isExitCallToJS:textJS withMethodName:@"faceVerifyResult"];
  923. self.verifyMsgView.descTitle = @"活体检测成功";
  924. [self.verifyMsgView show];
  925. }else {
  926. NSLog(@"活体检测失败");
  927. self.verifyMsgView.descTitle = @"活体检测失败";
  928. [self.verifyMsgView show];
  929. NSString *textJS = [NSString stringWithFormat:@"faceVerifyResult('%@')",@""];
  930. [self isExitCallToJS:textJS withMethodName:@"faceVerifyResult"];
  931. }
  932. }
  933. //保存图片到相册
  934. #pragma mark 保存图片
  935. -(void)jsSavePic:(NSDictionary *)dict {
  936. NSString *base64ImgData = [NSString stringWithFormat:@"%@",dict[@"imgbase64"]];
  937. NSData *data = [[NSData alloc]initWithBase64EncodedString:base64ImgData options:NSDataBase64DecodingIgnoreUnknownCharacters];
  938. UIImage *saveImg = [UIImage imageWithData:data];
  939. UIImageWriteToSavedPhotosAlbum(saveImg, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
  940. }
  941. #pragma mark 系统的完成保存图片的方法
  942. - (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
  943. {
  944. NSString *msg = nil ;
  945. if (error != NULL) {
  946. msg = @"保存图片失败" ;
  947. } else {
  948. msg = @"保存图片成功" ;
  949. }
  950. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:msg delay:1];
  951. }
  952. #pragma mark 粘贴板
  953. -(void)jsWirteRight:(NSDictionary *)dict {
  954. NSString *txt = [NSString stringWithFormat:@"%@",dict[@"txt"]];
  955. [[UIPasteboard generalPasteboard]setString:txt];
  956. }
  957. -(void)jsClearRight:(NSDictionary *)dict {
  958. //清粘贴板数据
  959. [[UIPasteboard generalPasteboard]setString:@""];
  960. }
  961. -(NSString *)jsReadRight:(NSDictionary *)dict {
  962. NSString *content = [UIPasteboard generalPasteboard].string;
  963. return content;
  964. }
  965. //内购VIP
  966. -(void)jsInPurchasingVip:(NSDictionary *)dict {
  967. NSString *productid = [NSString stringWithFormat:@"%@",dict[@"productid"]];
  968. //产品id
  969. if ([productid isEqualToString:@""]) {
  970. NSLog(@"订单号 有问题");
  971. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"订单号异常,请重试" delay:1];
  972. return;
  973. }
  974. [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果验证中,请稍候"];
  975. if([SKPaymentQueue canMakePayments]){
  976. [self requestProductData:productid];
  977. }else{
  978. [[LXViewControllerManager shareViewControllerManager] hideHud];
  979. }
  980. }
  981. //去苹果服务器请求商品
  982. - (void)requestProductData:(NSString *)type {
  983. NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
  984. NSSet *nsset = [NSSet setWithArray:product];
  985. SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
  986. request.delegate = self;
  987. [request start];
  988. }
  989. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
  990. NSArray *myProduct = response.products;
  991. if (myProduct.count == 0) {
  992. NSLog(@"无法获取产品信息,购买失败。");
  993. [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"暂时未获取到产品信息,请重试" delay:1];
  994. return;
  995. }
  996. SKPayment * payment = [SKPayment paymentWithProduct:myProduct[0]];
  997. [[SKPaymentQueue defaultQueue] addPayment:payment];
  998. }
  999. #pragma mark *****其他方法
  1000. -(void)judgeIsHiddenBottom {
  1001. if(self.tabBarController.selectedIndex == 3) {
  1002. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  1003. if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/me",kHost]]){
  1004. [self showTabBar];
  1005. [self showMethodTabBar];
  1006. }else {
  1007. [self hideTabBar];
  1008. [self hiddenMethodTabBar];
  1009. }
  1010. }
  1011. }
  1012. -(void)pushDY:(NSDictionary *)infoDict
  1013. {
  1014. [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshDY" object:nil userInfo:infoDict];
  1015. }
  1016. -(void)requestWebTime:(NSDictionary *)infoDict
  1017. {
  1018. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
  1019. if ([urlStr containsString:@"https://"]||[urlStr containsString:@"http://"]) {
  1020. }else {
  1021. urlStr = [kHost stringByAppendingString:urlStr];
  1022. }
  1023. if([infoDict[@"type"] isEqualToString:@"message"]) {
  1024. NSArray * array = [urlStr componentsSeparatedByString:@"=="];
  1025. urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1026. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
  1027. }else if ([infoDict[@"type"] isEqualToString:@"titleMessage"]) {
  1028. NSArray * array = [urlStr componentsSeparatedByString:@"=="];
  1029. urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1030. NSString * titleStr = @"消息通知";
  1031. titleStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"title"]];
  1032. if (urlStr&&self.tabBarController.selectedIndex == 3) {
  1033. [self JsOpenExternalLink:@{@"url":urlStr,@"title":titleStr}];
  1034. }
  1035. }else {
  1036. urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1037. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
  1038. }
  1039. }
  1040. - (void)hideTabBar {
  1041. kMainQueue(^{
  1042. if (self.tabBarController.tabBar.hidden == YES) {
  1043. return;
  1044. }
  1045. UIView *contentView;
  1046. if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
  1047. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  1048. else
  1049. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  1050. contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height + self.tabBarController.tabBar.frame.size.height);
  1051. self.tabBarController.tabBar.hidden = YES;
  1052. });
  1053. }
  1054. - (void)showTabBar{
  1055. kMainQueue(^{
  1056. if (self.tabBarController.tabBar.hidden == NO)
  1057. {
  1058. return;
  1059. }
  1060. UIView *contentView;
  1061. if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
  1062. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  1063. else
  1064. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  1065. contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
  1066. self.tabBarController.tabBar.hidden = NO;
  1067. });
  1068. }
  1069. - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
  1070. {
  1071. __block NSString *resultString = nil;
  1072. __block BOOL finished = NO;
  1073. [self.webView evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
  1074. if (error == nil) {
  1075. if (result != nil) {
  1076. resultString = [NSString stringWithFormat:@"%@", result];
  1077. }
  1078. } else {
  1079. NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
  1080. }
  1081. finished = YES;
  1082. }];
  1083. while (!finished) {
  1084. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
  1085. }
  1086. return resultString;
  1087. }
  1088. -(void)hiddenMethodTabBar
  1089. {
  1090. kMainQueue(^{
  1091. if (iPhoneX) {
  1092. if (@available(iOS 11.0, *)) {
  1093. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
  1094. }
  1095. }else {
  1096. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
  1097. }
  1098. });
  1099. }
  1100. -(void)showMethodTabBar
  1101. {
  1102. kMainQueue(^{
  1103. if (iPhoneX) {
  1104. if (@available(iOS 11.0, *)) {
  1105. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT);
  1106. }
  1107. }else {
  1108. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
  1109. }
  1110. });
  1111. }
  1112. //取消获取照片
  1113. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  1114. {
  1115. dispatch_async(dispatch_get_main_queue(), ^{
  1116. [picker dismissViewControllerAnimated:YES completion:^{
  1117. [self uploadUrl:@""];
  1118. }];
  1119. });
  1120. }
  1121. //上传图片
  1122. -(void)uploadPic:(NSData *)data
  1123. {
  1124. NSString *isPath = @"courseFile";
  1125. if (![[GlobalData shareInstance].isSkipPath isEqualToString:@""]) {
  1126. isPath = [GlobalData shareInstance].isSkipPath;
  1127. }
  1128. NSDictionary * body = @{@"type":isPath};
  1129. AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
  1130. //ContentType设置
  1131. manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html",@"image/jpeg",@"image/png",@"application/octet-stream",@"text/json",@"text/plain",nil];
  1132. manager.responseSerializer= [AFHTTPResponseSerializer serializer];
  1133. manager.requestSerializer = [AFHTTPRequestSerializer serializer];
  1134. manager.requestSerializer.timeoutInterval = 15.0f;
  1135. [manager POST:[NSString stringWithFormat:@"%@jyapp/filemanage/upload",kHost] parameters:body constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
  1136. //上传的参数(上传图片,以文件流的格式)
  1137. [formData appendPartWithFileData:data
  1138. name:isPath
  1139. fileName:[isPath stringByAppendingFormat:@".jpeg"]
  1140. mimeType:@"image/jpeg"];
  1141. } progress:^(NSProgress * _Nonnull uploadProgress) {
  1142. CGFloat progress = 100.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount;
  1143. NSLog(@"%.2lf%%", progress);
  1144. } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  1145. //请求成功的block回调
  1146. NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
  1147. NSLog(@"上传成功%@",dic);
  1148. if ([dic[@"msg"] isEqualToString:@"ssss"]) {
  1149. [self uploadUrl:dic[@"url"]];
  1150. }else{
  1151. [self uploadUrl:@""];
  1152. }
  1153. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  1154. NSLog(@"上传失败%@",error);
  1155. [self uploadUrl:@""];
  1156. [[GlobalData shareInstance] addOnePlistData:@{
  1157. @"detail":@"上传图片接口",
  1158. @"reqTime":[NSNumber numberWithInt:0],
  1159. }];
  1160. }];
  1161. }
  1162. -(void)uploadUrl:(NSString *)url {
  1163. NSString *textJS = [NSString new];
  1164. NSString *methodJS = [NSString new];
  1165. if ([url isEqualToString:@""]) {
  1166. textJS = @"hiddenLoading()";
  1167. methodJS =@"hiddenLoading";
  1168. }else{
  1169. textJS = [NSString stringWithFormat:@"uploadImg('%@')",url];
  1170. methodJS = @"uploadImg";
  1171. }
  1172. if ([url isEqualToString:@""]||[textJS isEqualToString:@""]) {
  1173. NSLog(@"空的情况");
  1174. textJS = @"hiddenLoading()";
  1175. methodJS = @"hiddenLoading";
  1176. }
  1177. NSDictionary *dict = @{@"jsStr":textJS,@"name":methodJS};
  1178. [self performSelector:@selector(uploadJS:) withObject:dict afterDelay:1];
  1179. }
  1180. //获取到图片
  1181. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  1182. {
  1183. dispatch_async(dispatch_get_main_queue(), ^{
  1184. [picker dismissViewControllerAnimated:YES completion:^{
  1185. UIImage * img=[info objectForKey:UIImagePickerControllerEditedImage];
  1186. NSData *data = UIImageJPEGRepresentation(img, 0.5);
  1187. if (data!=nil) {
  1188. [self uploadPic:data];
  1189. }else{
  1190. NSLog(@"data == nil");
  1191. [self uploadUrl:@""];
  1192. }
  1193. }];
  1194. });
  1195. }
  1196. -(void)uploadJS:(NSDictionary *)dict {
  1197. [self isExitCallToJS:dict[@"jsStr"] withMethodName:dict[@"name"]];
  1198. }
  1199. - (BOOL)checkLocationServiceIsEnabled{
  1200. // 该方法是类方法,和我们创建的管理器没有关系
  1201. if ([CLLocationManager locationServicesEnabled]) {
  1202. return YES;
  1203. }
  1204. return NO;
  1205. }
  1206. -(NSString *)convertToJsonData:(NSDictionary *)dict {
  1207. NSError *error;
  1208. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
  1209. NSString *jsonString;
  1210. if (!jsonData) {
  1211. NSLog(@"%@",error);
  1212. }else{
  1213. jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  1214. }
  1215. NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
  1216. NSRange range = {0,jsonString.length};
  1217. //去掉字符串中的空格
  1218. [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
  1219. NSRange range2 = {0,mutStr.length};
  1220. //去掉字符串中的换行符
  1221. [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
  1222. return mutStr;
  1223. }
  1224. -(void)addNoNetViews{
  1225. kMainQueue(^{
  1226. [self removeNoNetViews];
  1227. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  1228. NSLog(@"当前页面:%@",current_url);
  1229. self.noNetView = [NoNetView shareView];
  1230. [self.view addSubview:self.noNetView];
  1231. });
  1232. }
  1233. -(void)removeNoNetViews{
  1234. if (self.noNetView ) {
  1235. [self.noNetView removeFromSuperview];
  1236. self.noNetView = nil;
  1237. }
  1238. }
  1239. -(void)addFailNetViews{
  1240. kMainQueue(^{
  1241. [self removeFailNetViews];
  1242. self.failNetView = [NoNetView shareView];
  1243. [self.view addSubview:self.failNetView];
  1244. });
  1245. }
  1246. -(void)removeFailNetViews{
  1247. if (self.failNetView ) {
  1248. [self.failNetView removeFromSuperview];
  1249. self.failNetView = nil;
  1250. }
  1251. }
  1252. #pragma mark **** 通知相关方法
  1253. // 点击通知 跳转到通知内url
  1254. -(void)requestWebView:(NSNotification *)notification{
  1255. NSDictionary * infoDict = [notification object];
  1256. if (!infoDict) {
  1257. return;
  1258. }
  1259. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
  1260. if (urlStr) {
  1261. //当前控制器
  1262. if(self.tabBarController.selectedIndex != 3) {
  1263. return;
  1264. }
  1265. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  1266. [self performSelector:@selector(requestWebTime:) withObject:infoDict afterDelay:1];
  1267. }
  1268. }
  1269. -(void)clickSubNotiMethods:(NSNotification *)notification{
  1270. if(![LXUserDefaults isExistToken]) {
  1271. return;
  1272. }
  1273. NSDictionary * infoDict = [notification object][@"info"];
  1274. if (!infoDict) {
  1275. return;
  1276. }
  1277. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1278. if (urlStr) {
  1279. NSLog(@"有info");
  1280. if(self.tabBarController.selectedIndex == 3) {
  1281. //底部栏置换到订阅
  1282. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1283. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  1284. tab.selectedIndex = 1;
  1285. [self performSelector:@selector(pushDY:) withObject:infoDict afterDelay:1];
  1286. }
  1287. }
  1288. }
  1289. //点击支付通知
  1290. -(void)clickPayMethods:(NSNotification *)notification{
  1291. NSDictionary * infoDict = [notification object][@"info"];
  1292. if (!infoDict) {
  1293. return;
  1294. }
  1295. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1296. if ([urlStr containsString:@"https://"]||[urlStr containsString:@"http://"]) {
  1297. }else {
  1298. urlStr = [kHost stringByAppendingString:urlStr];
  1299. }
  1300. NSArray * array = [urlStr componentsSeparatedByString:@"=="];
  1301. urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1302. NSString * titleStr = @"消息通知";
  1303. titleStr = [NSString stringWithFormat:@"%@",infoDict[@"title"]];
  1304. if (urlStr) {
  1305. if(self.tabBarController.selectedIndex == 3) {
  1306. [self JsOpenExternalLink:@{@"url":urlStr,@"title":titleStr}];
  1307. }
  1308. }
  1309. }
  1310. -(void)alipayWXpayStatus:(NSNotification *)notification{
  1311. if(self.tabBarController.selectedIndex == 3) {
  1312. NSString * status = [notification object];
  1313. [self performSelector:@selector(payStatus:) withObject:status afterDelay:2];
  1314. }
  1315. }
  1316. -(void)payStatus:(NSString *)status
  1317. {
  1318. //目前延时两秒
  1319. NSLog(@"支付状态:%@",status);
  1320. if(self.tabBarController.selectedIndex == 3) {
  1321. [self isExitCallToJS:[NSString stringWithFormat:@"payCallBack('%@')", status] withMethodName:@"payCallBack"];
  1322. }
  1323. }
  1324. // 调用js方法 刷新推送权限状态
  1325. -(void)updateNotifyState{
  1326. if (self.updateNotify) {
  1327. self.updateNotify = NO;
  1328. [self isExitCallToJS:[NSString stringWithFormat:@"updateNoticeSwitch()"] withMethodName:@"updateNoticeSwitch"];
  1329. }
  1330. }
  1331. // 收到通知消息
  1332. -(void)afterReceiveNewMsg{
  1333. if(self.tabBarController.selectedIndex == 3) {
  1334. NSLog(@"afterReceiveNewMsg");
  1335. [self isExitCallToJS:@"afterReceiveNewMsg()" withMethodName:@"afterReceiveNewMsg"];
  1336. }
  1337. }
  1338. // 再次加载页面
  1339. -(void)reloadWebView{
  1340. if(self.tabBarController.selectedIndex == 3) {
  1341. if (![self.webView canGoBack]) {
  1342. [self webViewFirstRequest];
  1343. }else{
  1344. [self.webView reload];
  1345. }
  1346. }
  1347. }
  1348. // 返回上一页面- 防止
  1349. -(void)popWebView{
  1350. if(self.tabBarController.selectedIndex == 3) {
  1351. if ([self.webView canGoBack]) {
  1352. [self.webView goBack];
  1353. }
  1354. [self removeNoNetViews];
  1355. [self removeFailNetViews];
  1356. }
  1357. }
  1358. // 收到退出登录消息
  1359. -(void)loginOut:(NSNotification *)notification{
  1360. if([notification.userInfo[@"item_index"] integerValue]!=3) {
  1361. return;
  1362. }
  1363. [self webViewRequestByMsg];
  1364. }
  1365. //收到消息退出并重新加载web
  1366. -(void)webViewRequestByMsg{
  1367. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login?back=index&isios=t&flag=kicked"];
  1368. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1369. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  1370. }
  1371. // 监控网络状态变化
  1372. -(void)netReachChanged:(NSNotification *)notificaition{
  1373. NSDictionary *userInfo = notificaition.userInfo;
  1374. if ([userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == 0 || [userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == -1) {
  1375. [self addNoNetViews];
  1376. }else{
  1377. [self removeNoNetViews];
  1378. if (isExistNoNewWork) {
  1379. isExistNoNewWork = NO;
  1380. [self reloadWebView];
  1381. }
  1382. }
  1383. }
  1384. -(void)newsRedPoint:(NSNotification *)notificaition
  1385. {
  1386. NSDictionary *dict = notificaition.userInfo;
  1387. if(self.tabBarController.selectedIndex == 3) {
  1388. NSString *textJS = [NSString stringWithFormat:@"afterReceivePushMessage('%@','%@')",dict[@"typeMsg"],dict[@"url"]];
  1389. [self isExitCallToJS:textJS withMethodName:@"afterReceivePushMessage"];
  1390. }
  1391. }
  1392. //刷新页面相关
  1393. -(void)refreshNonCurVC:(NSNotification *)notificaition{
  1394. if(self.tabBarController.selectedIndex != 3) {
  1395. [self webViewFirstRequest];
  1396. }
  1397. }
  1398. -(void)refreshAllVC:(NSNotification *)notificaition{
  1399. [self webViewFirstRequest];
  1400. }
  1401. -(void)refreshExpAndMine:(NSNotification *)notificaition{
  1402. [self webViewFirstRequest];
  1403. }
  1404. //内购相关
  1405. -(void)receiptData:(NSNotification *)notificaition{
  1406. if(self.tabBarController.selectedIndex == 3) {
  1407. NSDictionary *infoDict = notificaition.userInfo;
  1408. if (infoDict) {
  1409. NSString *receipt = [NSString stringWithFormat:@"%@", infoDict[@"receipt"]];
  1410. [self isExitCallToJS:[NSString stringWithFormat:@"getReceipt('%@')", receipt] withMethodName:@"getReceipt"];
  1411. }
  1412. }
  1413. }
  1414. #pragma mark ****粘贴板相关-梳理
  1415. -(void)updateClipboard:(NSNotification *)notificaition{
  1416. if(self.tabBarController.selectedIndex == 3) {
  1417. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  1418. NSDictionary *dict = notificaition.userInfo;
  1419. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  1420. if ([current_url containsString:@"jyapp/free/login"]) {
  1421. [GlobalData shareInstance].isPasteLogin = YES;
  1422. }else {
  1423. [self popPasteVIew:content];
  1424. }
  1425. }
  1426. }
  1427. -(void)openTheClipboard:(NSNotification *)notificaition{
  1428. if(self.tabBarController.selectedIndex == 3) {
  1429. NSLog(@"菜单四打开指定粘贴板url");
  1430. NSDictionary *dict = notificaition.userInfo;
  1431. NSString *tmpUrl = [NSString stringWithFormat:@"%@%@", kHost, dict[@"url"]];
  1432. tmpUrl = [tmpUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1433. kMainQueue(^{
  1434. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tmpUrl]]];
  1435. })
  1436. }
  1437. }
  1438. //弹出粘贴板框
  1439. -(void)popPasteVIew:(NSString *)content {
  1440. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@distribution/share/getWordInfo",kHost] parameters:@{@"copyTxt":content} progress:^(NSProgress *progress) {
  1441. NSLog(@"%@",progress);
  1442. } success:^(id responseObject) {
  1443. NSLog(@"responseObject=%@",responseObject);
  1444. if ([responseObject objectForKey:@"data"]) {
  1445. NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:responseObject[@"data"]];
  1446. if ([dict objectForKey:@"title"]) {
  1447. self.clipboardView.title =dict[@"title"];
  1448. self.clipboardView.subTitle =dict[@"subTitle"];
  1449. self.clipboardView.imgUrl =dict[@"imgUrl"];
  1450. self.clipboardView.appUrl =dict[@"appUrl"];
  1451. self.clipboardView.butTxt =dict[@"butTxt"];
  1452. self.clipboardView.bottomTxt =dict[@"bottomTxt"];
  1453. [self.clipboardView show];
  1454. }
  1455. }
  1456. } failure:^(NSError *error) {
  1457. NSLog(@"error=%@",error);
  1458. }];
  1459. }
  1460. #pragma mark **** 代理方法
  1461. -(void)clipboardClick:(NSString *)url {
  1462. //发送通知打开粘贴板-url
  1463. [[NSNotificationCenter defaultCenter] postNotificationName:OpenTheClipboard object:nil userInfo:@{@"url":url}];
  1464. }
  1465. -(void)clearWeb{
  1466. NSURLCache * cache = [NSURLCache sharedURLCache];
  1467. [cache removeAllCachedResponses];
  1468. [cache setDiskCapacity:0];
  1469. [cache setMemoryCapacity:0];
  1470. }
  1471. /*
  1472. #pragma mark - Navigation
  1473. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1474. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1475. // Get the new view controller using [segue destinationViewController].
  1476. // Pass the selected object to the new view controller.
  1477. }
  1478. */
  1479. @end