JYNewSubViewController.m 69 KB

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