JYNewSearchViewController.m 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085
  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. @end
  34. NSString *const new_kInitVector_1 = @"1389461544135476";
  35. size_t const new_kKeySize_1 = kCCKeySizeAES128;
  36. NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
  37. @implementation JYNewSearchViewController
  38. -(void)viewWillAppear:(BOOL)animated
  39. {
  40. [super viewWillAppear:animated];
  41. [self.navigationController setNavigationBarHidden:YES animated:animated];
  42. if ([GlobalData shareInstance].isClickNotiStatus) {
  43. [GlobalData shareInstance].searchIsRed = NO;
  44. [GlobalData shareInstance].isClickNotiStatus = NO;
  45. }else {
  46. if([GlobalData shareInstance].searchIsRed) {
  47. [GlobalData shareInstance].searchIsRed = NO;
  48. [self webViewFirstRequest];
  49. }
  50. }
  51. }
  52. //弹框
  53. -(ZKFaceVerifyMsgView *)verifyMsgView
  54. {
  55. if(!_verifyMsgView) {
  56. _verifyMsgView = [[ZKFaceVerifyMsgView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 150)];
  57. _verifyMsgView.titleName = @"温馨提示";
  58. }
  59. return _verifyMsgView;
  60. }
  61. //弹框
  62. -(ZKClipboardView *)clipboardView{
  63. if(!_clipboardView) {
  64. _clipboardView = [[ZKClipboardView alloc]initWithFrame:CGRectMake(0, 0, WIDTH*0.8, 180+90)];
  65. _clipboardView.delegate = self;
  66. }
  67. return _clipboardView;
  68. }
  69. //进度条
  70. - (UIProgressView *)progressView
  71. {
  72. if (_progressView == nil) {
  73. _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,STATUS_BAR_HEIGHT - 2,WIDTH,2)];
  74. _progressView.tintColor = [UIColor blueColor];
  75. _progressView.trackTintColor = [UIColor whiteColor];
  76. }
  77. return _progressView;
  78. }
  79. //懒加载
  80. - (WKWebView *)webView
  81. {
  82. if(_webView == nil) {
  83. WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
  84. config.preferences = [[WKPreferences alloc] init];
  85. config.preferences.minimumFontSize = 0;
  86. config.allowsInlineMediaPlayback = YES;
  87. config.preferences.javaScriptEnabled = YES;
  88. config.preferences.javaScriptCanOpenWindowsAutomatically = YES;
  89. //添加消息处理,注意:self指代的是需要遵守WKScriptMessageHandler协议,结束时需要移除
  90. config.userContentController = [[WKUserContentController alloc] init];
  91. //声明协议
  92. NSArray *jsArr = @[@"loginByWeixin",
  93. @"share",
  94. @"saveUserToken",
  95. @"removeUserToken",
  96. @"openSystemNotification",
  97. @"openExternalLink",
  98. @"alert",
  99. @"hiddenBottom",
  100. @"checkLab",
  101. @"loginSuccess",
  102. @"backUrl",
  103. @"clearPushMessage",
  104. @"hideRedSpotOnMenu",
  105. @"showRedSpotOnMenu",
  106. @"wxPay",
  107. @"aliPay",
  108. @"chooseTab",
  109. @"skipCameraWithParam",
  110. @"skipAlbumWithParam",
  111. @"openActivityPage",
  112. @"callPhone",
  113. @"openOtherAppLinks",
  114. @"inPurchasingVip",
  115. @"wirteRight",
  116. @"clearRight",
  117. @"savePic",
  118. @"ocrVerifyService",
  119. @"faceVerifyService",
  120. @"skipAppointTab",
  121. @"refreshAppointTab",
  122. ];
  123. for (NSString*jsName in jsArr) {
  124. [config.userContentController addScriptMessageHandler:self name:jsName];
  125. }
  126. //高端的自定义配置创建WKWebView
  127. if (iPhoneX) {
  128. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT) configuration:config];
  129. if (@available(iOS 11.0, *)) {
  130. _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  131. }
  132. }else {
  133. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT) configuration:config];
  134. }
  135. _webView.scrollView.bounces = NO;
  136. _webView.UIDelegate = self;
  137. _webView.navigationDelegate = self;
  138. _webView.userInteractionEnabled = YES;
  139. [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  140. }
  141. return _webView;
  142. }
  143. -(void)webViewFirstRequest
  144. {
  145. //去时间戳-拼接
  146. NSString *tmpUrl = @"";
  147. if ([LXUserDefaults isExistToken]) {
  148. NSString *token = [LXUserDefaults token];
  149. tmpUrl = [[NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login"] stringByAppendingString:[NSString stringWithFormat:@"?sign=%@&url=/jyapp/jylab/mainSearch&from=restart", token]];
  150. }else {
  151. tmpUrl = [[NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/index"] stringByAppendingString:[NSString stringWithFormat:@"?deviceid=%@", [LXUserDefaults getDeviceID]]];
  152. }
  153. NSLog(@"111 :第一次加载:%@",tmpUrl);
  154. tmpUrl = [tmpUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  155. kMainQueue(^{
  156. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tmpUrl]]];
  157. })
  158. }
  159. #pragma mark - event response
  160. // 计算wkWebView进度条
  161. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
  162. // NSLog(@"进度条加载完毕");
  163. if (object == self.webView && [keyPath isEqualToString:@"estimatedProgress"]) {
  164. CGFloat newprogress = [[change objectForKey:NSKeyValueChangeNewKey] doubleValue];
  165. self.progressView.alpha = 1.0f;
  166. [self.progressView setProgress:newprogress animated:YES];
  167. if (newprogress >= 1.0f) {
  168. self.recognizer.enabled = YES;
  169. [UIView animateWithDuration:0.3f
  170. delay:0.3f
  171. options:UIViewAnimationOptionCurveEaseOut
  172. animations:^{
  173. self.progressView.alpha = 0.0f;
  174. }
  175. completion:^(BOOL finished) {
  176. [self.progressView setProgress:0 animated:NO];
  177. }];
  178. }
  179. } else {
  180. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  181. }
  182. }
  183. -(void)initNotification {
  184. //加载通知
  185. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushUrlOtherMethods:) name:OpenPushUrlOtherMethods object:nil];
  186. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushLinkUrlMethods:) name:OpenPushLinkUrlMethods object:nil];
  187. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openPushUrlMethodsOne:) name:OpenPushUrlMethodsOne object:nil];
  188. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jyReceiveNewsRedPoint:) name:JYReceiveNewsRedPoint object:nil];
  189. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jyRefreshMenusView:) name:JYRefreshMenusView object:nil];
  190. //支付状态通知
  191. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayWXpayStatus:) name:AlipayWXpayStatus object:nil];
  192. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNotifyState:) name:kUpdateNotifyState object:nil];
  193. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notNetReloadWebVIew:) name:NotNetReloadWebVIew object:nil];
  194. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popWebView:) name:PopWebView object:nil];
  195. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut:) name:kLoginOut object:nil];
  196. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
  197. //前往登录通知-tabbar
  198. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isLoginTabBar:) name:LoginIndexTabBar object:nil];
  199. //展示底部红的通知
  200. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jyReceiveNewsRedPoint:) name:JYReceiveNewsRedPoint object:nil];
  201. //接收全新通知
  202. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNonCurVC:) name:RefreshNonCurVC object:nil];
  203. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAllVC:) name:RefreshAllVC object:nil];
  204. //粘贴板-
  205. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateClipboard:) name:UpdateClipboard object:nil];
  206. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openTheClipboard:) name:OpenTheClipboard object:nil];
  207. }
  208. #pragma mark – Gesture Recognizer –
  209. -(void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer
  210. {
  211. NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  212. NSLog(@"%@",current_url);
  213. CGRect rect = self.view.bounds;
  214. CGFloat width = CGRectGetWidth(rect);
  215. if (![self.webView canGoBack]||([current_url containsString:@"jyapp/free/login"])) {
  216. NSLog(@"不可返回");
  217. return;
  218. }
  219. 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]]){
  220. return;
  221. }
  222. CGPoint touchPoint = [recoginzer locationInView:[UIApplication sharedApplication].keyWindow];
  223. if (recoginzer.state==UIGestureRecognizerStateBegan) {
  224. _isMoving = YES;
  225. startTouch = touchPoint;
  226. } else if (recoginzer.state==UIGestureRecognizerStateEnded||(recoginzer.state==UIGestureRecognizerStatePossible)){
  227. if (touchPoint.x - startTouch.x > width*0.125) {
  228. [UIView animateWithDuration:0.3 animations:^{
  229. if (recoginzer.state==UIGestureRecognizerStateEnded) {
  230. [self moveViewWithX:width];
  231. if ([current_url containsString:@"jyapp/jylab/mainSearch#"]) {
  232. [self isExitCallToJS:@"afterClickBack()" withMethodName:@"afterClickBack"];
  233. }
  234. [self.webView goBack];
  235. }
  236. } completion:^(BOOL finished) {
  237. _isMoving = NO;
  238. [self moveViewWithX:0];
  239. }];
  240. } else {
  241. [UIView animateWithDuration:0.3 animations:^{
  242. [self moveViewWithX:0];
  243. } completion:^(BOOL finished) {
  244. _isMoving = NO;
  245. }];
  246. }
  247. return;
  248. } else if (recoginzer.state==UIGestureRecognizerStateCancelled){
  249. [UIView animateWithDuration:0.3 animations:^{
  250. [self moveViewWithX:0];
  251. } completion:^(BOOL finished) {
  252. _isMoving = NO;
  253. }];
  254. return;
  255. }else {
  256. }
  257. if (_isMoving) {
  258. [self moveViewWithX:touchPoint.x - startTouch.x];
  259. }
  260. }
  261. -(void)moveViewWithX:(float)x
  262. {
  263. CGRect rect = self.view.bounds;
  264. CGFloat width = CGRectGetWidth(rect);
  265. x = x>width?width:x;
  266. x = x<0?0:x;
  267. CGRect frame = self.webView.frame;
  268. frame.origin.x = x;
  269. self.webView.frame = frame;
  270. }
  271. - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
  272. // message.body -- Allowed types are NSNumber, NSString, NSDate, NSArray,NSDictionary, and NSNull.
  273. // NSLog(@"原生收到了js发送过来的消息message.name = %@ message.body = %@",message.name,message.body);
  274. if ([message.name isEqualToString:@"loginByWeixin"]) {
  275. [self jsLoginByWeixin:message.body];
  276. }else if ([message.name isEqualToString:@"share"]) {
  277. [self jsShare:message.body];
  278. }else if ([message.name isEqualToString:@"saveUserToken"]) {
  279. [self jsSaveUserToken:message.body];
  280. }else if ([message.name isEqualToString:@"removeUserToken"]) {
  281. [self jsRemoveUserToken:message.body];
  282. }else if ([message.name isEqualToString:@"openSystemNotification"]) {
  283. [self jsOpenSystemNotification:message.body];
  284. }else if ([message.name isEqualToString:@"openExternalLink"]) {
  285. [self JsOpenExternalLink:message.body];
  286. }else if ([message.name isEqualToString:@"alert"]) {
  287. [self jsAlert:message.body];
  288. }else if ([message.name isEqualToString:@"hiddenBottom"]) {
  289. [self jsHiddenBottom:message.body];
  290. }else if ([message.name isEqualToString:@"checkLab"]) {
  291. [self jsCheckLab:message.body];
  292. }else if ([message.name isEqualToString:@"loginSuccess"]) {
  293. [self jsLoginSuccess:message.body];
  294. }else if ([message.name isEqualToString:@"backUrl"]) {
  295. [self jsBackUrl:message.body];
  296. }else if ([message.name isEqualToString:@"clearPushMessage"]) {
  297. [self jsClearPushMessage:message.body];
  298. }else if ([message.name isEqualToString:@"hideRedSpotOnMenu"]) {
  299. [self jsHideRedSpotOnMenu:message.body];
  300. }else if ([message.name isEqualToString:@"showRedSpotOnMenu"]) {
  301. [self jsShowRedSpotOnMenu:message.body];
  302. }else if ([message.name isEqualToString:@"wxPay"]) {
  303. [self jsWxPay:message.body];
  304. }else if ([message.name isEqualToString:@"aliPay"]) {
  305. [self jsAliPay:message.body];
  306. }else if ([message.name isEqualToString:@"chooseTab"]) {
  307. [self jsChooseTab:message.body];
  308. }else if ([message.name isEqualToString:@"skipCameraWithParam"]) {
  309. [self jsSkipCameraWithParam:message.body];
  310. }else if ([message.name isEqualToString:@"skipAlbumWithParam"]) {
  311. [self jsSkipAlbumWithParam:message.body];
  312. }else if ([message.name isEqualToString:@"openActivityPage"]) {
  313. [self jsOpenActivityPage:message.body];
  314. }else if ([message.name isEqualToString:@"callPhone"]) {
  315. [self jsCallPhone:message.body];
  316. }else if ([message.name isEqualToString:@"openOtherAppLinks"]) {
  317. [self jsOpenOtherAppLinks:message.body];
  318. }else if ([message.name isEqualToString:@"inPurchasingVip"]) {
  319. [self jsInPurchasingVip:message.body];
  320. }else if ([message.name isEqualToString:@"wirteRight"]) {
  321. [self jsWirteRight:message.body];
  322. }else if ([message.name isEqualToString:@"clearRight"]) {
  323. [self jsClearRight:message.body];
  324. }else if ([message.name isEqualToString:@"savePic"]) {
  325. [self jsSavePic:message.body];
  326. }else if ([message.name isEqualToString:@"ocrVerifyService"]) {
  327. [self jsOcrVerifyService:message.body];
  328. }else if ([message.name isEqualToString:@"faceVerifyService"]) {
  329. [self jsFaceVerifyService:message.body];
  330. }else if ([message.name isEqualToString:@"skipAppointTab"]) {
  331. [self jsSkipAppointTab:message.body];
  332. }else if ([message.name isEqualToString:@"refreshAppointTab"]) {
  333. [self jsRefreshAppointTab:message.body];
  334. }else {
  335. }
  336. }
  337. #pragma mark - WKUIDelegate
  338. - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable result))completionHandler
  339. {
  340. NSError *err = nil;
  341. NSData *dataFromString = [prompt dataUsingEncoding:NSUTF8StringEncoding];
  342. NSDictionary *paramdict = [NSJSONSerialization JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:&err];
  343. // NSLog(@"拦截prompt:%@",paramdict);
  344. if (!err){
  345. NSString *type = [paramdict objectForKey:@"jsName"];
  346. if (type && [type isEqualToString:@"getUserToken"]) {
  347. NSDictionary *dict = @{@"type":@"string",
  348. @"value":[self jsGetUserToken:paramdict]};
  349. completionHandler([self convertToJsonData:dict]);
  350. }else if (type && [type isEqualToString:@"getVersion"]) {
  351. NSDictionary *dict = @{@"type":@"string",
  352. @"value":[self jsGetVersion:paramdict]};
  353. completionHandler([self convertToJsonData:dict]);
  354. }else if (type && [type isEqualToString:@"checkNoticePermission"]) {
  355. NSDictionary *dict = @{@"type":@"int",
  356. @"value":[NSString stringWithFormat:@"%d",[self jsCheckNoticePermission:paramdict]]};
  357. completionHandler([self convertToJsonData:dict]);
  358. }else if (type && [type isEqualToString:@"getPushRid"]) {
  359. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetPushRid:paramdict]};
  360. completionHandler([self convertToJsonData:dict]);
  361. }else if (type && [type isEqualToString:@"isInstallWeixin"]) {
  362. NSDictionary *dict = @{@"type":@"int",
  363. @"value":[NSString stringWithFormat:@"%d",[self jsIsInstallWeixin:paramdict]]};
  364. completionHandler([self convertToJsonData:dict]);
  365. }else if (type && [type isEqualToString:@"getCipherText"]) {
  366. NSDictionary *dict = @{@"type":@"string",
  367. @"value":[self jsGetCipherText:paramdict]};
  368. completionHandler([self convertToJsonData:dict]);
  369. }
  370. else if (type && [type isEqualToString:@"getOtherPushRid"]) {
  371. NSDictionary *dict = @{@"type":@"string",@"value":[self jsGetOtherPushRid:paramdict]};
  372. completionHandler([self convertToJsonData:dict]);
  373. }else if (type && [type isEqualToString:@"getPhoneBrand"]) {
  374. NSDictionary *dict = @{@"type":@"string",
  375. @"value":[self jsGetPhoneBrand:paramdict]};
  376. completionHandler([self convertToJsonData:dict]);
  377. }else if (type && [type isEqualToString:@"getLocation"]) {
  378. NSDictionary *dict = @{@"type":@"string",
  379. @"value":[self jsGetLocation:paramdict]};
  380. completionHandler([self convertToJsonData:dict]);
  381. }else if (type && [type isEqualToString:@"readRight"]) {
  382. NSDictionary *dict = @{@"type":@"string",
  383. @"value":[self jsReadRight:paramdict]};
  384. completionHandler([self convertToJsonData:dict]);
  385. }else {
  386. completionHandler(@"");
  387. }
  388. }
  389. }
  390. // 在发送请求之前,决定是否跳转
  391. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  392. //如果当前页面是三级页面-
  393. NSString *curUrl = [webView.URL absoluteString];
  394. if ([curUrl containsString:@"jyapp/article/content"]) {
  395. //当前页面是三级页面--判断待跳转页面是否符合内置跳转
  396. NSString *nextUrl = [navigationAction.request.URL absoluteString];
  397. if ([nextUrl containsString:@"jianyu360.com"]||[nextUrl containsString:@"jianyu360.cn"]||[nextUrl containsString:@"qmx.top"]) {
  398. // 允许跳转
  399. decisionHandler(WKNavigationActionPolicyAllow);
  400. }else {
  401. NSLog(@"不允许内部跳转:-%@",nextUrl);
  402. //筛选拦截-压缩包等格式不允许跳转
  403. 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"]) {
  404. // 不允许跳转
  405. decisionHandler(WKNavigationActionPolicyCancel);
  406. }else {
  407. JYWKNewWebController *ctr = [[JYWKNewWebController alloc] init];
  408. ctr.url = nextUrl;
  409. ctr.titleShow = @"公告信息";
  410. kMainQueue(^{
  411. [self presentViewController:ctr animated:NO completion:nil];
  412. });
  413. // 不允许跳转-并跳转新页面
  414. decisionHandler(WKNavigationActionPolicyCancel);
  415. }
  416. }
  417. }else if ([curUrl containsString:@"apps.apple.com"]&&[curUrl containsString:@"1354897149"]){
  418. [[UIApplication sharedApplication] openURL:[NSURL URLWithString: curUrl]];
  419. decisionHandler(WKNavigationActionPolicyCancel);
  420. }else {
  421. // 允许跳转
  422. decisionHandler(WKNavigationActionPolicyAllow);
  423. }
  424. }
  425. #pragma mark ****WKUIDelegate
  426. //通过js alert 显示一个警告面板,调用原生会走此方法。
  427. - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
  428. {
  429. // NSLog(@"显示一个JavaScript警告面板, message = %@",message);
  430. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  431. [alertController addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  432. completionHandler();
  433. }]];
  434. [self presentViewController:alertController animated:YES completion:nil];
  435. }
  436. //通过 js confirm 显示一个确认面板,调用原生会走此方法。
  437. - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler
  438. {
  439. // NSLog(@"运行JavaScript确认面板, message = %@", message);
  440. UIAlertController *action = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
  441. [action addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  442. completionHandler(NO);
  443. }] ];
  444. [action addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  445. completionHandler(YES);
  446. }]];
  447. [self presentViewController:action animated:YES completion:nil];
  448. }
  449. #pragma mark - OC调JS交互
  450. -(void)isExitCallToJS:(NSString *)jsStr withMethodName:(NSString *)name{
  451. NSString *jsName = [NSString stringWithFormat:@"function exist(){return !window['%@']};exist()",name];
  452. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  453. WeakSelf;
  454. [_webView evaluateJavaScript:jsName completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  455. // NSLog(@"是否存在 result:%@,error:%@",result,error);
  456. if ([result intValue]==0) {
  457. [weakSelf executeCallJS:jsStr];
  458. }else {
  459. NSLog(@"不存在-不存在-不存在-%@",jsStr);
  460. }
  461. }];
  462. });
  463. }
  464. -(void)executeCallJS:(NSString *)jsStr {
  465. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  466. [_webView evaluateJavaScript:jsStr completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  467. if (error!=nil) {
  468. // NSLog(@"result:%@,error:%@",result,error);
  469. // [[GlobalData shareInstance] addOnePlistData:@{
  470. // @"detail":[[self stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\nJS异常方法:%@\n%@",jsStr,[error description]]],
  471. // @"reqTime":[NSNumber numberWithInt:0],
  472. // }];
  473. }
  474. }];
  475. });
  476. }
  477. - (void)viewDidLoad {
  478. [super viewDidLoad];
  479. // Do any additional setup after loading the view.
  480. NSLog(@"首页初始化");
  481. self.view.backgroundColor = [UIColor whiteColor];
  482. [self.view addSubview:self.webView];
  483. [self.view addSubview:self.progressView];
  484. [self webViewFirstRequest];
  485. [[AFNetworkReachabilityManager sharedManager] startMonitoring];
  486. [self initNotification];
  487. self.recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)];
  488. [self.recognizer delaysTouchesBegan];
  489. [self.view addGestureRecognizer:self.recognizer];
  490. //初始化临时属性
  491. self.placeAdr = [NSString new];
  492. //定时器-检测错误数据是否超过10个 发送
  493. [NSTimer scheduledTimerWithTimeInterval:180 target:self selector:@selector(errorLogListening) userInfo:nil repeats:YES];
  494. //监听底部栏
  495. [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(bottomOneListening) userInfo:nil repeats:YES];
  496. //监听购买结果
  497. [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
  498. }
  499. //-(void)btn1click{
  500. //
  501. // 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"];
  502. //
  503. // UIDocumentPickerViewController *documentPickerViewController = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes
  504. // inMode:UIDocumentPickerModeOpen];
  505. // documentPickerViewController.delegate = self;
  506. // [self presentViewController:documentPickerViewController animated:YES completion:nil];
  507. //}
  508. //#pragma mark - UIDocumentPickerDelegate
  509. //
  510. //- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
  511. //
  512. // NSArray *array = [[url absoluteString] componentsSeparatedByString:@"/"];
  513. // NSString *fileName = [array lastObject];
  514. // fileName = [fileName stringByRemovingPercentEncoding];
  515. // NSLog(@"%@",fileName);
  516. // if ([iCloudManager iCloudEnable]) {
  517. // [iCloudManager downloadWithDocumentURL:url callBack:^(id obj) {
  518. // NSLog(@"选择文件");
  519. //// NSData *data = obj;
  520. // //上传
  521. //// //写入沙盒Documents
  522. //// NSString *filePath = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@",fileName]];
  523. //// [data writeToFile:filePath atomically:YES];
  524. ////
  525. //// NSLog(@"%@",filePath);
  526. //
  527. //// NSArray *arr = [filePath componentsSeparatedByString:@"."];
  528. //// NSString *smallString = [[arr lastObject] lowercaseString];
  529. //// NSLog(@"%@",smallString);
  530. // }];
  531. // }
  532. //}
  533. -(void)bottomOneListening {
  534. //临时添加提示框
  535. // NSString *current_url = [self stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  536. // NSArray * array = [current_url componentsSeparatedByString:kHost];
  537. // current_url = [array.lastObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  538. // [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:current_url delay:2];
  539. if(self.tabBarController.selectedIndex == 0) {
  540. [self judgeIsHiddenBottom];
  541. }
  542. }
  543. - (BOOL)isTheCurrentPeriod{
  544. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  545. NSDate *now = [NSDate date];
  546. NSDateComponents *comps = [[NSDateComponents alloc] init];
  547. NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
  548. comps = [calendar components:unitFlags fromDate:now];
  549. long hour = (long)[comps hour];
  550. if (hour>=12&&hour<14) {
  551. return YES;
  552. }
  553. if (hour>=17&&hour<=23) {
  554. return YES;
  555. }
  556. if (hour>=0&&hour<7) {
  557. return YES;
  558. }
  559. return NO;
  560. }
  561. - (NSString *)toJsonStrWithArray:(NSArray *)arr {
  562. if ([arr isKindOfClass:[NSString class]]) {
  563. return (NSString *)arr;
  564. }
  565. NSError *parseError = nil;
  566. NSData *data = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:nil];
  567. NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  568. jsonStr = [jsonStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  569. jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@" " withString:@""];
  570. jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  571. if (parseError) {
  572. jsonStr = @"";
  573. }
  574. return jsonStr;
  575. }
  576. -(void)errorLogListening {
  577. if ([self isTheCurrentPeriod]) {
  578. if ([[GlobalData shareInstance] getPlistCount]>=50) {
  579. NSMutableDictionary *dict =[[GlobalData shareInstance] getPlistAllData];
  580. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/errLogs/Receive",kHost] parameters:@{@"jsonData":[self toJsonStrWithArray:dict[@"jsonData"]]} progress:^(NSProgress *progress) {
  581. NSLog(@"%@",progress);
  582. } success:^(id responseObject) {
  583. NSLog(@"responseObject=%@",responseObject);
  584. [[GlobalData shareInstance] clearPlistData];
  585. } failure:^(NSError *error) {
  586. NSLog(@"error=%@",error);
  587. [[GlobalData shareInstance] addOnePlistData:@{
  588. @"detail":[NSString stringWithFormat:@"上传日志接口:%@",[error description]],
  589. @"reqTime":[NSNumber numberWithInt:0],
  590. }];
  591. }];
  592. }
  593. }else {
  594. }
  595. }
  596. -(void)haveRedPoint
  597. {
  598. NSLog(@"http请求-------小红点");
  599. NSString *token = [LXUserDefaults token];
  600. if ([LXUserDefaults isExistToken]) {
  601. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/showRedSpotOnMenu",kHost] parameters:@{@"token":token} progress:^(NSProgress *progress) {
  602. // NSLog(@"%@",progress);
  603. } success:^(id responseObject) {
  604. // NSLog(@"responseObject=%@",responseObject);
  605. if([responseObject[@"subscribe"] integerValue]>=1) {
  606. //显示
  607. [GlobalData shareInstance].subIsRed = YES;
  608. kMainQueue(^{
  609. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  610. });
  611. }else {
  612. [GlobalData shareInstance].subIsRed = NO;
  613. kMainQueue(^{
  614. [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
  615. });
  616. }
  617. if([responseObject[@"my"] integerValue]>=1) {
  618. //显示
  619. [GlobalData shareInstance].mineIsRed = YES;
  620. kMainQueue(^{
  621. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  622. });
  623. }else {
  624. [GlobalData shareInstance].mineIsRed = NO;
  625. kMainQueue(^{
  626. [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  627. });
  628. }
  629. } failure:^(NSError *error) {
  630. NSLog(@"error=%@",error);
  631. [[GlobalData shareInstance] addOnePlistData:@{
  632. @"detail":[NSString stringWithFormat:@"获取小红点接口:%@",[error description]],
  633. @"reqTime":[NSNumber numberWithInt:0],
  634. }];
  635. }];
  636. }
  637. }
  638. #pragma mark - WKNavigationDelegate
  639. /* 页面加载完成 */
  640. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
  641. NSLog(@"-----页面加载完成%@",webView.URL.absoluteString);
  642. if (![GlobalData shareInstance].isSearchToLoad) {
  643. [GlobalData shareInstance].isSearchToLoad = YES;
  644. }
  645. //第一次加载小红点
  646. if(!isLoadRedDot) {
  647. isLoadRedDot = true;
  648. [self haveRedPoint];
  649. }
  650. [self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
  651. [self.webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';"completionHandler:nil];
  652. [self judgeIsHiddenBottom];//是否隐藏
  653. [self removeNoNetViews];
  654. [self removeFailNetViews];
  655. [[LXViewControllerManager shareViewControllerManager] hideHud];
  656. //写数据
  657. // [self writeWKWebData:webView.URL];
  658. if (![GlobalData shareInstance].isOpen) {//第一次打开
  659. [GlobalData shareInstance].isOpen = YES;
  660. [self performSelector:@selector(pasteboard) withObject:nil afterDelay:1.5];
  661. }
  662. }
  663. -(void)pasteboard {
  664. NSString *content = [UIPasteboard generalPasteboard].string;
  665. if ([content containsString:@"剑鱼标讯"]) {//第一次打开页面时候
  666. [[NSNotificationCenter defaultCenter] postNotificationName:UpdateClipboard object:nil userInfo:@{@"content":content}];
  667. }
  668. }
  669. -(void)writeWKWebData:(NSURL *)url {
  670. //得到NSData 数据
  671. NSData *dataContent = [NSData dataWithContentsOfURL:url];
  672. //NSURLCache 实例化
  673. NSURLCache *cache = [NSURLCache sharedURLCache];
  674. //得到相应
  675. NSURLResponse *response = [[NSURLResponse alloc]initWithURL:url MIMEType:nil expectedContentLength:0 textEncodingName:@"UTF-8"];
  676. //得到CacheURLResponse
  677. NSCachedURLResponse *cacheResponse = [[NSCachedURLResponse alloc]initWithResponse:response data:dataContent];
  678. //进行存储
  679. [cache storeCachedResponse:cacheResponse forRequest:[NSURLRequest requestWithURL:url]];
  680. }
  681. // 页面开始加载时调用
  682. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
  683. self.recognizer.enabled = NO;
  684. }
  685. // 当内容开始返回时调用
  686. - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
  687. }
  688. // 页面加载失败时调用
  689. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(nonnull NSError *)error{
  690. //加载失败 有网络-弹出页面 , 无网络-记录标记
  691. if ([ZKMethod judegeNetworkIsAvailable]) {
  692. //弹出页面
  693. NSLog(@"页面加载失败-有网络");
  694. [self addFailNetViews];
  695. }else {
  696. //记录标记
  697. NSLog(@"页面加载失败-无网络");
  698. isExistNoNewWork = YES;
  699. }
  700. self.recognizer.enabled = YES;
  701. [[GlobalData shareInstance] addOnePlistData:@{
  702. @"detail":[[self stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\n%@",[error description]]],
  703. @"reqTime":[NSNumber numberWithInt:0],
  704. }];
  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