JYNewSubViewController.m 68 KB

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