JYNewMessViewController.m 67 KB

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