JYNewSearchViewController.m 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084
  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 "JYNewSearchViewController.h"
  9. #import <WebKit/WebKit.h>
  10. #import "JYTabBarController.h"
  11. #import <CoreLocation/CoreLocation.h>
  12. #import <GRPCClient/GRPCCall+ChannelArg.h>
  13. #import <GRPCClient/GRPCCall+Tests.h>
  14. @interface JYNewSearchViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,CLLocationManagerDelegate,SKProductsRequestDelegate,SKPaymentTransactionObserver,ZKClipboardViewDelegate,WBFaceVerifyCustomerServiceDelegate,UIDocumentPickerDelegate>
  15. {
  16. NSInteger pushIndex;//第几个模块过来的
  17. BOOL isLoadRedDot;
  18. CGPoint startTouch;
  19. BOOL _isMoving;
  20. BOOL isExistNoNewWork;
  21. }
  22. @property (nonatomic, strong) UIProgressView *progressView;
  23. @property (nonatomic, strong) WKWebView *webView;
  24. @property(nonatomic, assign)BOOL updateNotify;
  25. @property(nonatomic,strong)CLLocationManager *locaationManager;
  26. @property(nonatomic,strong)NSString *placeAdr;
  27. @property(nonatomic,assign)BOOL isLocation;
  28. @property(nonatomic, strong)NoNetView *noNetView;
  29. @property(nonatomic, strong)NoNetView *failNetView;
  30. @property(nonatomic, strong)UIPanGestureRecognizer *recognizer;
  31. @property(nonatomic, strong)ZKClipboardView *clipboardView;
  32. @property(nonatomic, strong)ZKFaceVerifyMsgView *verifyMsgView;
  33. //进度条是否加载中
  34. @property(nonatomic, assign)BOOL isRuningLoad;
  35. @end
  36. NSString *const new_kInitVector_1 = @"1389461544135476";
  37. size_t const new_kKeySize_1 = kCCKeySizeAES128;
  38. NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
  39. @implementation JYNewSearchViewController
  40. -(void)viewWillAppear:(BOOL)animated
  41. {
  42. [super viewWillAppear:animated];
  43. [self.navigationController setNavigationBarHidden:YES animated:animated];
  44. if ([GlobalData shareInstance].isClickNotiStatus) {
  45. [GlobalData shareInstance].searchIsRed = NO;
  46. [GlobalData shareInstance].isClickNotiStatus = NO;
  47. }else {
  48. if([GlobalData shareInstance].searchIsRed) {
  49. [GlobalData shareInstance].searchIsRed = NO;
  50. [self webViewFirstRequest];
  51. }
  52. }
  53. }
  54. //弹框
  55. -(ZKFaceVerifyMsgView *)verifyMsgView
  56. {
  57. if(!_verifyMsgView) {
  58. _verifyMsgView = [[ZKFaceVerifyMsgView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 150)];
  59. _verifyMsgView.titleName = @"温馨提示";
  60. }
  61. return _verifyMsgView;
  62. }
  63. //弹框
  64. -(ZKClipboardView *)clipboardView{
  65. if(!_clipboardView) {
  66. _clipboardView = [[ZKClipboardView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 180+90)];
  67. _clipboardView.delegate = self;
  68. }
  69. return _clipboardView;
  70. }
  71. //进度条
  72. - (UIProgressView *)progressView
  73. {
  74. if (_progressView == nil) {
  75. _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,STATUS_BAR_HEIGHT - 2,WIDTH,2)];
  76. _progressView.tintColor = [UIColor blueColor];
  77. _progressView.trackTintColor = [UIColor whiteColor];
  78. }
  79. return _progressView;
  80. }
  81. //懒加载
  82. - (WKWebView *)webView
  83. {
  84. if(_webView == nil) {
  85. WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
  86. config.preferences = [[WKPreferences alloc] init];
  87. config.preferences.minimumFontSize = 0;
  88. config.allowsInlineMediaPlayback = YES;
  89. config.preferences.javaScriptEnabled = YES;
  90. config.preferences.javaScriptCanOpenWindowsAutomatically = YES;
  91. //添加消息处理,注意:self指代的是需要遵守WKScriptMessageHandler协议,结束时需要移除
  92. config.userContentController = [[WKUserContentController alloc] init];
  93. //声明协议
  94. NSArray *jsArr = @[@"loginByWeixin",
  95. @"share",
  96. @"saveUserToken",
  97. @"removeUserToken",
  98. @"openSystemNotification",
  99. @"openExternalLink",
  100. @"alert",
  101. @"hiddenBottom",
  102. @"checkLab",
  103. @"loginSuccess",
  104. @"backUrl",
  105. @"clearPushMessage",
  106. @"hideRedSpotOnMenu",
  107. @"showRedSpotOnMenu",
  108. @"wxPay",
  109. @"aliPay",
  110. @"chooseTab",
  111. @"skipCameraWithParam",
  112. @"skipAlbumWithParam",
  113. @"openActivityPage",
  114. @"callPhone",
  115. @"openOtherAppLinks",
  116. @"inPurchasingVip",
  117. @"wirteRight",
  118. @"clearRight",
  119. @"savePic",
  120. @"ocrVerifyService",
  121. @"faceVerifyService",
  122. @"skipAppointTab",
  123. @"refreshAppointTab",
  124. ];
  125. for (NSString*jsName in jsArr) {
  126. [config.userContentController addScriptMessageHandler:self name:jsName];
  127. }
  128. //高端的自定义配置创建WKWebView
  129. if (iPhoneX) {
  130. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT) configuration:config];
  131. if (@available(iOS 11.0, *)) {
  132. _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  133. }
  134. }else {
  135. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT) configuration:config];
  136. }
  137. _webView.scrollView.bounces = NO;
  138. _webView.UIDelegate = self;
  139. _webView.navigationDelegate = self;
  140. _webView.userInteractionEnabled = YES;
  141. [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  142. }
  143. return _webView;
  144. }
  145. -(void)webViewFirstRequest
  146. {
  147. //去时间戳-拼接
  148. NSString *tmpUrl = @"";
  149. if ([LXUserDefaults isExistToken]) {
  150. NSString *token = [LXUserDefaults token];
  151. tmpUrl = [[NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login"] stringByAppendingString:[NSString stringWithFormat:@"?sign=%@&url=/jyapp/jylab/mainSearch&from=restart", token]];
  152. }else {
  153. tmpUrl = [[NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/index"] stringByAppendingString:[NSString stringWithFormat:@"?deviceid=%@", [LXUserDefaults getDeviceID]]];
  154. }
  155. NSLog(@"111 :第一次加载:%@",tmpUrl);
  156. tmpUrl = [tmpUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  157. kMainQueue(^{
  158. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tmpUrl]]];
  159. })
  160. }
  161. #pragma mark - event response
  162. // 计算wkWebView进度条
  163. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
  164. // NSLog(@"进度条加载中...");
  165. if (!self.isRuningLoad) {
  166. self.isRuningLoad = YES;
  167. }
  168. if (object == self.webView && [keyPath isEqualToString:@"estimatedProgress"]) {
  169. CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
  170. self.progressView.alpha = 1.0f;
  171. [self.progressView setProgress:newprogress animated:YES];
  172. if (newprogress >= 1.0f) {
  173. NSLog(@"进度条加载完毕...");
  174. self.isRuningLoad = NO;
  175. self.recognizer.enabled = YES;
  176. [UIView animateWithDuration:0.3f
  177. delay:0.3f
  178. options:UIViewAnimationOptionCurveEaseOut
  179. animations:^{
  180. self.progressView.alpha = 0.0f;
  181. }
  182. completion:^(BOOL finished) {
  183. [self.progressView setProgress:0 animated:NO];
  184. }];
  185. }
  186. } else {
  187. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  188. }
  189. }
  190. -(void)initNotification {
  191. //加载通知
  192. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushUrlOtherMethods:) name:OpenPushUrlOtherMethods object:nil];
  193. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushLinkUrlMethods:) name:OpenPushLinkUrlMethods object:nil];
  194. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushUrlMethodsOne:) name:OpenPushUrlMethodsOne object:nil];
  195. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jyReceiveNewsRedPoint:) name:JYReceiveNewsRedPoint object:nil];
  196. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jyRefreshMenusView:) name:JYRefreshMenusView object:nil];
  197. //支付状态通知
  198. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayWXpayStatus:) name:AlipayWXpayStatus object:nil];
  199. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNotifyState:) name:kUpdateNotifyState object:nil];
  200. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notNetReloadWebVIew:) name:NotNetReloadWebVIew object:nil];
  201. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popWebView:) name:PopWebView object:nil];
  202. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut:) name:kLoginOut object:nil];
  203. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
  204. //前往登录通知-tabbar
  205. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isLoginTabBar:) name:LoginIndexTabBar object:nil];
  206. //展示底部红的通知
  207. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jyReceiveNewsRedPoint:) name:JYReceiveNewsRedPoint object:nil];
  208. //接收全新通知
  209. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNonCurVC:) name:RefreshNonCurVC object:nil];
  210. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAllVC:) name:RefreshAllVC object:nil];
  211. //粘贴板-
  212. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateClipboard:) name:UpdateClipboard object:nil];
  213. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openTheClipboard:) name:OpenTheClipboard object:nil];
  214. }
  215. #pragma mark – Gesture Recognizer –
  216. -(void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer
  217. {
  218. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  219. NSLog(@"%@",current_url);
  220. CGRect rect = self.view.bounds;
  221. CGFloat width = CGRectGetWidth(rect);
  222. if (![self.webView canGoBack]||([current_url containsString:@"jyapp/free/login"])) {
  223. NSLog(@"不可返回");
  224. return;
  225. }
  226. 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]]){
  227. return;
  228. }
  229. CGPoint touchPoint = [recoginzer locationInView:[UIApplication sharedApplication].keyWindow];
  230. if (recoginzer.state==UIGestureRecognizerStateBegan) {
  231. _isMoving = YES;
  232. startTouch = touchPoint;
  233. } else if (recoginzer.state==UIGestureRecognizerStateEnded||(recoginzer.state==UIGestureRecognizerStatePossible)){
  234. if (touchPoint.x - startTouch.x > width*0.125) {
  235. [UIView animateWithDuration:0.3 animations:^{
  236. if (recoginzer.state==UIGestureRecognizerStateEnded) {
  237. [self moveViewWithX:width];
  238. if ([current_url containsString:@"jyapp/jylab/mainSearch#"]) {
  239. [self isExitCallToJS:@"afterClickBack()" withMethodName:@"afterClickBack"];
  240. }
  241. [self.webView goBack];
  242. }
  243. } completion:^(BOOL finished) {
  244. _isMoving = NO;
  245. [self moveViewWithX:0];
  246. }];
  247. } else {
  248. [UIView animateWithDuration:0.3 animations:^{
  249. [self moveViewWithX:0];
  250. } completion:^(BOOL finished) {
  251. _isMoving = NO;
  252. }];
  253. }
  254. return;
  255. } else if (recoginzer.state==UIGestureRecognizerStateCancelled){
  256. [UIView animateWithDuration:0.3 animations:^{
  257. [self moveViewWithX:0];
  258. } completion:^(BOOL finished) {
  259. _isMoving = NO;
  260. }];
  261. return;
  262. }else {
  263. }
  264. if (_isMoving) {
  265. [self moveViewWithX:touchPoint.x - startTouch.x];
  266. }
  267. }
  268. -(void)moveViewWithX:(float)x
  269. {
  270. CGRect rect = self.view.bounds;
  271. CGFloat width = CGRectGetWidth(rect);
  272. x = x>width?width:x;
  273. x = x<0?0:x;
  274. CGRect frame = self.webView.frame;
  275. frame.origin.x = x;
  276. self.webView.frame = frame;
  277. }
  278. - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
  279. // message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
  280. // NSLog(@"原生收到了js发送过来的消息message.name = %@ message.body = %@",message.name,message.body);
  281. if ([message.name isEqualToString:@"loginByWeixin"]) {
  282. [self jsLoginByWeixin:message.body];
  283. }else if ([message.name isEqualToString:@"share"]) {
  284. [self jsShare:message.body];
  285. }else if ([message.name isEqualToString:@"saveUserToken"]) {
  286. [self jsSaveUserToken:message.body];
  287. }else if ([message.name isEqualToString:@"removeUserToken"]) {
  288. [self jsRemoveUserToken:message.body];
  289. }else if ([message.name isEqualToString:@"openSystemNotification"]) {
  290. [self jsOpenSystemNotification:message.body];
  291. }else if ([message.name isEqualToString:@"openExternalLink"]) {
  292. [self JsOpenExternalLink:message.body];
  293. }else if ([message.name isEqualToString:@"alert"]) {
  294. [self jsAlert:message.body];
  295. }else if ([message.name isEqualToString:@"hiddenBottom"]) {
  296. [self jsHiddenBottom:message.body];
  297. }else if ([message.name isEqualToString:@"checkLab"]) {
  298. [self jsCheckLab:message.body];
  299. }else if ([message.name isEqualToString:@"loginSuccess"]) {
  300. [self jsLoginSuccess:message.body];
  301. }else if ([message.name isEqualToString:@"backUrl"]) {
  302. [self jsBackUrl:message.body];
  303. }else if ([message.name isEqualToString:@"clearPushMessage"]) {
  304. [self jsClearPushMessage:message.body];
  305. }else if ([message.name isEqualToString:@"hideRedSpotOnMenu"]) {
  306. [self jsHideRedSpotOnMenu:message.body];
  307. }else if ([message.name isEqualToString:@"showRedSpotOnMenu"]) {
  308. [self jsShowRedSpotOnMenu:message.body];
  309. }else if ([message.name isEqualToString:@"wxPay"]) {
  310. [self jsWxPay:message.body];
  311. }else if ([message.name isEqualToString:@"aliPay"]) {
  312. [self jsAliPay:message.body];
  313. }else if ([message.name isEqualToString:@"chooseTab"]) {
  314. [self jsChooseTab:message.body];
  315. }else if ([message.name isEqualToString:@"skipCameraWithParam"]) {
  316. [self jsSkipCameraWithParam:message.body];
  317. }else if ([message.name isEqualToString:@"skipAlbumWithParam"]) {
  318. [self jsSkipAlbumWithParam:message.body];
  319. }else if ([message.name isEqualToString:@"openActivityPage"]) {
  320. [self jsOpenActivityPage:message.body];
  321. }else if ([message.name isEqualToString:@"callPhone"]) {
  322. [self jsCallPhone:message.body];
  323. }else if ([message.name isEqualToString:@"openOtherAppLinks"]) {
  324. [self jsOpenOtherAppLinks:message.body];
  325. }else if ([message.name isEqualToString:@"inPurchasingVip"]) {
  326. [self jsInPurchasingVip:message.body];
  327. }else if ([message.name isEqualToString:@"wirteRight"]) {
  328. [self jsWirteRight:message.body];
  329. }else if ([message.name isEqualToString:@"clearRight"]) {
  330. [self jsClearRight:message.body];
  331. }else if ([message.name isEqualToString:@"savePic"]) {
  332. [self jsSavePic:message.body];
  333. }else if ([message.name isEqualToString:@"ocrVerifyService"]) {
  334. [self jsOcrVerifyService:message.body];
  335. }else if ([message.name isEqualToString:@"faceVerifyService"]) {
  336. [self jsFaceVerifyService:message.body];
  337. }else if ([message.name isEqualToString:@"skipAppointTab"]) {
  338. [self jsSkipAppointTab:message.body];
  339. }else if ([message.name isEqualToString:@"refreshAppointTab"]) {
  340. [self jsRefreshAppointTab:message.body];
  341. }else {
  342. }
  343. }
  344. #pragma mark - WKUIDelegate
  345. - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler
  346. {
  347. NSError *err = nil;
  348. NSData *dataFromString = [prompt dataUsingEncoding:NSUTF8StringEncoding];
  349. NSDictionary *paramdict = [NSJSONSerialization JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:&err];
  350. // NSLog(@"拦截prompt:%@",paramdict);
  351. if (!err){
  352. NSString *type = [paramdict objectForKey:@"jsName"];
  353. if (type && [type isEqualToString:@"getUserToken"]) {
  354. NSDictionary *dict = @{@"type":@"string",
  355. @"value":[self jsGetUserToken:paramdict]};
  356. completionHandler([self convertToJsonData:dict]);
  357. }else if (type && [type isEqualToString:@"getVersion"]) {
  358. NSDictionary *dict = @{@"type":@"string",
  359. @"value":[self jsGetVersion:paramdict]};
  360. completionHandler([self convertToJsonData:dict]);
  361. }else if (type && [type isEqualToString:@"checkNoticePermission"]) {
  362. NSDictionary *dict = @{@"type":@"int",
  363. @"value":[NSString stringWithFormat:@"%d",[self jsCheckNoticePermission:paramdict]]};
  364. completionHandler([self convertToJsonData:dict]);
  365. }else if (type && [type isEqualToString:@"getPushRid"]) {
  366. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetPushRid:paramdict]};
  367. completionHandler([self convertToJsonData:dict]);
  368. }else if (type && [type isEqualToString:@"isInstallWeixin"]) {
  369. NSDictionary *dict = @{@"type":@"int",
  370. @"value":[NSString stringWithFormat:@"%d",[self jsIsInstallWeixin:paramdict]]};
  371. completionHandler([self convertToJsonData:dict]);
  372. }else if (type && [type isEqualToString:@"getCipherText"]) {
  373. NSDictionary *dict = @{@"type":@"string",
  374. @"value":[self jsGetCipherText:paramdict]};
  375. completionHandler([self convertToJsonData:dict]);
  376. }
  377. else if (type && [type isEqualToString:@"getOtherPushRid"]) {
  378. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetOtherPushRid:paramdict]};
  379. completionHandler([self convertToJsonData:dict]);
  380. }else if (type && [type isEqualToString:@"getPhoneBrand"]) {
  381. NSDictionary *dict = @{@"type":@"string",
  382. @"value":[self jsGetPhoneBrand:paramdict]};
  383. completionHandler([self convertToJsonData:dict]);
  384. }else if (type && [type isEqualToString:@"getLocation"]) {
  385. NSDictionary *dict = @{@"type":@"string",
  386. @"value":[self jsGetLocation:paramdict]};
  387. completionHandler([self convertToJsonData:dict]);
  388. }else if (type && [type isEqualToString:@"readRight"]) {
  389. NSDictionary *dict = @{@"type":@"string",
  390. @"value":[self jsReadRight:paramdict]};
  391. completionHandler([self convertToJsonData:dict]);
  392. }else {
  393. completionHandler(@"");
  394. }
  395. }
  396. }
  397. // 在发送请求之前,决定是否跳转
  398. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  399. //如果当前页面是三级页面-
  400. NSString *curUrl = [webView.URL absoluteString];
  401. if ([curUrl containsString:@"jyapp/article/content"]) {
  402. //当前页面是三级页面--判断待跳转页面是否符合内置跳转
  403. NSString *nextUrl = [navigationAction.request.URL absoluteString];
  404. if ([nextUrl containsString:@"jianyu360.com"]||[nextUrl containsString:@"jianyu360.cn"]||[nextUrl containsString:@"qmx.top"]) {
  405. // 允许跳转
  406. decisionHandler(WKNavigationActionPolicyAllow);
  407. }else {
  408. NSLog(@"不允许内部跳转:-%@",nextUrl);
  409. //筛选拦截-压缩包等格式不允许跳转
  410. if ([nextUrl hasSuffix:@".rar"]||[nextUrl hasSuffix:@".zip"]||[nextUrl hasSuffix:@".7z"]||[nextUrl hasSuffix:@".CAB"]||[nextUrl hasSuffix:@".ARJ"]||[nextUrl hasSuffix:@".LZH"]||[nextUrl hasSuffix:@".TAR"]||[nextUrl hasSuffix:@".GZ"]||[nextUrl hasSuffix:@".ACE"]||[nextUrl hasSuffix:@".UUE"]||[nextUrl hasSuffix:@".BZ2"]||[nextUrl hasSuffix:@".JAR"]||[nextUrl hasSuffix:@".ISO"]) {
  411. // 不允许跳转
  412. decisionHandler(WKNavigationActionPolicyCancel);
  413. }else {
  414. JYWKNewWebController *ctr = [[JYWKNewWebController alloc] init];
  415. ctr.url = nextUrl;
  416. ctr.titleShow = @"公告信息";
  417. kMainQueue(^{
  418. [self presentViewController:ctr animated:NO completion:nil];
  419. });
  420. // 不允许跳转-并跳转新页面
  421. decisionHandler(WKNavigationActionPolicyCancel);
  422. }
  423. }
  424. }else if ([curUrl containsString:@"apps.apple.com"]&&[curUrl containsString:@"1354897149"]){
  425. [[UIApplication sharedApplication] openURL:[NSURL URLWithString: curUrl]];
  426. decisionHandler(WKNavigationActionPolicyCancel);
  427. }else {
  428. // 允许跳转
  429. decisionHandler(WKNavigationActionPolicyAllow);
  430. }
  431. }
  432. #pragma mark ****WKUIDelegate
  433. //通过js alert 显示一个警告面板,调用原生会走此方法。
  434. - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
  435. {
  436. // NSLog(@"显示一个JavaScript警告面板, message = %@",message);
  437. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  438. [alertController addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  439. completionHandler();
  440. }]];
  441. [self presentViewController:alertController animated:YES completion:nil];
  442. }
  443. //通过 js confirm 显示一个确认面板,调用原生会走此方法。
  444. - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler
  445. {
  446. // NSLog(@"运行JavaScript确认面板, message = %@", message);
  447. UIAlertController *action = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  448. [action addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  449. completionHandler(NO);
  450. }] ];
  451. [action addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  452. completionHandler(YES);
  453. }]];
  454. [self presentViewController:action animated:YES completion:nil];
  455. }
  456. #pragma mark - OC调JS交互
  457. -(void)isExitCallToJS:(NSString *)jsStr withMethodName:(NSString *)name{
  458. NSString *jsName = [NSString stringWithFormat:@"function exist(){return !window['%@']};exist()",name];
  459. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  460. WeakSelf;
  461. [_webView evaluateJavaScript:jsName completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  462. // NSLog(@"是否存在 result:%@,error:%@",result,error);
  463. if ([result intValue]==0) {
  464. [weakSelf executeCallJS:jsStr];
  465. }else {
  466. NSLog(@"不存在-不存在-不存在-%@",jsStr);
  467. }
  468. }];
  469. });
  470. }
  471. -(void)executeCallJS:(NSString *)jsStr {
  472. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  473. [_webView evaluateJavaScript:jsStr completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  474. if (error!=nil) {
  475. }
  476. }];
  477. });
  478. }
  479. - (void)viewDidLoad {
  480. [super viewDidLoad];
  481. // Do any additional setup after loading the view.
  482. NSLog(@"首页初始化");
  483. self.view.backgroundColor = [UIColor whiteColor];
  484. [self.view addSubview:self.webView];
  485. [self.view addSubview:self.progressView];
  486. [self webViewFirstRequest];
  487. [[AFNetworkReachabilityManager sharedManager] startMonitoring];
  488. [self initNotification];
  489. self.recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)];
  490. [self.recognizer delaysTouchesBegan];
  491. [self.view addGestureRecognizer:self.recognizer];
  492. //初始化临时属性
  493. self.placeAdr = [NSString new];
  494. //定时器-检测错误数据是否超过10个 发送
  495. [NSTimer scheduledTimerWithTimeInterval:180 target:self selector:@selector(errorLogListening) userInfo:nil repeats:YES];
  496. //监听底部栏
  497. [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(bottomOneListening) userInfo:nil repeats:YES];
  498. //监听购买结果
  499. [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
  500. }
  501. //-(void)btn1click{
  502. //
  503. // NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code ", @"public.image", @"public.audiovisual-content", @"com.adobe.pdf", @"com.apple.keynote.key", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt"];
  504. //
  505. // UIDocumentPickerViewController *documentPickerViewController = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes
  506. // inMode:UIDocumentPickerModeOpen];
  507. // documentPickerViewController.delegate = self;
  508. // [self presentViewController:documentPickerViewController animated:YES completion:nil];
  509. //}
  510. //#pragma mark - UIDocumentPickerDelegate
  511. //
  512. //- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
  513. //
  514. // NSArray *array = [[url absoluteString] componentsSeparatedByString:@"/"];
  515. // NSString *fileName = [array lastObject];
  516. // fileName = [fileName stringByRemovingPercentEncoding];
  517. // NSLog(@"%@",fileName);
  518. // if ([iCloudManager iCloudEnable]) {
  519. // [iCloudManager downloadWithDocumentURL:url callBack:^(id obj) {
  520. // NSLog(@"选择文件");
  521. //// NSData *data = obj;
  522. // //上传
  523. //// //写入沙盒Documents
  524. //// NSString *filePath = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@",fileName]];
  525. //// [data writeToFile:filePath atomically:YES];
  526. ////
  527. //// NSLog(@"%@",filePath);
  528. //
  529. //// NSArray *arr = [filePath componentsSeparatedByString:@"."];
  530. //// NSString *smallString = [[arr lastObject] lowercaseString];
  531. //// NSLog(@"%@",smallString);
  532. // }];
  533. // }
  534. //}
  535. -(void)bottomOneListening {
  536. //临时添加提示框
  537. // NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  538. // NSArray * array = [current_url componentsSeparatedByString:kHost];
  539. // current_url = [array.lastObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  540. // [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:current_url delay:2];
  541. if(self.tabBarController.selectedIndex == 0) {
  542. [self judgeIsHiddenBottom];
  543. }
  544. }
  545. - (BOOL)isTheCurrentPeriod{
  546. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  547. NSDate *now = [NSDate date];
  548. NSDateComponents *comps = [[NSDateComponents alloc] init];
  549. NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
  550. comps = [calendar components:unitFlags fromDate:now];
  551. long hour = (long)[comps hour];
  552. if (hour>=12&&hour<14) {
  553. return YES;
  554. }
  555. if (hour>=17&&hour<=23) {
  556. return YES;
  557. }
  558. if (hour>=0&&hour<7) {
  559. return YES;
  560. }
  561. return NO;
  562. }
  563. - (NSString *)toJsonStrWithArray:(NSArray *)arr {
  564. if ([arr isKindOfClass:[NSString class]]) {
  565. return (NSString *)arr;
  566. }
  567. NSError *parseError = nil;
  568. NSData *data = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:nil];
  569. NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  570. jsonStr = [jsonStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  571. jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@" " withString:@""];
  572. jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  573. if (parseError) {
  574. jsonStr = @"";
  575. }
  576. return jsonStr;
  577. }
  578. -(void)errorLogListening {
  579. if ([self isTheCurrentPeriod]) {
  580. if ([[GlobalData shareInstance] getPlistCount]>=50) {
  581. NSMutableDictionary *dict =[[GlobalData shareInstance] getPlistAllData];
  582. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/errLogs/Receive",kHost] parameters:@{@"jsonData":[self toJsonStrWithArray:dict[@"jsonData"]]} progress:^(NSProgress *progress) {
  583. NSLog(@"%@",progress);
  584. } success:^(id responseObject) {
  585. NSLog(@"responseObject=%@",responseObject);
  586. [[GlobalData shareInstance] clearPlistData];
  587. } failure:^(NSError *error) {
  588. NSLog(@"error=%@",error);
  589. [[GlobalData shareInstance] addOnePlistData:@{
  590. @"detail":[NSString stringWithFormat:@"上传日志接口:%@",[error description]],
  591. @"reqTime":[NSNumber numberWithInt:0],
  592. }];
  593. }];
  594. }
  595. }else {
  596. }
  597. }
  598. -(void)haveRedPoint
  599. {
  600. NSLog(@"http请求-------小红点");
  601. NSString *token = [LXUserDefaults token];
  602. if ([LXUserDefaults isExistToken]) {
  603. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/showRedSpotOnMenu",kHost] parameters:@{@"token":token} progress:^(NSProgress *progress) {
  604. // NSLog(@"%@",progress);
  605. } success:^(id responseObject) {
  606. // NSLog(@"responseObject=%@",responseObject);
  607. if([responseObject[@"subscribe"] integerValue]>=1) {
  608. //显示
  609. [GlobalData shareInstance].subIsRed = YES;
  610. kMainQueue(^{
  611. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  612. });
  613. }else {
  614. [GlobalData shareInstance].subIsRed = NO;
  615. kMainQueue(^{
  616. [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
  617. });
  618. }
  619. if([responseObject[@"my"] integerValue]>=1) {
  620. //显示
  621. [GlobalData shareInstance].mineIsRed = YES;
  622. kMainQueue(^{
  623. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  624. });
  625. }else {
  626. [GlobalData shareInstance].mineIsRed = NO;
  627. kMainQueue(^{
  628. [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  629. });
  630. }
  631. } failure:^(NSError *error) {
  632. NSLog(@"error=%@",error);
  633. [[GlobalData shareInstance] addOnePlistData:@{
  634. @"detail":[NSString stringWithFormat:@"获取小红点接口:%@",[error description]],
  635. @"reqTime":[NSNumber numberWithInt:0],
  636. }];
  637. }];
  638. }
  639. }
  640. #pragma mark - WKNavigationDelegate
  641. /* 页面加载完成 */
  642. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
  643. NSLog(@"-----页面加载完成%@",webView.URL.absoluteString);
  644. if (![GlobalData shareInstance].isSearchToLoad) {
  645. [GlobalData shareInstance].isSearchToLoad = YES;
  646. }
  647. //第一次加载小红点
  648. if(!isLoadRedDot) {
  649. isLoadRedDot = true;
  650. [self haveRedPoint];
  651. }
  652. [self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
  653. [self.webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';"completionHandler:nil];
  654. [self judgeIsHiddenBottom];//是否隐藏
  655. [self removeNoNetViews];
  656. [self removeFailNetViews];
  657. [[LXViewControllerManager shareViewControllerManager] hideHud];
  658. //写数据
  659. // [self writeWKWebData:webView.URL];
  660. if (![GlobalData shareInstance].isOpen) {//第一次打开
  661. [GlobalData shareInstance].isOpen = YES;
  662. [self performSelector:@selector(pasteboard) withObject:nil afterDelay:1.5];
  663. }
  664. }
  665. -(void)pasteboard {
  666. NSString *content = [UIPasteboard generalPasteboard].string;
  667. if ([content containsString:@"剑鱼标讯"]) {//第一次打开页面时候
  668. [[NSNotificationCenter defaultCenter] postNotificationName:UpdateClipboard object:nil userInfo:@{@"content":content}];
  669. }
  670. }
  671. -(void)writeWKWebData:(NSURL *)url {
  672. //得到NSData 数据
  673. NSData *dataContent = [NSData dataWithContentsOfURL:url];
  674. //NSURLCache 实例化
  675. NSURLCache *cache = [NSURLCache sharedURLCache];
  676. //得到相应
  677. NSURLResponse *response = [[NSURLResponse alloc]initWithURL:url MIMEType:nil expectedContentLength:0 textEncodingName:@"UTF-8"];
  678. //得到CacheURLResponse
  679. NSCachedURLResponse *cacheResponse = [[NSCachedURLResponse alloc]initWithResponse:response data:dataContent];
  680. //进行存储
  681. [cache storeCachedResponse:cacheResponse forRequest:[NSURLRequest requestWithURL:url]];
  682. }
  683. // 页面开始加载时调用
  684. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
  685. self.recognizer.enabled = NO;
  686. }
  687. // 当内容开始返回时调用
  688. - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
  689. }
  690. // 页面加载失败时调用
  691. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(nonnull NSError *)error{
  692. //加载失败 有网络-弹出页面 , 无网络-记录标记
  693. if ([ZKMethod judegeNetworkIsAvailable]) {
  694. //弹出页面
  695. NSLog(@"页面加载失败-有网络");
  696. if (!self.isRuningLoad) {
  697. [self addFailNetViews];
  698. }
  699. }else {
  700. //记录标记
  701. NSLog(@"页面加载失败-无网络");
  702. isExistNoNewWork = YES;
  703. }
  704. self.recognizer.enabled = YES;
  705. }
  706. #pragma mark *****JS与OC交互
  707. #pragma mark - WKScriptMessageHandler JS调OC交互
  708. -(void)jsLoginByWeixin:(NSDictionary *)dict {
  709. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装微信 不走友盟
  710. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"微信登录失败,没有安装微信" delay:1.5];
  711. return;
  712. }
  713. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
  714. UMSocialUserInfoResponse *resp = result;
  715. [self dealWXDic:(NSDictionary *)resp.originalResponse];
  716. }];
  717. }
  718. // 处理微信登录获取到的数据
  719. -(void)dealWXDic:(NSDictionary *)dictionary{
  720. //如果获取到用户信息,即用户点击了“登录”,则进行用户信息获取
  721. if (dictionary.count > 0) {
  722. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dictionary];
  723. if (dic) {
  724. [dic removeObjectForKey:@"privilege"];
  725. [dic removeObjectForKey:@"language"];
  726. double currDouble = [[NSDate date] timeIntervalSince1970];
  727. [dic setObject:[NSNumber numberWithLong:(long)currDouble] forKey:@"createtime"];
  728. // 拼接标志位
  729. 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"]];
  730. sign = [LXMD5 md532BitLower:sign];
  731. [dic setObject:sign forKey:@"sign"];
  732. NSString *endStr = [[LXViewControllerManager shareViewControllerManager] getJsonStr:dic];
  733. NSData *data = [endStr dataUsingEncoding:NSUTF8StringEncoding];
  734. endStr = [data base64EncodedStringWithOptions:0];
  735. [self isExitCallToJS:[NSString stringWithFormat:@"loginByWeixinCallBack('%@')", endStr] withMethodName:@"loginByWeixinCallBack"];
  736. }
  737. }
  738. }
  739. -(void)jsShare:(NSDictionary *)dict {
  740. NSString *type = [NSString stringWithFormat:@"%@",dict[@"type"]];
  741. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  742. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  743. NSString *link = [NSString stringWithFormat:@"%@",dict[@"link"]];
  744. UMSocialPlatformType shareType;
  745. if ([type intValue] == 1) { // 微信好友
  746. shareType = UMSocialPlatformType_WechatSession;
  747. }else if ([type intValue] == 2){ /// qq好友
  748. shareType = UMSocialPlatformType_QQ;
  749. }else if ([type intValue] == 3){ // 朋友圈
  750. shareType = UMSocialPlatformType_WechatTimeLine;
  751. }else{
  752. shareType = UMSocialPlatformType_WechatSession;
  753. }
  754. if ([type intValue] == 1 || [type intValue] == 3) {
  755. if ([LXUserDefaults isInstallWeiXin] != 1) {
  756. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装微信" delay:1.5];
  757. return;
  758. }
  759. }
  760. if ([type intValue] == 2) {
  761. if (![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ]) {
  762. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装QQ" delay:1.5];
  763. return;
  764. }
  765. }
  766. //创建分享消息对象
  767. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  768. //创建网页内容对象
  769. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:content thumImage:[UIImage imageNamed:@"logo"]];
  770. //设置网页地址
  771. shareObject.webpageUrl = link;
  772. messageObject.shareObject = shareObject;
  773. //调用分享接口
  774. [[UMSocialManager defaultManager] shareToPlatform:shareType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  775. if (error) {
  776. if (error.userInfo[@"message"] && [error.userInfo[@"message"] containsString:@"Operation is cancel"]) {
  777. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"取消分享" delay:1];
  778. }else{
  779. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:error.userInfo[@"message"] delay:1];
  780. }
  781. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"0"] withMethodName:@"shareCallBack"];
  782. }else{
  783. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  784. [self isExitCallToJS:[NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"1"] withMethodName:@"shareCallBack"];
  785. }else{
  786. UMSocialLogInfo(@"response data is %@",data);
  787. }
  788. }
  789. }];
  790. }
  791. -(void)jsSaveUserToken:(NSDictionary *)dict{
  792. [LXUserDefaults saveToken:[NSString stringWithFormat:@"%@",dict[@"token"]]];
  793. }
  794. -(NSString *)jsGetUserToken:(NSDictionary *)dict{
  795. return [LXUserDefaults token];
  796. }
  797. -(void)jsRemoveUserToken:(NSDictionary *)dict{
  798. [LXUserDefaults clearAll];
  799. }
  800. -(int)jsCheckNoticePermission:(NSDictionary *)dict{
  801. return [LXUserDefaults notifyState];
  802. }
  803. // 跳转到系统设置
  804. -(void)jsOpenSystemNotification:(NSDictionary *)dict{
  805. self.updateNotify = YES;
  806. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  807. }
  808. // 获取推送id
  809. -(NSString *)jsGetPushRid:(NSDictionary *)dict{
  810. return [LXUserDefaults grpcPushID];
  811. }
  812. // 打开新页面 加载新web
  813. -(void)JsOpenExternalLink:(NSDictionary *)dict{
  814. NSString *url = [NSString stringWithFormat:@"%@",dict[@"url"]];
  815. NSString *title = [NSString stringWithFormat:@"%@",dict[@"title"]];
  816. if (url) {
  817. if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable || [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown) {
  818. }
  819. JYWKNewWebController *ctr = [[JYWKNewWebController alloc] init];
  820. ctr.url = url;
  821. if (!title || [title isEqualToString:@""] || [title isEqualToString:@"undefined"]) {
  822. ctr.titleShow = nil;
  823. }else{
  824. ctr.titleShow = title;
  825. }
  826. kMainQueue(^{
  827. [self presentViewController:ctr animated:NO completion:nil];
  828. });
  829. }
  830. }
  831. // 获取当前版本号
  832. -(NSString *)jsGetVersion:(NSDictionary *)dict{
  833. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  834. }
  835. -(void)jsAlert:(NSDictionary *)dict{
  836. [[LXViewControllerManager shareViewControllerManager] showAlertViewWithMessage:[NSString stringWithFormat:@"%@",dict[@"content"]]];
  837. }
  838. -(int)jsIsInstallWeixin:(NSDictionary *)dict{
  839. return [LXUserDefaults isInstallWeiXin];
  840. }
  841. -(NSString *)jsGetCipherText:(NSDictionary *)dict{
  842. NSDictionary *objDict = [NSDictionary dictionaryWithDictionary:dict[@"arguments"]];
  843. NSString *phone = [NSString stringWithFormat:@"%@",objDict[@"phone"]];
  844. NSDate *date=[NSDate date];
  845. NSDateFormatter *format1=[[NSDateFormatter alloc] init];
  846. [format1 setDateFormat:@"yyyyMMddhhmmss"];
  847. NSString *dateStr;
  848. dateStr=[format1 stringFromDate:date];
  849. NSLog(@"%@",dateStr);
  850. NSString *content = [[NSString stringWithFormat:@"%@_%@",phone,dateStr] stringByAppendingString:[NSString stringWithFormat:@"_%@",[LXMD5 md532BitLower:[NSString stringWithFormat:@"%@&%@",phone,dateStr]]]];
  851. NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
  852. NSUInteger dataLength = contentData.length;
  853. // 为结束符'\\0' +1
  854. char keyPtr[new_kKeySize_1 + 1];
  855. memset(keyPtr, 0, sizeof(keyPtr));
  856. [new_AesKey_1 getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
  857. // 密文长度 <= 明文长度 + BlockSize
  858. size_t encryptSize = dataLength + kCCBlockSizeAES128;
  859. void *encryptedBytes = malloc(encryptSize);
  860. size_t actualOutSize = 0;
  861. NSData *initVector = [new_kInitVector_1 dataUsingEncoding:NSUTF8StringEncoding];
  862. CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
  863. kCCAlgorithmAES,
  864. kCCOptionPKCS7Padding, // 系统默认使用 CBC,然后指明使用 PKCS7Padding
  865. keyPtr,
  866. new_kKeySize_1,
  867. initVector.bytes,
  868. contentData.bytes,
  869. dataLength,
  870. encryptedBytes,
  871. encryptSize,
  872. &actualOutSize);
  873. if (cryptStatus == kCCSuccess) {
  874. // 对加密后的数据进行 base64 编码
  875. return [[NSData dataWithBytesNoCopy:encryptedBytes length:actualOutSize] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  876. }
  877. free(encryptedBytes);
  878. return nil;
  879. }
  880. -(void)jsHiddenBottom:(NSDictionary *)dict{
  881. if(self.tabBarController.selectedIndex == 0) {
  882. if([[NSString stringWithFormat:@"%@",dict[@"hidden"]] integerValue]==0) {
  883. [self hideTabBar];
  884. [self hiddenMethodTabBar];
  885. }else {
  886. [self showTabBar];
  887. [self showMethodTabBar];
  888. }
  889. }
  890. }
  891. -(void)jsCheckLab:(NSDictionary *)dict {
  892. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshNonCurVC object:nil userInfo:nil];
  893. }
  894. //js方法登录成功
  895. -(void)jsLoginSuccess:(NSDictionary *)dict {
  896. NSLog(@"search登录成功提示:%@",dict);
  897. NSString *status = [NSString stringWithFormat:@"%@",dict[@"status"]];
  898. [GlobalData shareInstance].isReLogin = YES;
  899. if([status isEqualToString:@"S"]) {
  900. if(pushIndex!=0) {
  901. kMainQueue((^{
  902. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshAllVC object:nil userInfo:nil];
  903. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  904. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  905. tab.selectedIndex = pushIndex;
  906. pushIndex = 0;
  907. }));
  908. }else {
  909. [self webViewFirstRequest];
  910. }
  911. }else if ([status isEqualToString:@""]) {
  912. //不刷新订阅-首页,刷新其他
  913. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshExpAndMine object:nil userInfo:nil];
  914. }else {
  915. }
  916. //弹出页面
  917. if ([GlobalData shareInstance].isPasteLogin) {
  918. [GlobalData shareInstance].isPasteLogin = NO;
  919. NSString *content = [UIPasteboard generalPasteboard].string;
  920. [self popPasteVIew:content];
  921. }
  922. }
  923. -(void)jsBackUrl:(NSDictionary *)dict {
  924. NSString *status = [NSString stringWithFormat:@"%@",dict[@"status"]];
  925. if([status isEqualToString:@"H"]) {
  926. pushIndex = 0;
  927. [self webViewFirstRequest];
  928. }
  929. }
  930. -(void)jsClearPushMessage:(NSDictionary *)dict {
  931. kMainQueue(^{
  932. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
  933. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  934. });
  935. }
  936. -(void)jsHideRedSpotOnMenu:(NSDictionary *)dict {
  937. NSString *menu = [NSString stringWithFormat:@"%@",dict[@"menu"]];
  938. if([menu isEqualToString:@"subscribe"]) {
  939. kMainQueue(^{
  940. [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
  941. });
  942. }
  943. if([menu isEqualToString:@"my"]) {
  944. kMainQueue(^{
  945. [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  946. });
  947. }
  948. }
  949. -(void)jsShowRedSpotOnMenu:(NSDictionary *)dict {
  950. NSString *menu = [NSString stringWithFormat:@"%@",dict[@"menu"]];
  951. if([menu isEqualToString:@"subscribe"]) {
  952. kMainQueue(^{
  953. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  954. });
  955. }
  956. if([menu isEqualToString:@"my"]) {
  957. kMainQueue(^{
  958. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  959. });
  960. }
  961. }
  962. -(void)jsWxPay:(NSDictionary *)dict {
  963. if (![LXUserDefaults isInstallWeiXin]) { [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先安装微信再进行支付!" delay:1.5];
  964. return;
  965. }
  966. NSString *jsonString = [NSString stringWithFormat:@"%@",dict[@"order"]];
  967. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  968. NSError *err;
  969. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
  970. if(err) {
  971. NSLog(@"json解析失败:%@",err);
  972. return;
  973. }
  974. //吊起微信
  975. PayReq *request = [[PayReq alloc] init] ;
  976. request.openID = dic[@"Appid"];
  977. request.partnerId = dic[@"Partnerid"];
  978. request.prepayId= dic[@"Prepayid"];
  979. request.package = @"Sign=WXPay";
  980. request.nonceStr= dic[@"Noncestr"];
  981. request.timeStamp= [dic[@"Timestamp"] intValue];
  982. request.sign= dic[@"Sign"];
  983. kMainQueue(^{
  984. [WXApi sendReq:request];
  985. });
  986. }
  987. -(void)jsAliPay:(NSDictionary *)dict {
  988. if (![LXUserDefaults isInstallAli]) {
  989. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先安装支付宝再进行支付!" delay:1.5];
  990. return;
  991. }
  992. NSString *order = [NSString stringWithFormat:@"%@",dict[@"order"]];
  993. kMainQueue(^{
  994. [[AlipaySDK defaultService] payOrder:order fromScheme:@"jianyuiosapp" callback:nil];
  995. });
  996. }
  997. -(NSString *)jsGetOtherPushRid:(NSDictionary *)dict {
  998. return [LXUserDefaults deviceToken];
  999. }
  1000. -(NSString *)jsGetPhoneBrand:(NSDictionary *)dict {
  1001. UIDevice *device = [UIDevice currentDevice];
  1002. return device.platformString;
  1003. }
  1004. -(NSString *)jsGetLocation:(NSDictionary *)dict {
  1005. // NSLog(@"------开始调用获取位置:%@",self.placeAdr);
  1006. if (!self.isLocation) {
  1007. // 1.检查定位服务是否开启
  1008. if ([self checkLocationServiceIsEnabled]) {
  1009. // 2.创建定位管理器:
  1010. NSLog(@"定位可用");
  1011. [self createCLManager];
  1012. self.isLocation = YES; //只请求一次
  1013. }else{
  1014. NSLog(@"定位不可用");
  1015. self.isLocation = NO;
  1016. }
  1017. NSLog(@"即将返回城市信息-%@",self.placeAdr);
  1018. }
  1019. return self.placeAdr;
  1020. }
  1021. -(void)jsChooseTab:(NSDictionary *)dict {
  1022. NSInteger indexTab = [dict[@"indexTab"] integerValue];
  1023. kMainQueue((^{
  1024. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1025. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  1026. tab.selectedIndex = indexTab;
  1027. pushIndex = indexTab;
  1028. }));
  1029. }
  1030. //拍照上传图片
  1031. -(void)jsSkipCameraWithParam:(NSDictionary *)dict {
  1032. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  1033. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  1034. picker.delegate = self;
  1035. picker.allowsEditing = YES;
  1036. picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  1037. dispatch_async(dispatch_get_main_queue(), ^{
  1038. [self presentViewController:picker animated:YES completion:nil];
  1039. });
  1040. }
  1041. //相册选择照片
  1042. -(void)jsSkipAlbumWithParam:(NSDictionary *)dict {
  1043. [GlobalData shareInstance].isSkipPath = [NSString stringWithFormat:@"%@",dict[@"type"]];
  1044. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  1045. picker.delegate = self;
  1046. picker.allowsEditing = YES;
  1047. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  1048. dispatch_async(dispatch_get_main_queue(), ^{
  1049. [self presentViewController:picker animated:YES completion:nil];
  1050. });
  1051. }
  1052. //统计点击推送
  1053. -(void)jsOpenActivityPage:(NSDictionary *)dict {
  1054. NSDictionary * infoDic = @{@"url":[NSString stringWithFormat:@"%@",dict[@"url"]],
  1055. @"rectype":[NSString stringWithFormat:@"%@",dict[@"rectype"]],
  1056. @"openid":[NSString stringWithFormat:@"%@",dict[@"openid"]],
  1057. };
  1058. //post请求
  1059. NSLog(@"%@",[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost]);
  1060. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost] parameters:infoDic progress:^(NSProgress *progress) {
  1061. NSLog(@"成功:%@",progress);
  1062. } success:^(id responseObject) {
  1063. NSLog(@"responseObject=%@",responseObject);
  1064. } failure:^(NSError *error) {
  1065. NSLog(@"error=%@",error);
  1066. [[GlobalData shareInstance] addOnePlistData:@{
  1067. @"detail":[NSString stringWithFormat:@"message/receive接口:%@",[error description]],
  1068. @"reqTime":[NSNumber numberWithInt:0],
  1069. }];
  1070. }];
  1071. }
  1072. //拨打电话
  1073. -(void)jsCallPhone:(NSDictionary *)dict {
  1074. NSString *phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
  1075. NSMutableString *tel = [[NSMutableString alloc]initWithFormat:@"telprompt://%@",phone];
  1076. if (@available(iOS 10.0, *)) {
  1077. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel] options:@{} completionHandler:^(BOOL success) {
  1078. }];
  1079. } else {
  1080. // Fallback on earlier versions
  1081. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
  1082. }
  1083. }
  1084. //打开其他app 抖音+快手
  1085. -(void)jsOpenOtherAppLinks:(NSDictionary *)dict {
  1086. //测试跳转抖音--快手 @"gifshow://" @"snssdk1128://"
  1087. NSString *appLink = [NSString stringWithFormat:@"%@",dict[@"appLink"]];
  1088. NSString *appName = [NSString stringWithFormat:@"%@",dict[@"appName"]];
  1089. NSLog(@"appName:%@",appName);
  1090. NSURL *url = [NSURL URLWithString:appLink];
  1091. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  1092. if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
  1093. //iOS 10.0+
  1094. NSLog(@"iOS 10+");
  1095. if (@available(iOS 10.0, *)) {
  1096. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  1097. if (!success) {
  1098. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  1099. }
  1100. }];
  1101. } else {
  1102. // Fallback on earlier versions
  1103. [[UIApplication sharedApplication] openURL:url];
  1104. }
  1105. }else{
  1106. NSLog(@"iOS 2~10");
  1107. //iOS 2~10
  1108. [[UIApplication sharedApplication] openURL:url];
  1109. }
  1110. }else{
  1111. //一般是没有安装
  1112. NSLog(@"跳转下载app链接");
  1113. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:appName delay:2];
  1114. }
  1115. }
  1116. #pragma mark *****人脸核身
  1117. //ocr验证
  1118. -(void)jsOcrVerifyService:(NSDictionary *)dict{
  1119. NSLog(@"ocr:%@",dict);
  1120. NSString *orderNo = [NSString stringWithFormat:@"%@",dict[@"orderNo"]];
  1121. NSString *nonce = [NSString stringWithFormat:@"%@",dict[@"nonce"]];
  1122. NSString *userId = [NSString stringWithFormat:@"%@",dict[@"userId"]];
  1123. NSString *sign = [NSString stringWithFormat:@"%@",dict[@"sign"]];
  1124. kMainQueue((^{
  1125. WBOCRConfig *config = [WBOCRConfig sharedConfig];
  1126. config.needRecordVideo = NO;
  1127. config.SDKType = WBOCRSDKTypeIDCardNormal; // 身份证两面识别
  1128. [[WBOCRService sharedService] startOCRServiceWithConfig:config version:@"1.0.0" appId:OCRAPPID nonce:nonce userId:userId sign:sign orderNo:orderNo startSucceed:^{
  1129. /** SDK服务拉起成功回调 */
  1130. NSLog(@"启动SDK成功!!!");
  1131. } recognizeSucceed:^(id _Nonnull resultModel, id _Nullable extension) {
  1132. /** SDK本次识别成功回调 */
  1133. NSLog(@"SDK识别成功!!!");
  1134. //调用js - 告知成功
  1135. NSString *textJS = [NSString stringWithFormat:@"ocrVerifyResult('%@')",orderNo];
  1136. [self isExitCallToJS:textJS withMethodName:@"ocrVerifyResult"];
  1137. } failed:^(NSError * _Nonnull error, id _Nullable extension) {
  1138. /** SDK异常回调 */
  1139. NSLog(@"识别出错!!!"); //200101 用户取消操作
  1140. //弹出页面
  1141. if (error.code == 200101) {
  1142. self.verifyMsgView.descTitle = @"您取消了身份验证";
  1143. }else {
  1144. self.verifyMsgView.descTitle = @"身份验证失败";
  1145. }
  1146. [self.verifyMsgView show];
  1147. NSString *textJS = [NSString stringWithFormat:@"ocrVerifyResult('%@')",@""];
  1148. [self isExitCallToJS:textJS withMethodName:@"ocrVerifyResult"];
  1149. }];
  1150. }));
  1151. }
  1152. //人脸核身
  1153. -(void)jsFaceVerifyService:(NSDictionary *)dict {
  1154. NSLog(@"face:%@",dict);
  1155. NSString *orderNo = [NSString stringWithFormat:@"%@",dict[@"orderNo"]];
  1156. NSString *nonce = [NSString stringWithFormat:@"%@",dict[@"nonce"]];
  1157. NSString *userId = [NSString stringWithFormat:@"%@",dict[@"userId"]];
  1158. NSString *sign = [NSString stringWithFormat:@"%@",dict[@"sign"]];
  1159. NSString *faceId = [NSString stringWithFormat:@"%@",dict[@"faceId"]];
  1160. kMainQueue((^{
  1161. [WBFaceVerifyCustomerService sharedInstance].delegate = self;
  1162. WBFaceVerifySDKConfig *config = [WBFaceVerifySDKConfig sdkConfig];
  1163. config.recordVideo = NO;
  1164. config.theme = WBFaceVerifyThemeDarkness;
  1165. [[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:^{
  1166. } failure:^(WBFaceError * _Nonnull error) {
  1167. }];
  1168. }));
  1169. }
  1170. #pragma mark - WBFaceVerifyCustomerServiceDelegate
  1171. -(void)wbfaceVerifyCustomerServiceDidFinishedWithFaceVerifyResult:(WBFaceVerifyResult *)faceVerifyResult{
  1172. if (faceVerifyResult.isSuccess) {
  1173. NSLog(@"活体检测成功:%@",faceVerifyResult.orderNo);
  1174. NSString *textJS = [NSString stringWithFormat:@"faceVerifyResult('%@')",faceVerifyResult.orderNo];
  1175. [self isExitCallToJS:textJS withMethodName:@"faceVerifyResult"];
  1176. self.verifyMsgView.descTitle = @"活体检测成功";
  1177. [self.verifyMsgView show];
  1178. }else {
  1179. NSLog(@"活体检测失败");
  1180. self.verifyMsgView.descTitle = @"活体检测失败";
  1181. [self.verifyMsgView show];
  1182. NSString *textJS = [NSString stringWithFormat:@"faceVerifyResult('%@')",@""];
  1183. [self isExitCallToJS:textJS withMethodName:@"faceVerifyResult"];
  1184. }
  1185. }
  1186. //保存图片到相册
  1187. #pragma mark 保存图片
  1188. -(void)jsSavePic:(NSDictionary *)dict {
  1189. NSString *base64ImgData = [NSString stringWithFormat:@"%@",dict[@"imgbase64"]];
  1190. base64ImgData = [base64ImgData stringByReplacingOccurrencesOfString:@"data:image/png;base64," withString:@""];
  1191. NSData *data = [[NSData alloc]initWithBase64EncodedString:base64ImgData options:NSDataBase64DecodingIgnoreUnknownCharacters];
  1192. UIImage *saveImg = [UIImage imageWithData:data];
  1193. UIImageWriteToSavedPhotosAlbum(saveImg, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
  1194. }
  1195. #pragma mark 系统的完成保存图片的方法
  1196. - (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
  1197. {
  1198. NSString *msg = nil ;
  1199. if (error != NULL) {
  1200. msg = @"保存图片失败" ;
  1201. } else {
  1202. msg = @"保存图片成功" ;
  1203. }
  1204. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:msg delay:1];
  1205. }
  1206. #pragma mark 粘贴板
  1207. -(void)jsWirteRight:(NSDictionary *)dict {
  1208. NSString *txt = [NSString stringWithFormat:@"%@",dict[@"txt"]];
  1209. [[UIPasteboard generalPasteboard]setString:txt];
  1210. }
  1211. -(void)jsClearRight:(NSDictionary *)dict {
  1212. //清粘贴板数据
  1213. [[UIPasteboard generalPasteboard]setString:@""];
  1214. }
  1215. -(NSString *)jsReadRight:(NSDictionary *)dict {
  1216. NSString *content = [UIPasteboard generalPasteboard].string;
  1217. return content;
  1218. }
  1219. //内购VIP
  1220. -(void)jsInPurchasingVip:(NSDictionary *)dict {
  1221. NSString *productid = [NSString stringWithFormat:@"%@",dict[@"productid"]];
  1222. //产品id
  1223. if ([productid isEqualToString:@""]) {
  1224. NSLog(@"订单号 有问题");
  1225. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"订单号异常,请重试" delay:1];
  1226. return;
  1227. }
  1228. [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果验证中,请稍候"];
  1229. //监听购买结果
  1230. if([SKPaymentQueue canMakePayments]){
  1231. [self requestProductData:productid];
  1232. }else{
  1233. NSLog(@"不允许程序内付费");
  1234. [[LXViewControllerManager shareViewControllerManager] hideHud];
  1235. }
  1236. }
  1237. //去苹果服务器请求商品
  1238. - (void)requestProductData:(NSString *)type {
  1239. NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
  1240. NSSet *nsset = [NSSet setWithArray:product];
  1241. SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
  1242. request.delegate = self;
  1243. [request start];
  1244. }
  1245. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
  1246. NSArray *myProduct = response.products;
  1247. if (myProduct.count == 0) {
  1248. NSLog(@"无法获取产品信息,购买失败。");
  1249. [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"暂时未获取到产品信息,请重试" delay:1];
  1250. return;
  1251. }
  1252. SKPayment * payment = [SKPayment paymentWithProduct:myProduct[0]];
  1253. [[SKPaymentQueue defaultQueue] addPayment:payment];
  1254. }
  1255. //监听购买结果
  1256. - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
  1257. NSLog(@"收到支付回调");
  1258. for (SKPaymentTransaction *transaction in transactions) {
  1259. switch (transaction.transactionState) {
  1260. case SKPaymentTransactionStatePurchased://交易完成
  1261. NSLog(@"购买成功transactionIdentifier = %@", transaction.transactionIdentifier);
  1262. [self completeTransaction:transaction];
  1263. break;
  1264. case SKPaymentTransactionStateFailed://交易失败
  1265. [self failedTransaction:transaction];
  1266. break;
  1267. case SKPaymentTransactionStateRestored://已经购买过该商品
  1268. [self restoreTransaction:transaction];
  1269. break;
  1270. case SKPaymentTransactionStatePurchasing://商品添加进列表
  1271. NSLog(@"商品添加进列表");
  1272. break;
  1273. default:
  1274. break;
  1275. }
  1276. }
  1277. }
  1278. - (void)completeTransaction:(SKPaymentTransaction *)transaction {
  1279. // Your application should implement these two methods.
  1280. [[LXViewControllerManager shareViewControllerManager] hideHud];
  1281. NSString * productIdentifier = transaction.payment.productIdentifier;
  1282. NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] appStoreReceiptURL]];
  1283. NSData *receiptData;
  1284. NSError *error = nil;
  1285. receiptData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:&error];
  1286. NSString *receipt = [receiptData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  1287. if ([productIdentifier length] > 0) {
  1288. // 向自己的服务器验证购买凭证
  1289. if(self.tabBarController.selectedIndex == 0) {
  1290. [self isExitCallToJS:[NSString stringWithFormat:@"getReceipt('%@')", receipt] withMethodName:@"getReceipt"];
  1291. }else {
  1292. [[NSNotificationCenter defaultCenter] postNotificationName:@"receiptData" object:nil userInfo:@{@"receipt":receipt}];
  1293. }
  1294. }
  1295. // Remove the transaction from the payment queue.
  1296. [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
  1297. }
  1298. - (void)failedTransaction:(SKPaymentTransaction *)transaction {
  1299. [[LXViewControllerManager shareViewControllerManager] hideHud];
  1300. if(transaction.error.code != SKErrorPaymentCancelled) {
  1301. NSLog(@"购买失败");
  1302. [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"购买失败,请重新尝试。" delay:1];
  1303. } else {
  1304. NSLog(@"用户取消交易");
  1305. [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"取消交易" delay:1];
  1306. }
  1307. [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
  1308. }
  1309. - (void)restoreTransaction:(SKPaymentTransaction *)transaction {
  1310. // 对于已购商品,处理恢复购买的逻辑
  1311. NSLog(@"对于已购商品,处理恢复购买的逻辑");
  1312. [[LXViewControllerManager shareViewControllerManager] hideHud];
  1313. [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
  1314. }
  1315. //切换模块
  1316. -(void)jsSkipAppointTab:(NSDictionary *)dict {
  1317. if(self.tabBarController.selectedIndex == 0) {
  1318. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1319. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  1320. NSString *name = [NSString stringWithFormat:@"%@",dict[@"name"]];
  1321. if ([name isEqualToString:@"search"]) {
  1322. tab.selectedIndex = 0;//切换底部栏
  1323. }else if ([name isEqualToString:@"subscribe"]) {
  1324. tab.selectedIndex = 1;//切换底部栏
  1325. }else if ([name isEqualToString:@"box"]) {
  1326. tab.selectedIndex = 2;//切换底部栏
  1327. }else if ([name isEqualToString:@"me"]) {
  1328. tab.selectedIndex = 3;//切换底部栏
  1329. }else {
  1330. }
  1331. }
  1332. }
  1333. //刷新模块页面
  1334. -(void)jsRefreshAppointTab:(NSDictionary *)dict {
  1335. if(self.tabBarController.selectedIndex == 0) {
  1336. [[NSNotificationCenter defaultCenter] postNotificationName:JYRefreshMenusView object:nil userInfo:dict];
  1337. }
  1338. }
  1339. #pragma mark *****其他方法
  1340. -(void)judgeIsHiddenBottom {
  1341. if(self.tabBarController.selectedIndex == 0) {
  1342. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  1343. NSArray *array = [current_url componentsSeparatedByString:@"?"];
  1344. current_url = [NSString stringWithFormat:@"%@",array.firstObject];
  1345. if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/mainSearch",kHost]]){
  1346. [self showTabBar];
  1347. [self showMethodTabBar];
  1348. }else {
  1349. [self hideTabBar];
  1350. [self hiddenMethodTabBar];
  1351. }
  1352. }
  1353. }
  1354. - (void)hideTabBar {
  1355. kMainQueue(^{
  1356. if (self.tabBarController.tabBar.hidden == YES) {
  1357. return;
  1358. }
  1359. UIView *contentView;
  1360. if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
  1361. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  1362. else
  1363. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  1364. 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);
  1365. self.tabBarController.tabBar.hidden = YES;
  1366. });
  1367. }
  1368. - (void)showTabBar{
  1369. kMainQueue(^{
  1370. if (self.tabBarController.tabBar.hidden == NO){
  1371. return;
  1372. }
  1373. UIView *contentView;
  1374. if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
  1375. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  1376. else
  1377. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  1378. 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);
  1379. self.tabBarController.tabBar.hidden = NO;
  1380. });
  1381. }
  1382. - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
  1383. {
  1384. __block NSString *resultString = nil;
  1385. __block BOOL finished = NO;
  1386. [self.webView evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
  1387. if (error == nil) {
  1388. if (result != nil) {
  1389. resultString = [NSString stringWithFormat:@"%@", result];
  1390. }
  1391. } else {
  1392. NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
  1393. }
  1394. finished = YES;
  1395. }];
  1396. while (!finished) {
  1397. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
  1398. }
  1399. return resultString;
  1400. }
  1401. -(void)hiddenMethodTabBar
  1402. {
  1403. kMainQueue(^{
  1404. if (iPhoneX) {
  1405. if (@available(iOS 11.0, *)) {
  1406. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
  1407. }
  1408. }else {
  1409. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
  1410. }
  1411. });
  1412. }
  1413. -(void)showMethodTabBar
  1414. {
  1415. kMainQueue(^{
  1416. if (iPhoneX) {
  1417. if (@available(iOS 11.0, *)) {
  1418. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT);
  1419. }
  1420. }else {
  1421. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
  1422. }
  1423. });
  1424. }
  1425. //取消获取照片
  1426. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  1427. {
  1428. dispatch_async(dispatch_get_main_queue(), ^{
  1429. [picker dismissViewControllerAnimated:YES completion:^{
  1430. [self uploadUrl:@""];
  1431. }];
  1432. });
  1433. }
  1434. //上传图片
  1435. -(void)uploadPic:(NSData *)data
  1436. {
  1437. NSString *isPath = @"courseFile";
  1438. if (![[GlobalData shareInstance].isSkipPath isEqualToString:@""]) {
  1439. isPath = [GlobalData shareInstance].isSkipPath;
  1440. }
  1441. NSDictionary * body = @{@"type":isPath};
  1442. AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
  1443. //ContentType设置
  1444. manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html",@"image/jpeg",@"image/png",@"application/octet-stream",@"text/json",@"text/plain",nil];
  1445. manager.responseSerializer= [AFHTTPResponseSerializer serializer];
  1446. manager.requestSerializer = [AFHTTPRequestSerializer serializer];
  1447. manager.requestSerializer.timeoutInterval = 15.0f;
  1448. [manager POST:[NSString stringWithFormat:@"%@jyapp/filemanage/upload",kHost] parameters:body constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
  1449. //上传的参数(上传图片,以文件流的格式)
  1450. [formData appendPartWithFileData:data
  1451. name:isPath
  1452. fileName:[isPath stringByAppendingFormat:@".jpeg"]
  1453. mimeType:@"image/jpeg"];
  1454. } progress:^(NSProgress * _Nonnull uploadProgress) {
  1455. CGFloat progress = 100.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount;
  1456. NSLog(@"%.2lf%%", progress);
  1457. } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  1458. //请求成功的block回调
  1459. NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
  1460. NSLog(@"上传成功%@",dic);
  1461. if ([dic[@"msg"] isEqualToString:@"ssss"]) {
  1462. [self uploadUrl:dic[@"url"]];
  1463. }else{
  1464. [self uploadUrl:@""];
  1465. }
  1466. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  1467. NSLog(@"上传失败%@",error);
  1468. [self uploadUrl:@""];
  1469. [[GlobalData shareInstance] addOnePlistData:@{
  1470. @"detail":@"上传图片接口",
  1471. @"reqTime":[NSNumber numberWithInt:0],
  1472. }];
  1473. }];
  1474. }
  1475. -(void)uploadUrl:(NSString *)url {
  1476. NSString *textJS = [NSString new];
  1477. NSString *methodJS = [NSString new];
  1478. if ([url isEqualToString:@""]) {
  1479. textJS = @"hiddenLoading()";
  1480. methodJS =@"hiddenLoading";
  1481. }else{
  1482. textJS = [NSString stringWithFormat:@"uploadImg('%@')",url];
  1483. methodJS = @"uploadImg";
  1484. }
  1485. if ([url isEqualToString:@""]||[textJS isEqualToString:@""]) {
  1486. NSLog(@"空的情况");
  1487. textJS = @"hiddenLoading()";
  1488. methodJS = @"hiddenLoading";
  1489. }
  1490. NSDictionary *dict = @{@"jsStr":textJS,@"name":methodJS};
  1491. [self performSelector:@selector(uploadJS:) withObject:dict afterDelay:1];
  1492. }
  1493. //获取到图片
  1494. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  1495. {
  1496. dispatch_async(dispatch_get_main_queue(), ^{
  1497. [picker dismissViewControllerAnimated:YES completion:^{
  1498. UIImage * img=[info objectForKey:UIImagePickerControllerEditedImage];
  1499. NSData *data = UIImageJPEGRepresentation(img, 0.5);
  1500. if (data!=nil) {
  1501. [self uploadPic:data];
  1502. }else{
  1503. NSLog(@"data == nil");
  1504. [self uploadUrl:@""];
  1505. }
  1506. }];
  1507. });
  1508. }
  1509. -(void)uploadJS:(NSDictionary *)dict {
  1510. [self isExitCallToJS:dict[@"jsStr"] withMethodName:dict[@"name"]];
  1511. }
  1512. - (BOOL)checkLocationServiceIsEnabled{
  1513. // 该方法是类方法,和我们创建的管理器没有关系
  1514. if ([CLLocationManager locationServicesEnabled]) {
  1515. return YES;
  1516. }
  1517. return NO;
  1518. }
  1519. - (void)createCLManager{
  1520. // 创建CoreLocation管理对象
  1521. self.locaationManager = [[CLLocationManager alloc]init];
  1522. // 设定定位精准度
  1523. [self.locaationManager setDesiredAccuracy:kCLLocationAccuracyBest];
  1524. // 设定DistanceFilter可以在用户移动指定距离之后触发更新事件(100米更新一次)
  1525. [self.locaationManager setDistanceFilter:1.f];
  1526. // 设置代理
  1527. self.locaationManager.delegate = self;
  1528. // 开始更新定位
  1529. [self.locaationManager startUpdatingLocation];
  1530. }
  1531. // 代理方法,更新位置
  1532. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
  1533. CLLocation * newLocation = [locations lastObject];
  1534. // 判空处理
  1535. if (newLocation.horizontalAccuracy < 0) {
  1536. return;
  1537. }
  1538. CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  1539. [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
  1540. for (CLPlacemark *placeMark in placemarks) {
  1541. //NSLog(@"位置:%@", placeMark.name);
  1542. //NSLog(@"街道:%@", placeMark.thoroughfare);
  1543. //NSLog(@"子街道:%@", placeMark.subThoroughfare);
  1544. //NSLog(@"区\\县:%@", placeMark.subLocality);
  1545. //NSLog(@"市:%@", placeMark.locality);
  1546. //NSLog(@"行政区:%@", placeMark.administrativeArea);
  1547. //NSLog(@"国家:%@", placeMark.country);
  1548. self.placeAdr = [placeMark.administrativeArea stringByAppendingString:[NSString stringWithFormat:@"-%@",placeMark.locality]];
  1549. }
  1550. }];
  1551. }
  1552. // 代理方法,定位权限检查
  1553. -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
  1554. switch (status) {
  1555. case kCLAuthorizationStatusNotDetermined:{
  1556. NSLog(@"用户还未决定授权");
  1557. // 主动获得授权
  1558. [self.locaationManager requestWhenInUseAuthorization];
  1559. break;
  1560. }
  1561. case kCLAuthorizationStatusRestricted:
  1562. {
  1563. NSLog(@"访问受限");
  1564. // 主动获得授权
  1565. [self.locaationManager requestWhenInUseAuthorization];
  1566. break;
  1567. }
  1568. case kCLAuthorizationStatusDenied:{
  1569. // 此时使用主动获取方法也不能申请定位权限
  1570. // 类方法,判断是否开启定位服务
  1571. if ([CLLocationManager locationServicesEnabled]) {
  1572. NSLog(@"定位服务开启,被拒绝");
  1573. } else {
  1574. NSLog(@"定位服务关闭,不可用");
  1575. }
  1576. break;
  1577. }
  1578. case kCLAuthorizationStatusAuthorizedAlways:{
  1579. NSLog(@"获得前后台授权");
  1580. break;
  1581. }
  1582. case kCLAuthorizationStatusAuthorizedWhenInUse:{
  1583. NSLog(@"获得前台授权");
  1584. break;
  1585. }
  1586. default:
  1587. break;
  1588. }
  1589. }
  1590. -(NSString *)convertToJsonData:(NSDictionary *)dict {
  1591. NSError *error;
  1592. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
  1593. NSString *jsonString;
  1594. if (!jsonData) {
  1595. NSLog(@"%@",error);
  1596. }else{
  1597. jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  1598. }
  1599. NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
  1600. NSRange range = {0,jsonString.length};
  1601. //去掉字符串中的空格
  1602. [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
  1603. NSRange range2 = {0,mutStr.length};
  1604. //去掉字符串中的换行符
  1605. [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
  1606. return mutStr;
  1607. }
  1608. -(void)addNoNetViews{
  1609. kMainQueue(^{
  1610. self.recognizer.enabled = NO;
  1611. [self removeNoNetViews];
  1612. //about:blank
  1613. self.noNetView = [NoNetView shareView];
  1614. [self.view addSubview:self.noNetView];
  1615. });
  1616. }
  1617. -(void)removeNoNetViews{
  1618. if (self.noNetView ) {
  1619. self.recognizer.enabled = YES;
  1620. [self.noNetView removeFromSuperview];
  1621. self.noNetView = nil;
  1622. }
  1623. }
  1624. -(void)addFailNetViews{
  1625. kMainQueue(^{
  1626. self.recognizer.enabled = NO;
  1627. [self removeFailNetViews];
  1628. self.failNetView = [NoNetView shareView];
  1629. [self.view addSubview:self.failNetView];
  1630. });
  1631. }
  1632. -(void)removeFailNetViews{
  1633. if (self.failNetView ) {
  1634. self.recognizer.enabled = YES;
  1635. [self.failNetView removeFromSuperview];
  1636. self.failNetView = nil;
  1637. }
  1638. }
  1639. #pragma mark **** 通知相关方法
  1640. -(void)openPushUrlOtherMethods:(NSNotification *)notification{
  1641. if(self.tabBarController.selectedIndex == 0) {
  1642. NSDictionary *infoDict = notification.userInfo;
  1643. if (!infoDict) {return;}
  1644. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1645. if ([urlStr isEqualToString:kHost]) {return;}
  1646. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
  1647. }
  1648. }
  1649. -(void)openPushUrlMethodsOne:(NSNotification *)notification{
  1650. NSDictionary *infoDict = notification.userInfo;
  1651. NSLog(@"%@",infoDict);
  1652. if (!infoDict) {return;}
  1653. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1654. if ([urlStr isEqualToString:kHost]||![LXUserDefaults token]) {return;}
  1655. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
  1656. }
  1657. -(void)openPushLinkUrlMethods:(NSNotification *)notification{
  1658. NSDictionary *infoDict = notification.userInfo;
  1659. NSLog(@"%@",infoDict);
  1660. if (!infoDict) {return;}
  1661. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  1662. if ([urlStr isEqualToString:kHost]) {return;}
  1663. if (self.tabBarController.selectedIndex == 0) {
  1664. [self JsOpenExternalLink:@{@"url":urlStr,@"title":@"消息通知"}];
  1665. }
  1666. }
  1667. -(void)alipayWXpayStatus:(NSNotification *)notification{
  1668. if(self.tabBarController.selectedIndex == 0) {
  1669. NSString * status = [notification object];
  1670. [self performSelector:@selector(payStatus:) withObject:status afterDelay:2];
  1671. }
  1672. }
  1673. -(void)payStatus:(NSString *)status {
  1674. NSLog(@"支付状态:%@",status);//目前延时两秒
  1675. if(self.tabBarController.selectedIndex == 0) {
  1676. [self isExitCallToJS:[NSString stringWithFormat:@"payCallBack('%@')", status] withMethodName:@"payCallBack"];
  1677. }
  1678. }
  1679. // 调用js方法 刷新推送权限状态
  1680. -(void)updateNotifyState:(NSNotification *)notification{
  1681. if (self.updateNotify) {
  1682. self.updateNotify = NO;
  1683. [self isExitCallToJS:[NSString stringWithFormat:@"updateNoticeSwitch()"] withMethodName:@"updateNoticeSwitch"];
  1684. }
  1685. }
  1686. // 再次加载页面
  1687. -(void)notNetReloadWebVIew:(NSNotification *)notification{
  1688. if(self.tabBarController.selectedIndex == 0) {
  1689. if (![self.webView canGoBack]) {
  1690. [self webViewFirstRequest];
  1691. }else{
  1692. [self.webView reload];
  1693. }
  1694. }
  1695. }
  1696. // 返回上一页面- 防止
  1697. -(void)popWebView:(NSNotification *)notification{
  1698. if(self.tabBarController.selectedIndex == 0) {
  1699. if ([self.webView canGoBack]) {
  1700. [self.webView goBack];
  1701. }
  1702. [self removeNoNetViews];
  1703. [self removeFailNetViews];
  1704. }
  1705. }
  1706. // 收到退出登录消息
  1707. -(void)loginOut:(NSNotification *)notification{
  1708. if([notification.userInfo[@"item_index"] integerValue]!=0) {
  1709. return;
  1710. }
  1711. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login?back=index&isios=t&flag=kicked"];
  1712. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1713. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  1714. }
  1715. // 监控网络状态变化
  1716. -(void)netReachChanged:(NSNotification *)notificaition{
  1717. NSDictionary *userInfo = notificaition.userInfo;
  1718. if ([userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == 0 || [userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == -1) {
  1719. // NSLog(@"检测无网络");
  1720. [self addNoNetViews];
  1721. }else{
  1722. [self removeNoNetViews];
  1723. if (isExistNoNewWork) {
  1724. isExistNoNewWork = NO;
  1725. [self notNetReloadWebVIew:nil];
  1726. }
  1727. }
  1728. }
  1729. //前往登录页面
  1730. -(void)isLoginTabBar:(NSNotification *)notification
  1731. {
  1732. NSDictionary *dict = notification.userInfo;
  1733. NSLog(@"我从第几个页面过来:%@",dict[@"item_index"]);
  1734. pushIndex = [dict[@"item_index"] integerValue];
  1735. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login"];
  1736. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1737. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  1738. }
  1739. -(void)jyReceiveNewsRedPoint:(NSNotification *)notificaition {
  1740. NSDictionary *dict = notificaition.userInfo;
  1741. NSLog(@"收到消息处理:%@",dict);
  1742. if (![dict[@"index"] isEqualToString:@""]) { //展示红点-
  1743. int index = [dict[@"index"] intValue];
  1744. kMainQueue(^{
  1745. [self.tabBarController.tabBar showBadgeOnItemIndex:index];
  1746. });
  1747. }
  1748. if(self.tabBarController.selectedIndex == 0) {
  1749. NSString *textJS = [NSString stringWithFormat:@"afterReceivePushMessage('%@','%@')",dict[@"typeMsg"],dict[@"url"]];
  1750. [self isExitCallToJS:textJS withMethodName:@"afterReceivePushMessage"];
  1751. }
  1752. }
  1753. -(void)jyRefreshMenusView:(NSNotification *)notificaition {
  1754. NSDictionary *dict = notificaition.userInfo;
  1755. NSString *name = [NSString stringWithFormat:@"%@",dict[@"name"]];
  1756. NSString *type = [NSString stringWithFormat:@"%@",dict[@"type"]];
  1757. if ([name isEqualToString:@"search"]) {
  1758. if ([type isEqualToString:@"0"]) {
  1759. [self.webView reload];
  1760. }else {
  1761. [self webViewFirstRequest];
  1762. }
  1763. }
  1764. }
  1765. //刷新页面相关
  1766. -(void)refreshNonCurVC:(NSNotification *)notificaition{
  1767. if(self.tabBarController.selectedIndex != 0) {
  1768. [self webViewFirstRequest];
  1769. }
  1770. }
  1771. -(void)refreshAllVC:(NSNotification *)notificaition{
  1772. [self webViewFirstRequest];
  1773. }
  1774. #pragma mark ****粘贴板相关-梳理
  1775. -(void)updateClipboard:(NSNotification *)notificaition{
  1776. if(self.tabBarController.selectedIndex == 0) {
  1777. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  1778. NSDictionary *dict = notificaition.userInfo;
  1779. NSString *content = [NSString stringWithFormat:@"%@",dict[@"content"]];
  1780. if ([current_url containsString:@"jyapp/free/login"]) {
  1781. [GlobalData shareInstance].isPasteLogin = YES;
  1782. }else {
  1783. [self popPasteVIew:content];
  1784. }
  1785. }
  1786. }
  1787. -(void)openTheClipboard:(NSNotification *)notificaition{
  1788. if(self.tabBarController.selectedIndex == 0) {
  1789. NSLog(@"菜单一打开指定粘贴板url");
  1790. NSDictionary *dict = notificaition.userInfo;
  1791. NSString *tmpUrl = [NSString stringWithFormat:@"%@%@", kHost, dict[@"url"]];
  1792. tmpUrl = [tmpUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1793. kMainQueue(^{
  1794. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tmpUrl]]];
  1795. })
  1796. }
  1797. }
  1798. //弹出粘贴板框
  1799. -(void)popPasteVIew:(NSString *)content {
  1800. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@distribution/share/getWordInfo",kHost] parameters:@{@"copyTxt":content} progress:^(NSProgress *progress) {
  1801. NSLog(@"%@",progress);
  1802. } success:^(id responseObject) {
  1803. NSLog(@"responseObject=%@",responseObject);
  1804. if ([responseObject objectForKey:@"data"]) {
  1805. NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:responseObject[@"data"]];
  1806. if ([dict objectForKey:@"title"]) {
  1807. self.clipboardView.title =dict[@"title"];
  1808. self.clipboardView.subTitle =dict[@"subTitle"];
  1809. self.clipboardView.imgUrl =dict[@"imgUrl"];
  1810. self.clipboardView.appUrl =dict[@"appUrl"];
  1811. self.clipboardView.butTxt =dict[@"butTxt"];
  1812. self.clipboardView.bottomTxt =dict[@"bottomTxt"];
  1813. [self.clipboardView show];
  1814. }
  1815. }
  1816. } failure:^(NSError *error) {
  1817. NSLog(@"error=%@",error);
  1818. }];
  1819. }
  1820. #pragma mark **** 代理方法
  1821. -(void)clipboardClick:(NSString *)url {
  1822. //发送通知打开粘贴板-url
  1823. [[NSNotificationCenter defaultCenter] postNotificationName:OpenTheClipboard object:nil userInfo:@{@"url":url}];
  1824. }
  1825. /*
  1826. #pragma mark - Navigation
  1827. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1828. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1829. // Get the new view controller using [segue destinationViewController].
  1830. // Pass the selected object to the new view controller.
  1831. }
  1832. */
  1833. @end