JYNewMineViewController.m 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  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. [[LXViewControllerManager shareViewControllerManager] hideHud];
  438. [self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
  439. // [self.webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';"completionHandler:nil];
  440. //写数据
  441. // [self writeWKWebData:webView.URL];
  442. }
  443. -(void)writeWKWebData:(NSURL *)url {
  444. //得到NSData 数据
  445. NSData *dataContent = [NSData dataWithContentsOfURL:url];
  446. //NSURLCache 实例化
  447. NSURLCache *cache = [NSURLCache sharedURLCache];
  448. //得到相应
  449. NSURLResponse *response = [[NSURLResponse alloc]initWithURL:url MIMEType:@"text/html" expectedContentLength:0 textEncodingName:@"UTF-8"];
  450. //得到CacheURLResponse
  451. NSCachedURLResponse *cacheResponse = [[NSCachedURLResponse alloc]initWithResponse:response data:dataContent];
  452. //进行存储
  453. [cache storeCachedResponse:cacheResponse forRequest:[NSURLRequest requestWithURL:url]];
  454. }
  455. // 页面开始加载时调用
  456. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
  457. self.recognizer.enabled = NO;
  458. }
  459. // 当内容开始返回时调用
  460. - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
  461. }
  462. // 页面加载失败时调用
  463. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(nonnull NSError *)error{
  464. //加载失败 有网络-弹出页面 , 无网络-记录标记
  465. if ([ZKMethod judegeNetworkIsAvailable]) {
  466. //弹出页面
  467. NSLog(@"页面加载失败-有网络");
  468. [self addFailNetViews];
  469. }else {
  470. //记录标记
  471. NSLog(@"页面加载失败-无网络");
  472. isExistNoNewWork = YES;
  473. }
  474. self.recognizer.enabled = YES;
  475. [[GlobalData shareInstance] addOnePlistData:@{
  476. @"detail":[[self stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\n%@",[error description]]],
  477. @"reqTime":[NSNumber numberWithInt:0],
  478. }];
  479. }
  480. #pragma mark *****JS与OC交互
  481. #pragma mark - WKScriptMessageHandler JS调OC交互
  482. -(void)jsLoginByWeixin:(NSDictionary *)dict {
  483. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装微信 不走友盟
  484. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"微信登录失败,没有安装微信" delay:1.5];
  485. return;
  486. }
  487. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
  488. UMSocialUserInfoResponse *resp = result;
  489. [self dealWXDic:(NSDictionary *)resp.originalResponse];
  490. [[LXViewControllerManager shareViewControllerManager] hideHud];
  491. }];
  492. }
  493. // 处理微信登录获取到的数据
  494. -(void)dealWXDic:(NSDictionary *)dictionary{
  495. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  496. //如果获取到用户信息,即用户点击了“登录”,则进行用户信息获取
  497. if (dictionary.count > 0) {
  498. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dictionary];
  499. if (dic) {
  500. [dic removeObjectForKey:@"privilege"];
  501. [dic removeObjectForKey:@"language"];
  502. double currDouble = [[NSDate date] timeIntervalSince1970];
  503. [dic setObject:[NSNumber numberWithLong:(long)currDouble] forKey:@"createtime"];
  504. // 拼接标志位
  505. 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"]];
  506. sign = [LXMD5 md532BitLower:sign];
  507. [dic setObject:sign forKey:@"sign"];
  508. NSString *endStr = [[LXViewControllerManager shareViewControllerManager] getJsonStr:dic];
  509. NSData *data = [endStr dataUsingEncoding:NSUTF8StringEncoding];
  510. endStr = [data base64EncodedStringWithOptions:0];
  511. [self isExitCallToJS:[NSString stringWithFormat:@"loginByWeixinCallBack('%@')", endStr] withMethodName:@"loginByWeixinCallBack"];
  512. }
  513. }
  514. }
  515. -(void)jsShare:(NSDictionary *)dict {
  516. NSString *type = [NSString stringWithFormat:@"%@",dict[@"type"]];
  517. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  518. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  519. NSString *link = [NSString stringWithFormat:@"%@",dict[@"link"]];
  520. UMSocialPlatformType shareType;
  521. if ([type intValue] == 1) { // 微信好友
  522. shareType = UMSocialPlatformType_WechatSession;
  523. }else if ([type intValue] == 2){ /// qq好友
  524. shareType = UMSocialPlatformType_QQ;
  525. }else if ([type intValue] == 3){ // 朋友圈
  526. shareType = UMSocialPlatformType_WechatTimeLine;
  527. }else{
  528. shareType = UMSocialPlatformType_WechatSession;
  529. }
  530. if ([type intValue] == 1 || [type intValue] == 3) {
  531. if ([LXUserDefaults isInstallWeiXin] != 1) {
  532. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装微信" delay:1.5];
  533. return;
  534. }
  535. }
  536. if ([type intValue] == 2) {
  537. if (![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ]) {
  538. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装QQ" delay:1.5];
  539. return;
  540. }
  541. }
  542. //创建分享消息对象
  543. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  544. //创建网页内容对象
  545. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:content thumImage:[UIImage imageNamed:@"logo"]];
  546. //设置网页地址
  547. shareObject.webpageUrl = link;
  548. messageObject.shareObject = shareObject;
  549. //调用分享接口
  550. [[UMSocialManager defaultManager] shareToPlatform:shareType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  551. NSLog(@"%@",error);
  552. if (error) {
  553. if (error.userInfo[@"message"] && [error.userInfo[@"message"] containsString:@"Operation is cancel"]) {
  554. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"取消分享" delay:1];
  555. }else{
  556. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:error.userInfo[@"message"] delay:1];
  557. }
  558. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"0"] withMethodName:@"shareCallBack"];
  559. }else{
  560. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  561. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"1"] withMethodName:@"shareCallBack"];
  562. }else{
  563. UMSocialLogInfo(@"response data is %@",data);
  564. }
  565. }
  566. }];
  567. }
  568. -(void)jsSaveUserToken:(NSDictionary *)dict{
  569. [[LXViewControllerManager shareViewControllerManager] hideHud];
  570. [LXUserDefaults saveToken:[NSString stringWithFormat:@"%@",dict[@"token"]]];
  571. }
  572. -(NSString *)jsGetUserToken:(NSDictionary *)dict{
  573. return [LXUserDefaults token];
  574. }
  575. -(void)jsRemoveUserToken:(NSDictionary *)dict{
  576. [LXUserDefaults clearAll];
  577. }
  578. -(int)jsCheckNoticePermission:(NSDictionary *)dict{
  579. return [LXUserDefaults notifyState];
  580. }
  581. // 跳转到系统设置
  582. -(void)jsOpenSystemNotification:(NSDictionary *)dict{
  583. self.updateNotify = YES;
  584. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  585. }
  586. // 获取推送id
  587. -(NSString *)jsGetPushRid:(NSDictionary *)dict{
  588. return [LXUserDefaults registrationID];
  589. }
  590. // 打开新页面 加载新web
  591. -(void)JsOpenExternalLink:(NSDictionary *)dict{
  592. NSString *url = [NSString stringWithFormat:@"%@",dict[@"url"]];
  593. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  594. if (url) {
  595. if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable || [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown) {
  596. }
  597. JYWKNewWebController *ctr = [[JYWKNewWebController alloc] init];
  598. ctr.url = url;
  599. if (!title || [title isEqualToString:@""]||[title isEqualToString:@"undefined"]) {
  600. ctr.titleShow = nil;
  601. }else{
  602. ctr.titleShow = title;
  603. }
  604. kMainQueue(^{
  605. [self presentViewController:ctr animated:NO completion:nil];
  606. });
  607. }
  608. }
  609. // 获取当前版本号
  610. -(NSString *)jsGetVersion:(NSDictionary *)dict{
  611. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  612. }
  613. -(void)jsAlert:(NSDictionary *)dict{
  614. [[LXViewControllerManager shareViewControllerManager] showAlertViewWithMessage:[NSString stringWithFormat:@"%@",dict[@"content"]]];
  615. }
  616. -(int)jsIsInstallWeixin:(NSDictionary *)dict{
  617. return [LXUserDefaults isInstallWeiXin];
  618. }
  619. -(NSString *)jsGetCipherText:(NSDictionary *)dict{
  620. NSDictionary *objDict = [NSDictionary dictionaryWithDictionary:dict[@"arguments"]];
  621. NSString *phone = [NSString stringWithFormat:@"%@",objDict[@"phone"]];
  622. NSDate *date=[NSDate date];
  623. NSDateFormatter *format1=[[NSDateFormatter alloc] init];
  624. [format1 setDateFormat:@"yyyyMMddhhmmss"];
  625. NSString *dateStr;
  626. dateStr=[format1 stringFromDate:date];
  627. NSString *content = [[NSString stringWithFormat:@"%@_%@",phone,dateStr] stringByAppendingString:[NSString stringWithFormat:@"_%@",[LXMD5 md532BitLower:[NSString stringWithFormat:@"%@&%@",phone,dateStr]]]];
  628. NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
  629. NSUInteger dataLength = contentData.length;
  630. // 为结束符'\\0' +1
  631. char keyPtr[new_kKeySize_4 + 1];
  632. memset(keyPtr, 0, sizeof(keyPtr));
  633. [new_AesKey_4 getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
  634. // 密文长度 <= 明文长度 + BlockSize
  635. size_t encryptSize = dataLength + kCCBlockSizeAES128;
  636. void *encryptedBytes = malloc(encryptSize);
  637. size_t actualOutSize = 0;
  638. NSData *initVector = [new_kInitVector_4 dataUsingEncoding:NSUTF8StringEncoding];
  639. CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
  640. kCCAlgorithmAES,
  641. kCCOptionPKCS7Padding, // 系统默认使用 CBC,然后指明使用 PKCS7Padding
  642. keyPtr,
  643. new_kKeySize_4,
  644. initVector.bytes,
  645. contentData.bytes,
  646. dataLength,
  647. encryptedBytes,
  648. encryptSize,
  649. &actualOutSize);
  650. if (cryptStatus == kCCSuccess) {
  651. // 对加密后的数据进行 base64 编码
  652. return [[NSData dataWithBytesNoCopy:encryptedBytes length:actualOutSize] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  653. }
  654. free(encryptedBytes);
  655. return nil;
  656. }
  657. -(void)jsHiddenBottom:(NSDictionary *)dict{
  658. if(self.tabBarController.selectedIndex == 3) {
  659. if([[NSString stringWithFormat:@"%@",dict[@"hidden"]] integerValue]==0) {
  660. [self hideTabBar];
  661. [self hiddenMethodTabBar];
  662. }else {
  663. [self showTabBar];
  664. [self showMethodTabBar];
  665. }
  666. }
  667. }
  668. -(void)jsCheckLab:(NSDictionary *)dict {
  669. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshNonCurVC object:nil userInfo:nil];
  670. }
  671. //js方法登录成功
  672. -(void)jsLoginSuccess:(NSDictionary *)dict {
  673. NSLog(@"mine登录成功提示");
  674. NSString *status = [NSString stringWithFormat:@"%@",dict[@"status"]];
  675. [GlobalData shareInstance].isReLogin = YES;
  676. if([status isEqualToString:@"S"]) {
  677. kMainQueue(^{
  678. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshAllVC object:nil userInfo:nil];
  679. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  680. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  681. tab.selectedIndex = 0;
  682. //
  683. });
  684. }else {
  685. }
  686. //弹出页面
  687. if ([GlobalData shareInstance].isPasteLogin) {
  688. [GlobalData shareInstance].isPasteLogin = NO;
  689. NSString *content = [UIPasteboard generalPasteboard].string;
  690. [self popPasteVIew:content];
  691. }
  692. }
  693. -(void)jsBackUrl:(NSDictionary *)dict {
  694. NSString *status = [NSString stringWithFormat:@"%@",dict[@"status"]];
  695. NSLog(@"sub返回");
  696. if([status isEqualToString:@"H"]) {
  697. //测试返回首页
  698. kMainQueue(^{
  699. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshAllVC object:nil userInfo:nil];
  700. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  701. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  702. tab.selectedIndex = 0;
  703. });
  704. }
  705. }
  706. -(void)jsClearPushMessage:(NSDictionary *)dict {
  707. kMainQueue(^{
  708. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
  709. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  710. });
  711. }
  712. -(void)jsHideRedSpotOnMenu:(NSDictionary *)dict {
  713. NSString *menu = [NSString stringWithFormat:@"%@",dict[@"menu"]];
  714. if([menu isEqualToString:@"subscribe"]) {
  715. kMainQueue(^{
  716. [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
  717. });
  718. }
  719. if([menu isEqualToString:@"my"]) {
  720. kMainQueue(^{
  721. [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  722. });
  723. }
  724. }
  725. -(void)jsShowRedSpotOnMenu:(NSDictionary *)dict {
  726. NSString *menu = [NSString stringWithFormat:@"%@",dict[@"menu"]];
  727. if([menu isEqualToString:@"subscribe"]) {
  728. kMainQueue(^{
  729. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  730. });
  731. }
  732. if([menu isEqualToString:@"my"]) {
  733. kMainQueue(^{
  734. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  735. });
  736. }
  737. }
  738. -(void)jsWxPay:(NSDictionary *)dict {
  739. NSString *jsonString = [NSString stringWithFormat:@"%@",dict[@"order"]];
  740. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装wx
  741. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先安装微信再进行支付!" delay:1.5];
  742. return;
  743. }
  744. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  745. NSError *err;
  746. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
  747. if(err) {
  748. NSLog(@"json解析失败:%@",err);
  749. return;
  750. }
  751. //吊起微信
  752. PayReq *request = [[PayReq alloc] init] ;
  753. request.openID = dic[@"Appid"];
  754. request.partnerId = dic[@"Partnerid"];
  755. request.prepayId= dic[@"Prepayid"];
  756. request.package = @"Sign=WXPay";
  757. request.nonceStr= dic[@"Noncestr"];
  758. request.timeStamp= [dic[@"Timestamp"] intValue];
  759. request.sign= dic[@"Sign"];
  760. kMainQueue(^{
  761. [WXApi sendReq:request];
  762. });
  763. }
  764. -(void)jsAliPay:(NSDictionary *)dict {
  765. NSString *order = [NSString stringWithFormat:@"%@",dict[@"order"]];
  766. kMainQueue(^{
  767. [[AlipaySDK defaultService] payOrder:order fromScheme:@"jianyuiosapp" callback:nil];
  768. });
  769. }
  770. -(NSString *)jsGetOtherPushRid:(NSDictionary *)dict {
  771. return [LXUserDefaults deviceToken];
  772. }
  773. -(NSString *)jsGetPhoneBrand:(NSDictionary *)dict {
  774. UIDevice *device = [UIDevice currentDevice];
  775. return device.platformString;
  776. }
  777. //拍照上传图片
  778. -(void)jsSkipCameraWithParam:(NSDictionary *)dict {
  779. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  780. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  781. picker.delegate = self;
  782. picker.allowsEditing = YES;
  783. picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  784. dispatch_async(dispatch_get_main_queue(), ^{
  785. [self presentViewController:picker animated:YES completion:nil];
  786. });
  787. }
  788. //相册选择照片
  789. -(void)jsSkipAlbumWithParam:(NSDictionary *)dict {
  790. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  791. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  792. picker.delegate = self;
  793. picker.allowsEditing = YES;
  794. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  795. dispatch_async(dispatch_get_main_queue(), ^{
  796. [self presentViewController:picker animated:YES completion:nil];
  797. });
  798. }
  799. -(void)jsOpenActivityPage:(NSDictionary *)dict {
  800. NSDictionary * infoDic = @{@"url":[NSString stringWithFormat:@"%@",dict[@"url"]],
  801. @"rectype":[NSString stringWithFormat:@"%@",dict[@"rectype"]],
  802. @"openid":[NSString stringWithFormat:@"%@",dict[@"openid"]],
  803. };
  804. //post请求
  805. NSLog(@"%@",[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost]);
  806. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost] parameters:infoDic progress:^(NSProgress *progress) {
  807. NSLog(@"成功:%@",progress);
  808. } success:^(id responseObject) {
  809. NSLog(@"responseObject=%@",responseObject);
  810. } failure:^(NSError *error) {
  811. NSLog(@"error=%@",error);
  812. [[GlobalData shareInstance] addOnePlistData:@{
  813. @"detail":[NSString stringWithFormat:@"message/receive接口:%@",[error description]],
  814. @"reqTime":[NSNumber numberWithInt:0],
  815. }];
  816. }];
  817. }
  818. //拨打电话
  819. -(void)jsCallPhone:(NSDictionary *)dict {
  820. NSString *phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
  821. NSMutableString *tel = [[NSMutableString alloc]initWithFormat:@"telprompt://%@",phone];
  822. if (@available(iOS 10.0, *)) {
  823. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel] options:@{} completionHandler:^(BOOL success) {
  824. }];
  825. } else {
  826. // Fallback on earlier versions
  827. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
  828. }
  829. }
  830. //打开其他app 抖音+快手
  831. -(void)jsOpenOtherAppLinks:(NSDictionary *)dict {
  832. //测试跳转抖音--快手 @"gifshow://" @"snssdk1128://"
  833. NSString *appLink = [NSString stringWithFormat:@"%@",dict[@"appLink"]];
  834. NSString *appName = [NSString stringWithFormat:@"%@",dict[@"appName"]];
  835. NSLog(@"appName:%@",appName);
  836. NSURL *url = [NSURL URLWithString:appLink];
  837. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  838. if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
  839. //iOS 10.0+
  840. NSLog(@"iOS 10+");
  841. if (@available(iOS 10.0, *)) {
  842. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  843. if (!success) {
  844. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  845. }
  846. }];
  847. } else {
  848. // Fallback on earlier versions
  849. [[UIApplication sharedApplication] openURL:url];
  850. }
  851. }else{
  852. NSLog(@"iOS 2~10");
  853. //iOS 2~10
  854. [[UIApplication sharedApplication] openURL:url];
  855. }
  856. }else{
  857. //一般是没有安装
  858. NSLog(@"跳转下载app链接");
  859. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  860. }
  861. }
  862. #pragma mark *****人脸核身
  863. //ocr验证
  864. -(void)jsOcrVerifyService:(NSDictionary *)dict{
  865. NSLog(@"ocr:%@",dict);
  866. NSString *orderNo = [NSString stringWithFormat:@"%@",dict[@"orderNo"]];
  867. NSString *nonce = [NSString stringWithFormat:@"%@",dict[@"nonce"]];
  868. NSString *userId = [NSString stringWithFormat:@"%@",dict[@"userId"]];
  869. NSString *sign = [NSString stringWithFormat:@"%@",dict[@"sign"]];
  870. kMainQueue((^{
  871. WBOCRConfig *config = [WBOCRConfig sharedConfig];
  872. config.needRecordVideo = NO;
  873. config.SDKType = WBOCRSDKTypeIDCardNormal; // 身份证两面识别
  874. [[WBOCRService sharedService] startOCRServiceWithConfig:config version:@"1.0.0" appId:OCRAPPID nonce:nonce userId:userId sign:sign orderNo:orderNo startSucceed:^{
  875. /** SDK服务拉起成功回调 */
  876. NSLog(@"启动SDK成功!!!");
  877. } recognizeSucceed:^(id _Nonnull resultModel, id _Nullable extension) {
  878. /** SDK本次识别成功回调 */
  879. NSLog(@"SDK识别成功!!!");
  880. //调用js - 告知成功
  881. NSString *textJS = [NSString stringWithFormat:@"ocrVerifyResult('%@')",orderNo];
  882. [self isExitCallToJS:textJS withMethodName:@"ocrVerifyResult"];
  883. } failed:^(NSError * _Nonnull error, id _Nullable extension) {
  884. /** SDK异常回调 */
  885. NSLog(@"识别出错!!!"); //200101 用户取消操作
  886. //弹出页面
  887. if (error.code == 200101) {
  888. self.verifyMsgView.descTitle = @"您取消了身份验证";
  889. }else {
  890. self.verifyMsgView.descTitle = @"身份验证失败";
  891. }
  892. [self.verifyMsgView show];
  893. NSString *textJS = [NSString stringWithFormat:@"ocrVerifyResult('%@')",@""];
  894. [self isExitCallToJS:textJS withMethodName:@"ocrVerifyResult"];
  895. }];
  896. }));
  897. }
  898. //人脸核身
  899. -(void)jsFaceVerifyService:(NSDictionary *)dict {
  900. NSLog(@"face:%@",dict);
  901. NSString *orderNo = [NSString stringWithFormat:@"%@",dict[@"orderNo"]];
  902. NSString *nonce = [NSString stringWithFormat:@"%@",dict[@"nonce"]];
  903. NSString *userId = [NSString stringWithFormat:@"%@",dict[@"userId"]];
  904. NSString *sign = [NSString stringWithFormat:@"%@",dict[@"sign"]];
  905. NSString *faceId = [NSString stringWithFormat:@"%@",dict[@"faceId"]];
  906. kMainQueue((^{
  907. [WBFaceVerifyCustomerService sharedInstance].delegate = self;
  908. WBFaceVerifySDKConfig *config = [WBFaceVerifySDKConfig sdkConfig];
  909. config.recordVideo = NO;
  910. config.theme = WBFaceVerifyThemeDarkness;
  911. [[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:^{
  912. } failure:^(WBFaceError * _Nonnull error) {
  913. }];
  914. }));
  915. }
  916. #pragma mark - WBFaceVerifyCustomerServiceDelegate
  917. -(void)wbfaceVerifyCustomerServiceDidFinishedWithFaceVerifyResult:(WBFaceVerifyResult *)faceVerifyResult{
  918. if (faceVerifyResult.isSuccess) {
  919. NSLog(@"活体检测成功:%@",faceVerifyResult.orderNo);
  920. NSString *textJS = [NSString stringWithFormat:@"faceVerifyResult('%@')",faceVerifyResult.orderNo];
  921. [self isExitCallToJS:textJS withMethodName:@"faceVerifyResult"];
  922. self.verifyMsgView.descTitle = @"活体检测成功";
  923. [self.verifyMsgView show];
  924. }else {
  925. NSLog(@"活体检测失败");
  926. self.verifyMsgView.descTitle = @"活体检测失败";
  927. [self.verifyMsgView show];
  928. NSString *textJS = [NSString stringWithFormat:@"faceVerifyResult('%@')",@""];
  929. [self isExitCallToJS:textJS withMethodName:@"faceVerifyResult"];
  930. }
  931. }
  932. //保存图片到相册
  933. #pragma mark 保存图片
  934. -(void)jsSavePic:(NSDictionary *)dict {
  935. NSString *base64ImgData = [NSString stringWithFormat:@"%@",dict[@"imgbase64"]];
  936. NSData *data = [[NSData alloc]initWithBase64EncodedString:base64ImgData options:NSDataBase64DecodingIgnoreUnknownCharacters];
  937. UIImage *saveImg = [UIImage imageWithData:data];
  938. UIImageWriteToSavedPhotosAlbum(saveImg, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
  939. }
  940. #pragma mark 系统的完成保存图片的方法
  941. - (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
  942. {
  943. NSString *msg = nil ;
  944. if (error != NULL) {
  945. msg = @"保存图片失败" ;
  946. } else {
  947. msg = @"保存图片成功" ;
  948. }
  949. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:msg delay:1];
  950. }
  951. #pragma mark 粘贴板
  952. -(void)jsWirteRight:(NSDictionary *)dict {
  953. NSString *txt = [NSString stringWithFormat:@"%@",dict[@"txt"]];
  954. [[UIPasteboard generalPasteboard]setString:txt];
  955. }
  956. -(void)jsClearRight:(NSDictionary *)dict {
  957. //清粘贴板数据
  958. [[UIPasteboard generalPasteboard]setString:@""];
  959. }
  960. -(NSString *)jsReadRight:(NSDictionary *)dict {
  961. NSString *content = [UIPasteboard generalPasteboard].string;
  962. return content;
  963. }
  964. //内购VIP
  965. -(void)jsInPurchasingVip:(NSDictionary *)dict {
  966. NSString *productid = [NSString stringWithFormat:@"%@",dict[@"productid"]];
  967. //产品id
  968. if ([productid isEqualToString:@""]) {
  969. NSLog(@"订单号 有问题");
  970. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"订单号异常,请重试" delay:1];
  971. return;
  972. }
  973. [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果验证中,请稍候"];
  974. if([SKPaymentQueue canMakePayments]){
  975. [self requestProductData:productid];
  976. }else{
  977. [[LXViewControllerManager shareViewControllerManager] hideHud];
  978. }
  979. }
  980. //去苹果服务器请求商品
  981. - (void)requestProductData:(NSString *)type {
  982. NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
  983. NSSet *nsset = [NSSet setWithArray:product];
  984. SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
  985. request.delegate = self;
  986. [request start];
  987. }
  988. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
  989. NSArray *myProduct = response.products;
  990. if (myProduct.count == 0) {
  991. NSLog(@"无法获取产品信息,购买失败。");
  992. [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"暂时未获取到产品信息,请重试" delay:1];
  993. return;
  994. }
  995. SKPayment * payment = [SKPayment paymentWithProduct:myProduct[0]];
  996. [[SKPaymentQueue defaultQueue] addPayment:payment];
  997. }
  998. #pragma mark *****其他方法
  999. -(void)judgeIsHiddenBottom {
  1000. if(self.tabBarController.selectedIndex == 3) {
  1001. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  1002. if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/me",kHost]]){
  1003. [self showTabBar];
  1004. [self showMethodTabBar];
  1005. }else {
  1006. [self hideTabBar];
  1007. [self hiddenMethodTabBar];
  1008. }
  1009. }
  1010. }
  1011. -(void)pushDY:(NSDictionary *)infoDict
  1012. {
  1013. [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshDY" object:nil userInfo:infoDict];
  1014. }
  1015. -(void)requestWebTime:(NSDictionary *)infoDict
  1016. {
  1017. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
  1018. if ([urlStr containsString:@"https://"]||[urlStr containsString:@"http://"]) {
  1019. }else {
  1020. urlStr = [kHost stringByAppendingString:urlStr];
  1021. }
  1022. if([infoDict[@"type"] isEqualToString:@"message"]) {
  1023. NSArray * array = [urlStr componentsSeparatedByString:@"=="];
  1024. urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1025. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
  1026. }else if ([infoDict[@"type"] isEqualToString:@"titleMessage"]) {
  1027. NSArray * array = [urlStr componentsSeparatedByString:@"=="];
  1028. urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1029. NSString * titleStr = @"消息通知";
  1030. titleStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"title"]];
  1031. if (urlStr&&self.tabBarController.selectedIndex == 3) {
  1032. [self JsOpenExternalLink:@{@"url":urlStr,@"title":titleStr}];
  1033. }
  1034. }else {
  1035. urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1036. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
  1037. }
  1038. }
  1039. - (void)hideTabBar {
  1040. kMainQueue(^{
  1041. if (self.tabBarController.tabBar.hidden == YES) {
  1042. return;
  1043. }
  1044. UIView *contentView;
  1045. if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
  1046. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  1047. else
  1048. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  1049. 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);
  1050. self.tabBarController.tabBar.hidden = YES;
  1051. });
  1052. }
  1053. - (void)showTabBar{
  1054. kMainQueue(^{
  1055. if (self.tabBarController.tabBar.hidden == NO)
  1056. {
  1057. return;
  1058. }
  1059. UIView *contentView;
  1060. if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
  1061. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  1062. else
  1063. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  1064. 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);
  1065. self.tabBarController.tabBar.hidden = NO;
  1066. });
  1067. }
  1068. - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
  1069. {
  1070. __block NSString *resultString = nil;
  1071. __block BOOL finished = NO;
  1072. [self.webView evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
  1073. if (error == nil) {
  1074. if (result != nil) {
  1075. resultString = [NSString stringWithFormat:@"%@", result];
  1076. }
  1077. } else {
  1078. NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
  1079. }
  1080. finished = YES;
  1081. }];
  1082. while (!finished) {
  1083. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
  1084. }
  1085. return resultString;
  1086. }
  1087. -(void)hiddenMethodTabBar
  1088. {
  1089. kMainQueue(^{
  1090. if (iPhoneX) {
  1091. if (@available(iOS 11.0, *)) {
  1092. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
  1093. }
  1094. }else {
  1095. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
  1096. }
  1097. });
  1098. }
  1099. -(void)showMethodTabBar
  1100. {
  1101. kMainQueue(^{
  1102. if (iPhoneX) {
  1103. if (@available(iOS 11.0, *)) {
  1104. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT);
  1105. }
  1106. }else {
  1107. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
  1108. }
  1109. });
  1110. }
  1111. //取消获取照片
  1112. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  1113. {
  1114. dispatch_async(dispatch_get_main_queue(), ^{
  1115. [picker dismissViewControllerAnimated:YES completion:^{
  1116. [self uploadUrl:@""];
  1117. }];
  1118. });
  1119. }
  1120. //上传图片
  1121. -(void)uploadPic:(NSData *)data
  1122. {
  1123. NSString *isPath = @"courseFile";
  1124. if (![[GlobalData shareInstance].isSkipPath isEqualToString:@""]) {
  1125. isPath = [GlobalData shareInstance].isSkipPath;
  1126. }
  1127. NSDictionary * body = @{@"type":isPath};
  1128. AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
  1129. //ContentType设置
  1130. manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html",@"image/jpeg",@"image/png",@"application/octet-stream",@"text/json",@"text/plain",nil];
  1131. manager.responseSerializer= [AFHTTPResponseSerializer serializer];
  1132. manager.requestSerializer = [AFHTTPRequestSerializer serializer];
  1133. manager.requestSerializer.timeoutInterval = 15.0f;
  1134. [manager POST:[NSString stringWithFormat:@"%@jyapp/filemanage/upload",kHost] parameters:body constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
  1135. //上传的参数(上传图片,以文件流的格式)
  1136. [formData appendPartWithFileData:data
  1137. name:isPath
  1138. fileName:[isPath stringByAppendingFormat:@".jpeg"]
  1139. mimeType:@"image/jpeg"];
  1140. } progress:^(NSProgress * _Nonnull uploadProgress) {
  1141. CGFloat progress = 100.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount;
  1142. NSLog(@"%.2lf%%", progress);
  1143. } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  1144. //请求成功的block回调
  1145. NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
  1146. NSLog(@"上传成功%@",dic);
  1147. if ([dic[@"msg"] isEqualToString:@"ssss"]) {
  1148. [self uploadUrl:dic[@"url"]];
  1149. }else{
  1150. [self uploadUrl:@""];
  1151. }
  1152. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  1153. NSLog(@"上传失败%@",error);
  1154. [self uploadUrl:@""];
  1155. [[GlobalData shareInstance] addOnePlistData:@{
  1156. @"detail":@"上传图片接口",
  1157. @"reqTime":[NSNumber numberWithInt:0],
  1158. }];
  1159. }];
  1160. }
  1161. -(void)uploadUrl:(NSString *)url {
  1162. NSString *textJS = [NSString new];
  1163. NSString *methodJS = [NSString new];
  1164. if ([url isEqualToString:@""]) {
  1165. textJS = @"hiddenLoading()";
  1166. methodJS =@"hiddenLoading";
  1167. }else{
  1168. textJS = [NSString stringWithFormat:@"uploadImg('%@')",url];
  1169. methodJS = @"uploadImg";
  1170. }
  1171. if ([url isEqualToString:@""]||[textJS isEqualToString:@""]) {
  1172. NSLog(@"空的情况");
  1173. textJS = @"hiddenLoading()";
  1174. methodJS = @"hiddenLoading";
  1175. }
  1176. NSDictionary *dict = @{@"jsStr":textJS,@"name":methodJS};
  1177. [self performSelector:@selector(uploadJS:) withObject:dict afterDelay:1];
  1178. }
  1179. //获取到图片
  1180. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  1181. {
  1182. dispatch_async(dispatch_get_main_queue(), ^{
  1183. [picker dismissViewControllerAnimated:YES completion:^{
  1184. UIImage * img=[info objectForKey:UIImagePickerControllerEditedImage];
  1185. NSData *data = UIImageJPEGRepresentation(img, 0.5);
  1186. if (data!=nil) {
  1187. [self uploadPic:data];
  1188. }else{
  1189. NSLog(@"data == nil");
  1190. [self uploadUrl:@""];
  1191. }
  1192. }];
  1193. });
  1194. }
  1195. -(void)uploadJS:(NSDictionary *)dict {
  1196. [self isExitCallToJS:dict[@"jsStr"] withMethodName:dict[@"name"]];
  1197. }
  1198. - (BOOL)checkLocationServiceIsEnabled{
  1199. // 该方法是类方法,和我们创建的管理器没有关系
  1200. if ([CLLocationManager locationServicesEnabled]) {
  1201. return YES;
  1202. }
  1203. return NO;
  1204. }
  1205. -(NSString *)convertToJsonData:(NSDictionary *)dict {
  1206. NSError *error;
  1207. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
  1208. NSString *jsonString;
  1209. if (!jsonData) {
  1210. NSLog(@"%@",error);
  1211. }else{
  1212. jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  1213. }
  1214. NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
  1215. NSRange range = {0,jsonString.length};
  1216. //去掉字符串中的空格
  1217. [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
  1218. NSRange range2 = {0,mutStr.length};
  1219. //去掉字符串中的换行符
  1220. [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
  1221. return mutStr;
  1222. }
  1223. -(void)addNoNetViews{
  1224. kMainQueue(^{
  1225. [self removeNoNetViews];
  1226. self.noNetView = [NoNetView shareView];
  1227. [self.view addSubview:self.noNetView];
  1228. });
  1229. }
  1230. -(void)removeNoNetViews{
  1231. if (self.noNetView ) {
  1232. [self.noNetView removeFromSuperview];
  1233. self.noNetView = nil;
  1234. }
  1235. }
  1236. -(void)addFailNetViews{
  1237. kMainQueue(^{
  1238. [self removeFailNetViews];
  1239. self.failNetView = [NoNetView shareView];
  1240. if(self.tabBarController.selectedIndex == 0) {
  1241. if ([self.webView canGoBack]) {
  1242. self.failNetView.popBtn.hidden = NO;
  1243. }else{
  1244. self.failNetView.popBtn.hidden = YES;
  1245. }
  1246. }
  1247. [self.view addSubview:self.failNetView];
  1248. });
  1249. }
  1250. -(void)removeFailNetViews{
  1251. if (self.failNetView ) {
  1252. [self.failNetView removeFromSuperview];
  1253. self.failNetView = nil;
  1254. }
  1255. }
  1256. #pragma mark **** 通知相关方法
  1257. // 点击通知 跳转到通知内url
  1258. -(void)requestWebView:(NSNotification *)notification{
  1259. NSDictionary * infoDict = [notification object];
  1260. if (!infoDict) {
  1261. return;
  1262. }
  1263. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
  1264. if (urlStr) {
  1265. //当前控制器
  1266. if(self.tabBarController.selectedIndex != 3) {
  1267. return;
  1268. }
  1269. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  1270. [self performSelector:@selector(requestWebTime:) withObject:infoDict afterDelay:1];
  1271. }
  1272. }
  1273. -(void)clickSubNotiMethods:(NSNotification *)notification{
  1274. if(![LXUserDefaults isExistToken]) {
  1275. return;
  1276. }
  1277. NSDictionary * infoDict = [notification object][@"info"];
  1278. if (!infoDict) {
  1279. return;
  1280. }
  1281. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1282. if (urlStr) {
  1283. NSLog(@"有info");
  1284. if(self.tabBarController.selectedIndex == 3) {
  1285. //底部栏置换到订阅
  1286. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1287. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  1288. tab.selectedIndex = 1;
  1289. [self performSelector:@selector(pushDY:) withObject:infoDict afterDelay:1];
  1290. }
  1291. }
  1292. }
  1293. //点击支付通知
  1294. -(void)clickPayMethods:(NSNotification *)notification{
  1295. NSDictionary * infoDict = [notification object][@"info"];
  1296. if (!infoDict) {
  1297. return;
  1298. }
  1299. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1300. if ([urlStr containsString:@"https://"]||[urlStr containsString:@"http://"]) {
  1301. }else {
  1302. urlStr = [kHost stringByAppendingString:urlStr];
  1303. }
  1304. NSArray * array = [urlStr componentsSeparatedByString:@"=="];
  1305. urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1306. NSString * titleStr = @"消息通知";
  1307. titleStr = [NSString stringWithFormat:@"%@",infoDict[@"title"]];
  1308. if (urlStr) {
  1309. if(self.tabBarController.selectedIndex == 3) {
  1310. [self JsOpenExternalLink:@{@"url":urlStr,@"title":titleStr}];
  1311. }
  1312. }
  1313. }
  1314. -(void)alipayWXpayStatus:(NSNotification *)notification{
  1315. if(self.tabBarController.selectedIndex == 3) {
  1316. NSString * status = [notification object];
  1317. [self performSelector:@selector(payStatus:) withObject:status afterDelay:2];
  1318. }
  1319. }
  1320. -(void)payStatus:(NSString *)status
  1321. {
  1322. //目前延时两秒
  1323. NSLog(@"支付状态:%@",status);
  1324. if(self.tabBarController.selectedIndex == 3) {
  1325. [self isExitCallToJS:[NSString stringWithFormat:@"payCallBack('%@')", status] withMethodName:@"payCallBack"];
  1326. }
  1327. }
  1328. // 调用js方法 刷新推送权限状态
  1329. -(void)updateNotifyState{
  1330. if (self.updateNotify) {
  1331. self.updateNotify = NO;
  1332. [self isExitCallToJS:[NSString stringWithFormat:@"updateNoticeSwitch()"] withMethodName:@"updateNoticeSwitch"];
  1333. }
  1334. }
  1335. // 收到通知消息
  1336. -(void)afterReceiveNewMsg{
  1337. if(self.tabBarController.selectedIndex == 3) {
  1338. NSLog(@"afterReceiveNewMsg");
  1339. [self isExitCallToJS:@"afterReceiveNewMsg()" withMethodName:@"afterReceiveNewMsg"];
  1340. }
  1341. }
  1342. // 再次加载页面
  1343. -(void)reloadWebView{
  1344. if(self.tabBarController.selectedIndex == 3) {
  1345. if (![self.webView canGoBack]) {
  1346. [self webViewFirstRequest];
  1347. }else{
  1348. [self.webView reload];
  1349. }
  1350. }
  1351. }
  1352. // 返回上一页面- 防止
  1353. -(void)popWebView{
  1354. if(self.tabBarController.selectedIndex == 3) {
  1355. if ([self.webView canGoBack]) {
  1356. [self.webView goBack];
  1357. }
  1358. [self removeNoNetViews];
  1359. [self removeFailNetViews];
  1360. }
  1361. }
  1362. // 收到退出登录消息
  1363. -(void)loginOut:(NSNotification *)notification{
  1364. if([notification.userInfo[@"item_index"] integerValue]!=3) {
  1365. return;
  1366. }
  1367. [self webViewRequestByMsg];
  1368. }
  1369. //收到消息退出并重新加载web
  1370. -(void)webViewRequestByMsg{
  1371. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login?back=index&isios=t&flag=kicked"];
  1372. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1373. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  1374. }
  1375. // 监控网络状态变化
  1376. -(void)netReachChanged:(NSNotification *)notificaition{
  1377. NSDictionary *userInfo = notificaition.userInfo;
  1378. if ([userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == 0 || [userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == -1) {
  1379. [self addNoNetViews];
  1380. }else{
  1381. [self removeNoNetViews];
  1382. if (isExistNoNewWork) {
  1383. isExistNoNewWork = NO;
  1384. [self reloadWebView];
  1385. }
  1386. }
  1387. }
  1388. -(void)newsRedPoint:(NSNotification *)notificaition
  1389. {
  1390. NSDictionary *dict = notificaition.userInfo;
  1391. if(self.tabBarController.selectedIndex == 3) {
  1392. NSString *textJS = [NSString stringWithFormat:@"afterReceivePushMessage('%@','%@')",dict[@"typeMsg"],dict[@"url"]];
  1393. [self isExitCallToJS:textJS withMethodName:@"afterReceivePushMessage"];
  1394. }
  1395. }
  1396. //刷新页面相关
  1397. -(void)refreshNonCurVC:(NSNotification *)notificaition{
  1398. if(self.tabBarController.selectedIndex != 3) {
  1399. [self webViewFirstRequest];
  1400. }
  1401. }
  1402. -(void)refreshAllVC:(NSNotification *)notificaition{
  1403. [self webViewFirstRequest];
  1404. }
  1405. -(void)refreshExpAndMine:(NSNotification *)notificaition{
  1406. [self webViewFirstRequest];
  1407. }
  1408. //内购相关
  1409. -(void)receiptData:(NSNotification *)notificaition{
  1410. if(self.tabBarController.selectedIndex == 3) {
  1411. NSDictionary *infoDict = notificaition.userInfo;
  1412. if (infoDict) {
  1413. NSString *receipt = [NSString stringWithFormat:@"%@", infoDict[@"receipt"]];
  1414. [self isExitCallToJS:[NSString stringWithFormat:@"getReceipt('%@')", receipt] withMethodName:@"getReceipt"];
  1415. }
  1416. }
  1417. }
  1418. #pragma mark ****粘贴板相关-梳理
  1419. -(void)updateClipboard:(NSNotification *)notificaition{
  1420. if(self.tabBarController.selectedIndex == 3) {
  1421. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  1422. NSDictionary *dict = notificaition.userInfo;
  1423. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  1424. if ([current_url containsString:@"jyapp/free/login"]) {
  1425. [GlobalData shareInstance].isPasteLogin = YES;
  1426. }else {
  1427. [self popPasteVIew:content];
  1428. }
  1429. }
  1430. }
  1431. -(void)openTheClipboard:(NSNotification *)notificaition{
  1432. if(self.tabBarController.selectedIndex == 3) {
  1433. NSLog(@"菜单四打开指定粘贴板url");
  1434. NSDictionary *dict = notificaition.userInfo;
  1435. NSString *tmpUrl = [NSString stringWithFormat:@"%@%@", kHost, dict[@"url"]];
  1436. tmpUrl = [tmpUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1437. kMainQueue(^{
  1438. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tmpUrl]]];
  1439. })
  1440. }
  1441. }
  1442. //弹出粘贴板框
  1443. -(void)popPasteVIew:(NSString *)content {
  1444. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@distribution/share/getWordInfo",kHost] parameters:@{@"copyTxt":content} progress:^(NSProgress *progress) {
  1445. NSLog(@"%@",progress);
  1446. } success:^(id responseObject) {
  1447. NSLog(@"responseObject=%@",responseObject);
  1448. if ([responseObject objectForKey:@"data"]) {
  1449. NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:responseObject[@"data"]];
  1450. if ([dict objectForKey:@"title"]) {
  1451. self.clipboardView.title =dict[@"title"];
  1452. self.clipboardView.subTitle =dict[@"subTitle"];
  1453. self.clipboardView.imgUrl =dict[@"imgUrl"];
  1454. self.clipboardView.appUrl =dict[@"appUrl"];
  1455. self.clipboardView.butTxt =dict[@"butTxt"];
  1456. self.clipboardView.bottomTxt =dict[@"bottomTxt"];
  1457. [self.clipboardView show];
  1458. }
  1459. }
  1460. } failure:^(NSError *error) {
  1461. NSLog(@"error=%@",error);
  1462. }];
  1463. }
  1464. #pragma mark **** 代理方法
  1465. -(void)clipboardClick:(NSString *)url {
  1466. //发送通知打开粘贴板-url
  1467. [[NSNotificationCenter defaultCenter] postNotificationName:OpenTheClipboard object:nil userInfo:@{@"url":url}];
  1468. }
  1469. -(void)clearWeb{
  1470. NSURLCache * cache = [NSURLCache sharedURLCache];
  1471. [cache removeAllCachedResponses];
  1472. [cache setDiskCapacity:0];
  1473. [cache setMemoryCapacity:0];
  1474. }
  1475. /*
  1476. #pragma mark - Navigation
  1477. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1478. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1479. // Get the new view controller using [segue destinationViewController].
  1480. // Pass the selected object to the new view controller.
  1481. }
  1482. */
  1483. @end