JYSearchViewController.m 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. //
  2. // JYSearchViewController.m
  3. // JianYuIOS
  4. //
  5. // Created by apple on 2018/11/8.
  6. // Copyright © 2018年 lixianglan. All rights reserved.
  7. //
  8. #import "JYSearchViewController.h"
  9. #import "JYTabBarController.h"
  10. #import <CoreLocation/CoreLocation.h>
  11. @protocol JYSearchViewControllerJSExport<JSExport>
  12. JSExportAs(loginByWeixin, -(NSString *)jsLoginByWeixin:(NSString *)str);// 微信登录 openid
  13. JSExportAs(share, -(void)jsShare:(NSString *)type title:(NSString *)title content:(NSString *)content link:(NSString *)link); // 调用分享
  14. JSExportAs(saveUserToken, -(void)jsSaveUserToken:(NSString *)token);// 登录时获取令牌 保存
  15. JSExportAs(getUserToken, -(NSString *)jsGetUserToken:(NSString *)str);// 取本地存的令牌
  16. JSExportAs(removeUserToken, -(void)jsRemoveUserToken:(NSString *)str); // 退出时清空数据
  17. JSExportAs(checkNoticePermission, -(int)jsCheckNoticePermission:(NSString *)str); // 查询手机通知是否打开
  18. JSExportAs(openSystemNotification, -(void)jsOpenSystemNotification:(NSString *)str);// 跳转到系统设置
  19. JSExportAs(getPushRid, -(NSString *)jsGetPushRid:(NSString *)str);// 返回极光id
  20. JSExportAs(getMessageList, -(NSString *)jsGetMessageList:(NSString *)openid);// 按通知接收时间倒排,取前100条
  21. JSExportAs(updateMessageState, -(void)jsUpdateMessageState:(NSString *)lxID state:(NSString *)state);// 更新状态
  22. JSExportAs(deleteMessageById, -(void)jsDeleteMessageById:(NSString *)lxID);// 删除一条消息
  23. JSExportAs(getMessage, -(NSString *)jsGetMessage:(NSString *)lxID);// 取单条数据
  24. JSExportAs(getUnReadMessageCount, -(int)jsGetUnReadMessageCount:(NSString *)openid);// 获取未读消息总数
  25. JSExportAs(updateAllUnReadMessage, -(void)jsUpdateAllUnReadMessage:(NSString *)openid);// 全部置为已读
  26. JSExportAs(lightStatusBar, -(void)jsLightStatusBar:(NSString *)status);// 导航栏文字颜色
  27. JSExportAs(openExternalLink, -(void)jsOpenExternalLink:(NSString *)url title:(NSString *)title);// 打开新控制器 加载新web
  28. JSExportAs(getVersion, -(NSString *)jsGetVersion:(NSString *)str);// 获取当前版本号
  29. JSExportAs(alert, -(void)jsAlert:(NSString *)content);// 弹框
  30. JSExportAs(isInstallWeixin, -(int)jsIsInstallWeixin:(NSString *)str);// 是否安装微信
  31. JSExportAs(changeMessageType, -(void)jsChangeMessageType:(NSString *)link);//已读操作处理
  32. JSExportAs(openActivityPage, -(void)jsOpenActivityPage:(NSString *)url rectype:(NSString *)rectype openid:(NSString *)openid);
  33. JSExportAs(getCipherText, -(NSString *)jsGGetCipherText:(NSString *)phone);
  34. JSExportAs(business, -(NSInteger)jsBusiness:(NSInteger)shooID shopType:(NSInteger )shopType);
  35. //新增
  36. JSExportAs(hiddenBottom, -(void)jsHiddenBottom:(NSString*)hidden);
  37. //刷新其他页面
  38. JSExportAs(checkLab, -(void)jsCheckLab:(NSString*)str);
  39. //登录相关
  40. JSExportAs(loginSuccess, -(void)jsLoginSuccess:(NSString*)status);
  41. JSExportAs(backUrl, -(void)jsBackUrl:(NSString*)str);
  42. //JSExportAs(redirectKeyset, -(void)jsRedirectKeyset:(NSString*)str);
  43. JSExportAs(clearPushMessage, -(void)jsClearPushMessage:(NSString*)type);
  44. JSExportAs(hideRedSpotOnMenu, -(void)jsHideRedSpotOnMenu:(NSString*)str);
  45. JSExportAs(showRedSpotOnMenu, -(void)jsShowRedSpotOnMenu:(NSString*)str);
  46. //支付相关
  47. JSExportAs(wxPay, -(void)jsWxPay:(NSString *)jsonString);
  48. JSExportAs(aliPay, -(void)jsAliPay:(NSString*)str);
  49. //原生通知
  50. JSExportAs(getOtherPushRid, -(NSString *)jsGetOtherPushRid:(NSString *)str);
  51. JSExportAs(getPhoneBrand, -(NSString *)jsGetPhoneBrand:(NSString *)str);
  52. //返回省-市
  53. JSExportAs(getLocation, -(NSString *)jsGetLocation:(NSString *)str);
  54. //切换底部栏
  55. JSExportAs(chooseTab, -(void)jsChooseTab:(int)indexTab);
  56. @end
  57. @interface JYSearchViewController ()<UIWebViewDelegate, JYSearchViewControllerJSExport,CLLocationManagerDelegate>
  58. {
  59. CGPoint startTouch;
  60. BOOL _isMoving;
  61. NSInteger pushIndex;//第几个模块过来的
  62. NSInteger _timeTick;
  63. NSInteger _time;
  64. BOOL autologin;
  65. BOOL notiFinish;
  66. BOOL refreshTabBool; //实验室-百宝箱 是否刷新
  67. }
  68. @property(nonatomic, strong)UIWebView *webView;
  69. //@property (weak, nonatomic) IBOutlet UIWebView *webView;
  70. @property(nonatomic, assign)BOOL updateNotify;
  71. @property(nonatomic, assign)BOOL afterOpenPushMessage;
  72. @property(nonatomic, strong)NoNetView *noNetView;
  73. @property(nonatomic, strong)NSURLRequest *errRequest;
  74. @property (nonatomic, strong)NSMutableDictionary *notiDict;
  75. @property (nonatomic,weak)NSTimer *timer;
  76. @property(nonatomic,strong)CLLocationManager *locaationManager;
  77. @property(nonatomic,strong)NSString *placeAdr;
  78. @end
  79. NSString *const kInitVector_0 = @"1389461544135476";
  80. size_t const kKeySize_0 = kCCKeySizeAES128;
  81. NSString *const AesKey_0 = @"mGlAgnIBB8bx2nch";
  82. @implementation JYSearchViewController
  83. -(void)viewWillAppear:(BOOL)animated
  84. {
  85. [super viewWillAppear:animated];
  86. [self.navigationController setNavigationBarHidden:YES animated:animated];
  87. }
  88. - (void)viewDidLoad {
  89. [super viewDidLoad];
  90. self.view.backgroundColor = [UIColor whiteColor];
  91. if (iPhoneX) {
  92. self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT)];
  93. if (@available(iOS 11.0, *)) {
  94. self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  95. }
  96. }else {
  97. self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT)];
  98. }
  99. [self.view addSubview: self.webView];
  100. self.webView.scrollView.bounces = NO;
  101. self.webView.delegate = self;
  102. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  103. [self webViewFirstRequest];//请求页面数据
  104. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestWebView:) name:kRequestWebViewWithUrl object:nil];
  105. //点击订阅通知
  106. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickSubNotiMethods:) name:ClickSubNotiMethods object:nil];
  107. //点击支付通知
  108. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickPayMethods:) name:ClickPayMethods object:nil];
  109. //支付状态通知
  110. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayWXpayStatus:) name:AlipayWXpayStatus object:nil];
  111. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNotifyState) name:kUpdateNotifyState object:nil];
  112. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(afterReceiveNewMsg) name:kAfterReceiveNewMsg object:nil];
  113. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadWebView) name:kReloadWebVIew object:nil];
  114. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut:) name:kLoginOut object:nil];
  115. [[AFNetworkReachabilityManager sharedManager] startMonitoring];
  116. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
  117. UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)];
  118. [recognizer delaysTouchesBegan];
  119. [self.view addGestureRecognizer:recognizer];
  120. //手势
  121. //新增监听
  122. if([LXUserDefaults token]) {
  123. self.notiDict = [[NSMutableDictionary alloc]initWithDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"NotiDict"]];
  124. if(self.notiDict.count) {
  125. self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
  126. }
  127. }
  128. //前往登录通知-tabbar
  129. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isLoginTabBar:) name:LoginIndexTabBar object:nil];
  130. //新增刷新通知
  131. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshSS:) name:@"refreshSS" object:nil];
  132. //展示底部红的通知
  133. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newsRedPoint:) name:JYNewsRedPoint object:nil];
  134. //接收全新通知
  135. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNonCurVC:) name:RefreshNonCurVC object:nil];
  136. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAllVC:) name:RefreshAllVC object:nil];
  137. //初始化临时属性
  138. self.placeAdr = [NSString new];
  139. //是否需要显示小红点
  140. [self haveRedPoint];
  141. [self clearWeb];
  142. }
  143. -(void)newsRedPoint:(NSNotification *)notificaition
  144. {
  145. NSDictionary *dict = notificaition.userInfo;
  146. NSLog(@"%@",dict);
  147. NSInteger type = [dict[@"type"] integerValue];
  148. if(type==1) {
  149. //显示
  150. kMainQueue(^{
  151. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  152. });
  153. }else if (type==2) {
  154. //显示
  155. kMainQueue(^{
  156. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  157. });
  158. }else {
  159. }
  160. if(self.tabBarController.selectedIndex == 0) {
  161. NSString *textJS = [NSString stringWithFormat:@"afterReceivePushMessage('%@','%@')",dict[@"typeMsg"],dict[@"url"]];
  162. NSLog(@"%@",textJS);
  163. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  164. [context evaluateScript:textJS];
  165. }
  166. }
  167. -(void)haveRedPoint
  168. {
  169. NSString *token = [LXUserDefaults token];
  170. if (token) {
  171. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/showRedSpotOnMenu",kHost] parameters:@{@"token":token} progress:^(NSProgress *progress) {
  172. NSLog(@"%@",progress);
  173. } success:^(id responseObject) {
  174. NSLog(@"responseObject=%@",responseObject);
  175. if([responseObject[@"subscribe"] integerValue]>=1) {
  176. //显示
  177. [GlobalData shareInstance].subIsRed = YES;
  178. kMainQueue(^{
  179. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  180. });
  181. }else {
  182. [GlobalData shareInstance].subIsRed = NO;
  183. kMainQueue(^{
  184. [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
  185. });
  186. }
  187. if([responseObject[@"my"] integerValue]>=1) {
  188. //显示
  189. [GlobalData shareInstance].mineIsRed = YES;
  190. kMainQueue(^{
  191. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  192. });
  193. }else {
  194. [GlobalData shareInstance].mineIsRed = NO;
  195. kMainQueue(^{
  196. [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  197. });
  198. }
  199. } failure:^(NSError *error) {
  200. NSLog(@"error=%@",error);
  201. }];
  202. }
  203. }
  204. //2.5.1
  205. -(void)timeFireMethod{
  206. _timeTick++;
  207. NSLog(@"定时器");
  208. if(self.webView&&notiFinish) {
  209. NSString * urlStr = [NSString stringWithFormat:@"%@",self.notiDict[@"info"][@"url"]];
  210. if (urlStr) {
  211. if([self.notiDict[@"type"] isEqualToString:@"bid"]) {
  212. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  213. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  214. tab.selectedIndex = 1;
  215. [self performSelector:@selector(pushDY:) withObject:self.notiDict[@"info"] afterDelay:1];
  216. }else {
  217. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  218. self.afterOpenPushMessage = YES;
  219. [self performSelector:@selector(requestWebTime:) withObject:self.notiDict afterDelay:1];
  220. }
  221. [self.timer invalidate];
  222. self.timer = nil;
  223. _timeTick = 0;
  224. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"NotiDict"];
  225. }
  226. return;
  227. }
  228. if (_timeTick == 60) {
  229. [self.timer invalidate];
  230. self.timer = nil;
  231. _timeTick = 0;
  232. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"NotiDict"];
  233. }
  234. }
  235. -(void)moveViewWithX:(float)x
  236. {
  237. CGRect rect = self.view.bounds;
  238. CGFloat width = CGRectGetWidth(rect);
  239. x = x>width?width:x;
  240. x = x<0?0:x;
  241. CGRect frame = self.webView.frame;
  242. frame.origin.x = x;
  243. self.webView.frame = frame;
  244. }
  245. #pragma mark – Gesture Recognizer –
  246. -(void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer
  247. {
  248. NSString *current_url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  249. NSLog(@"当前页面:%@",current_url);
  250. CGRect rect = self.view.bounds;
  251. CGFloat width = CGRectGetWidth(rect);
  252. if (![self.webView canGoBack]) {
  253. NSLog(@"不可返回");
  254. return;
  255. }
  256. if([current_url containsString:@"jyapp/free/login"]) {
  257. return;
  258. }
  259. // NSString *current_url = self.webView.request.URL.absoluteString;
  260. 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]]){
  261. return;
  262. }
  263. //https://www.jianyu360.com/jyapp/free/me
  264. //https://www.jianyu360.com/jyapp/jylab/index
  265. //https://www.jianyu360.com/jyapp/wxkeyset/keyset/index
  266. //https://www.jianyu360.com/jyapp/jylab/mainSearch
  267. CGPoint touchPoint = [recoginzer locationInView:[UIApplication sharedApplication].keyWindow];
  268. if (recoginzer.state==UIGestureRecognizerStateBegan) {
  269. _isMoving = YES;
  270. startTouch = touchPoint;
  271. } else if (recoginzer.state==UIGestureRecognizerStateEnded){
  272. if (touchPoint.x - startTouch.x > width*0.125) {
  273. [UIView animateWithDuration:0.3 animations:^{
  274. [self moveViewWithX:width];
  275. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  276. [context evaluateScript:@"afterClickBack()"];
  277. [self.webView goBack];
  278. } completion:^(BOOL finished) {
  279. _isMoving = NO;
  280. [self moveViewWithX:0];
  281. }];
  282. } else {
  283. [UIView animateWithDuration:0.3 animations:^{
  284. [self moveViewWithX:0];
  285. } completion:^(BOOL finished) {
  286. _isMoving = NO;
  287. }];
  288. }
  289. return;
  290. } else if (recoginzer.state==UIGestureRecognizerStateCancelled){
  291. [UIView animateWithDuration:0.3 animations:^{
  292. [self moveViewWithX:0];
  293. } completion:^(BOOL finished) {
  294. _isMoving = NO;
  295. }];
  296. return;
  297. }
  298. if (_isMoving) {
  299. [self moveViewWithX:touchPoint.x - startTouch.x];
  300. }
  301. }
  302. // 监控网络状态变化
  303. -(void)netReachChanged:(NSNotification *)notificaition{
  304. NSDictionary *userInfo = notificaition.userInfo;
  305. if ([userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == 0 || [userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == -1) {
  306. [self addNoNetViews];
  307. }else{
  308. [self removeNoNetViews];
  309. }
  310. }
  311. // 再次加载页面
  312. -(void)reloadWebView{
  313. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  314. if (!self.webView.canGoBack) {
  315. [self webViewFirstRequest];
  316. }else{
  317. [self.webView reload];
  318. }
  319. }
  320. // 首次加载web
  321. -(void)webViewFirstRequest{
  322. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/index"];
  323. NSString *token = [LXUserDefaults token];
  324. if (token) {
  325. url = [url stringByAppendingString:[NSString stringWithFormat:@"?sign=%@&url=/jyapp/jylab/mainSearch&from=restart", token]];
  326. }
  327. NSLog(@"111第一次加载%@",url);
  328. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  329. //[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:20]];
  330. kMainQueue(^{
  331. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  332. })
  333. }
  334. //收到消息退出并重新加载web
  335. -(void)webViewRequestByMsg{
  336. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login?back=index&isios=t&flag=kicked"];
  337. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  338. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  339. }
  340. -(void)requestWebTime:(NSDictionary *)infoDict
  341. {
  342. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
  343. if([infoDict[@"type"] isEqualToString:@"message"]) {
  344. NSString *url = [NSString stringWithFormat:@"%@",urlStr];
  345. NSArray * array = [url componentsSeparatedByString:@"=="];
  346. url = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  347. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  348. [[NSNotificationCenter defaultCenter] postNotificationName:@"kNewWebControllerDismiss" object:nil];
  349. }else if ([infoDict[@"type"] isEqualToString:@"titleMessage"]) {
  350. //新增支付 后台唤起
  351. NSArray * array = [urlStr componentsSeparatedByString:@"=="];
  352. urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  353. NSString * titleStr = @"消息通知";
  354. titleStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"title"]];
  355. if (urlStr) {
  356. if(self.tabBarController.selectedIndex == 0) {
  357. [self jsOpenExternalLink:urlStr title:titleStr];
  358. }
  359. }
  360. }else {
  361. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, urlStr];
  362. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  363. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  364. [[NSNotificationCenter defaultCenter] postNotificationName:@"kNewWebControllerDismiss" object:nil];
  365. }
  366. }
  367. // 点击通知 跳转到通知内url
  368. -(void)requestWebView:(NSNotification *)notification{
  369. NSDictionary * infoDict = [notification object];
  370. if (!infoDict) {
  371. return;
  372. }
  373. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
  374. if (urlStr) {
  375. //当前控制器
  376. if(self.tabBarController.selectedIndex != 0) {
  377. return;
  378. }
  379. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  380. self.afterOpenPushMessage = YES;
  381. [self performSelector:@selector(requestWebTime:) withObject:infoDict afterDelay:1];
  382. }
  383. }
  384. -(void)clickSubNotiMethods:(NSNotification *)notification{
  385. NSDictionary * infoDict = [notification object][@"info"];
  386. if (!infoDict) {
  387. return;
  388. }
  389. NSLog(@"%@",infoDict);
  390. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  391. if (urlStr) {
  392. NSLog(@"有info");
  393. if(self.tabBarController.selectedIndex == 0) {
  394. //底部栏置换到订阅
  395. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  396. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  397. tab.selectedIndex = 1;
  398. [self performSelector:@selector(pushDY:) withObject:infoDict afterDelay:1];
  399. }
  400. }
  401. }
  402. //点击支付通知
  403. -(void)clickPayMethods:(NSNotification *)notification{
  404. NSDictionary * infoDict = [notification object][@"info"];
  405. if (!infoDict) {
  406. return;
  407. }
  408. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  409. NSArray * array = [urlStr componentsSeparatedByString:@"=="];
  410. urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  411. NSString * titleStr = @"消息通知";
  412. titleStr = [NSString stringWithFormat:@"%@",infoDict[@"title"]];
  413. if (urlStr) {
  414. if(self.tabBarController.selectedIndex == 0) {
  415. [self jsOpenExternalLink:urlStr title:titleStr];
  416. }
  417. }
  418. }
  419. -(void)pushDY:(NSDictionary *)infoDict
  420. {
  421. [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshDY" object:nil userInfo:infoDict];
  422. }
  423. #pragma mark 收到z支付通知
  424. -(void)alipayWXpayStatus:(NSNotification *)notification{
  425. NSString * status = [notification object];
  426. [self performSelector:@selector(payStatus:) withObject:status afterDelay:2];
  427. }
  428. -(void)payStatus:(NSString *)status
  429. {
  430. //目前延时两秒
  431. NSLog(@"支付状态:%@",status);
  432. if(self.tabBarController.selectedIndex == 0) {
  433. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  434. NSString * textJS1 = [NSString stringWithFormat:@"payCallBack('%@')", status];
  435. [context evaluateScript:textJS1];
  436. }
  437. }
  438. // 收到通知消息
  439. -(void)afterReceiveNewMsg{
  440. NSLog(@"afterReceiveNewMsg");
  441. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  442. [context evaluateScript:@"afterReceiveNewMsg()"];
  443. }
  444. // 收到退出登录消息
  445. -(void)loginOut:(NSNotification *)notification{
  446. if([notification.userInfo[@"item_index"] integerValue]!=0) {
  447. return;
  448. }
  449. [self webViewRequestByMsg];
  450. }
  451. //刷新页面相关
  452. -(void)refreshNonCurVC:(NSNotification *)notificaition{
  453. if(self.tabBarController.selectedIndex != 0) {
  454. refreshTabBool = YES;
  455. [self webViewFirstRequest];
  456. }
  457. }
  458. -(void)refreshAllVC:(NSNotification *)notificaition{
  459. [self webViewFirstRequest];
  460. }
  461. //前往登录页面
  462. -(void)isLoginTabBar:(NSNotification *)notification
  463. {
  464. NSDictionary *dict = notification.userInfo;
  465. NSLog(@"我从第几个页面过来:%@",dict[@"item_index"]);
  466. pushIndex = [dict[@"item_index"] integerValue];
  467. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login"];
  468. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  469. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  470. }
  471. //js返回首页
  472. -(void)jsBackUrl:(NSString*)str
  473. {
  474. NSLog(@"search返回首页,search返回首页");
  475. if([str isEqualToString:@"H"]) {
  476. pushIndex = 0;
  477. [self webViewFirstRequest];
  478. }
  479. }
  480. //js方法登录成功
  481. -(void)jsLoginSuccess:(NSString*)status
  482. {
  483. NSLog(@"首页登录成功提示");
  484. [GlobalData shareInstance].isReLogin = YES;
  485. if([status isEqualToString:@"S"]) {
  486. if(pushIndex!=0) {
  487. kMainQueue((^{
  488. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshAllVC object:nil userInfo:nil];
  489. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  490. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  491. tab.selectedIndex = pushIndex;
  492. pushIndex = 0;
  493. }));
  494. }else {
  495. NSLog(@"刷新页面------当前页面");
  496. [self webViewFirstRequest];
  497. }
  498. }else if ([status isEqualToString:@""]) {
  499. //不刷新订阅-首页,刷新其他
  500. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshExpAndMine object:nil userInfo:nil];
  501. }else {
  502. }
  503. }
  504. - (void)hideTabBar {
  505. NSLog(@"隐藏tabbar");
  506. kMainQueue(^{
  507. if (self.tabBarController.tabBar.hidden == YES) {
  508. return;
  509. }
  510. UIView *contentView;
  511. if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
  512. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  513. else
  514. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  515. 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);
  516. self.tabBarController.tabBar.hidden = YES;
  517. });
  518. }
  519. - (void)showTabBar{
  520. kMainQueue(^{
  521. if (self.tabBarController.tabBar.hidden == NO)
  522. {
  523. return;
  524. }
  525. UIView *contentView;
  526. if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
  527. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  528. else
  529. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  530. 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);
  531. self.tabBarController.tabBar.hidden = NO;
  532. });
  533. }
  534. -(void)judgeIsHidden
  535. {
  536. NSString *current_url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  537. //[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/index",kHost]]
  538. // NSLog(@"%@",current_url);
  539. if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/mainSearch",kHost]]){
  540. NSLog(@"展示");
  541. [self showTabBar];
  542. [self showMethodTabBar];
  543. }else {
  544. NSLog(@"隐藏");
  545. [self hideTabBar];
  546. [self hiddenMethodTabBar];
  547. }
  548. }
  549. -(void)jsHiddenBottom:(NSString *)hidden
  550. {
  551. NSLog(@"让我展示隐藏bottom==%@",hidden);
  552. if([hidden integerValue]==0) {
  553. [self hideTabBar];
  554. [self hiddenMethodTabBar];
  555. }else {
  556. [self showTabBar];
  557. [self showMethodTabBar];
  558. }
  559. }
  560. -(void)hiddenMethodTabBar
  561. {
  562. kMainQueue(^{
  563. if (iPhoneX) {
  564. if (@available(iOS 11.0, *)) {
  565. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
  566. NSLog(@"%@",self.webView)
  567. }
  568. }else {
  569. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
  570. }
  571. });
  572. }
  573. -(void)showMethodTabBar
  574. {
  575. kMainQueue(^{
  576. if (iPhoneX) {
  577. if (@available(iOS 11.0, *)) {
  578. self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT-TAB_BAR_HEIGHT);
  579. }
  580. }else {
  581. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
  582. }
  583. });
  584. }
  585. #pragma mark webView代理方法
  586. - (void)webViewDidFinishLoad:(UIWebView *)webView{
  587. NSLog(@"加载完成:%@",[self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"]);
  588. if(!notiFinish) {
  589. notiFinish = YES;
  590. }
  591. if(refreshTabBool) {
  592. refreshTabBool = NO;
  593. }else {
  594. //正常的网页加载
  595. [self judgeIsHidden];//是否隐藏
  596. }
  597. [self removeNoNetViews];
  598. [[LXViewControllerManager shareViewControllerManager] hideHud];
  599. JSContext *context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  600. // // Disable user selection
  601. [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
  602. // Disable callout
  603. [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
  604. context[@"JyObj"] = self;
  605. [context evaluateScript:@"afterPageInit()"];
  606. if (self.afterOpenPushMessage) {
  607. self.afterOpenPushMessage = NO;
  608. // [context evaluateScript:@"afterOpenPushMessage()"];
  609. [context evaluateScript:[NSString stringWithFormat:@"afterOpenPushMessage('%d')", [self jsIsCanBack:nil]]];
  610. }
  611. }
  612. -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
  613. [[LXViewControllerManager shareViewControllerManager] hideHud];
  614. }
  615. -(void)webViewDidStartLoad:(UIWebView *)webView{
  616. // if ([[UIDevice currentDevice].systemVersion floatValue] < 10) {
  617. // [[LXViewControllerMager shareViewControllerManager] hideHud];
  618. // }
  619. }
  620. - (void)didReceiveMemoryWarning {
  621. [super didReceiveMemoryWarning];
  622. // [self clearWeb];
  623. // Dispose of any resources that can be recreated.
  624. }
  625. -(void)clearWeb{
  626. NSURLCache * cache = [NSURLCache sharedURLCache];
  627. [cache removeAllCachedResponses];
  628. [cache setDiskCapacity:0];
  629. [cache setMemoryCapacity:0];
  630. }
  631. -(void)addNoNetViews{
  632. kMainQueue(^{
  633. [self removeNoNetViews];
  634. self.noNetView = [NoNetView shareView];
  635. [self.view addSubview:self.noNetView];
  636. });
  637. }
  638. -(void)removeNoNetViews{
  639. if (self.noNetView ) {
  640. [self.noNetView removeFromSuperview];
  641. self.noNetView = nil;
  642. }
  643. }
  644. #pragma mark JS 回调
  645. // 微信登录
  646. -(NSString *)jsLoginByWeixin:(NSString *)str{
  647. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装微信 不走友盟
  648. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"微信登录失败,没有安装微信" delay:1.5];
  649. return nil;
  650. }
  651. kMainQueue(^{
  652. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
  653. UMSocialUserInfoResponse *resp = result;
  654. [self dealWXDic:(NSDictionary *)resp.originalResponse];
  655. [[LXViewControllerManager shareViewControllerManager] hideHud];
  656. }];
  657. });
  658. return nil;
  659. }
  660. // 处理微信登录获取到的数据
  661. -(void)dealWXDic:(NSDictionary *)dictionary{
  662. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  663. //如果获取到用户信息,即用户点击了“登录”,则进行用户信息获取
  664. if (dictionary.count > 0) {
  665. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dictionary];
  666. if (dic) {
  667. [dic removeObjectForKey:@"privilege"];
  668. [dic removeObjectForKey:@"language"];
  669. double currDouble = [[NSDate date] timeIntervalSince1970];
  670. [dic setObject:[NSNumber numberWithLong:(long)currDouble] forKey:@"createtime"];
  671. // 拼接标志位
  672. 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"]];
  673. sign = [LXMD5 md532BitLower:sign];
  674. [dic setObject:sign forKey:@"sign"];
  675. NSString *endStr = [[LXViewControllerManager shareViewControllerManager] getJsonStr:dic];
  676. NSData *data = [endStr dataUsingEncoding:NSUTF8StringEncoding];
  677. endStr = [data base64EncodedStringWithOptions:0];
  678. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  679. NSString * textJS1 = [NSString stringWithFormat:@"loginByWeixinCallBack('%@')", endStr];
  680. JSValue *value = [context evaluateScript:textJS1];
  681. NSLog(@"%@", value);
  682. }
  683. }
  684. }
  685. // js 调用分享
  686. -(void)jsShare:(NSString *)type title:(NSString *)title content:(NSString *)content link:(NSString *)link{
  687. UMSocialPlatformType shareType;
  688. if ([type intValue] == 1) { // 微信好友
  689. shareType = UMSocialPlatformType_WechatSession;
  690. }else if ([type intValue] == 2){ /// qq好友
  691. shareType = UMSocialPlatformType_QQ;
  692. }else if ([type intValue] == 3){ // 朋友圈
  693. shareType = UMSocialPlatformType_WechatTimeLine;
  694. }else{
  695. shareType = UMSocialPlatformType_WechatSession;
  696. }
  697. kMainQueue((^{
  698. // 没有安装app 不走分享逻辑
  699. if ([type intValue] == 1 || [type intValue] == 3) {
  700. if ([LXUserDefaults isInstallWeiXin] != 1) {
  701. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装微信" delay:1.5];
  702. return;
  703. }
  704. }
  705. // 没有安装app 不走分享逻辑
  706. if ([type intValue] == 2) {
  707. if (![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ]) {
  708. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装QQ" delay:1.5];
  709. return;
  710. }
  711. }
  712. //创建分享消息对象
  713. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  714. //创建网页内容对象
  715. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:content thumImage:[UIImage imageNamed:@"logo"]];
  716. //设置网页地址
  717. shareObject.webpageUrl = link;
  718. messageObject.shareObject = shareObject;
  719. //调用分享接口
  720. [[UMSocialManager defaultManager] shareToPlatform:shareType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  721. if (error) {
  722. NSLog(@"22222222%@",error.userInfo);
  723. if (error.userInfo[@"message"] && [error.userInfo[@"message"] containsString:@"Operation is cancel"]) {
  724. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"取消分享" delay:1];
  725. }else{
  726. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:error.userInfo[@"message"] delay:1];
  727. }
  728. NSString *textJS = [NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"0"];
  729. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  730. [context evaluateScript:textJS];
  731. }else{
  732. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  733. UMSocialShareResponse *resp = data;
  734. NSLog(@"33333%@",resp.message);
  735. NSLog(@"44444%@",resp.originalResponse);
  736. NSString *textJS = [NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"1"];
  737. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  738. [context evaluateScript:textJS];
  739. }else{
  740. UMSocialLogInfo(@"response data is %@",data);
  741. NSLog(@"55555%@",data);
  742. }
  743. }
  744. }];
  745. }));
  746. }
  747. // 登录时获取到令牌 并保存
  748. -(void)jsSaveUserToken:(NSString *)token{
  749. NSLog(@"登陆成功");
  750. [[LXViewControllerManager shareViewControllerManager] hideHud];
  751. [LXUserDefaults saveToken:token];
  752. }
  753. // 取本地的用户令牌
  754. -(NSString *)jsGetUserToken:(NSString *)str{
  755. NSLog(@"取用户token");
  756. return [LXUserDefaults token];
  757. }
  758. // 退出时 清空用户数据
  759. -(void)jsRemoveUserToken:(NSString *)str{
  760. NSLog(@"清除用户token");
  761. [LXUserDefaults clearAll];
  762. // [[LXDataBaseManager shareDataBaseManager] clearAll];
  763. }
  764. // 手机通知权限是否打开
  765. -(int)jsCheckNoticePermission:(NSString *)str{
  766. int a = [LXUserDefaults notifyState];
  767. return a;
  768. }
  769. // 跳转到系统设置
  770. -(void)jsOpenSystemNotification:(NSString *)str{
  771. self.updateNotify = YES;
  772. kMainQueue(^{
  773. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  774. });
  775. }
  776. // 调用js方法 刷新推送权限状态
  777. -(void)updateNotifyState{
  778. if (self.updateNotify) {
  779. self.updateNotify = NO;
  780. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  781. NSString * textJS1 = [NSString stringWithFormat:@"updateNoticeSwitch()"];
  782. [context evaluateScript:textJS1];
  783. }
  784. }
  785. // 获取推送id
  786. -(NSString *)jsGetPushRid:(NSString *)str{
  787. return [LXUserDefaults registrationID];
  788. }
  789. // 按通知取数据
  790. -(NSString *)jsGetMessageList:(NSString *)openid{
  791. NSArray *arr = [[LXDataBaseManager shareDataBaseManager] getMessageWithKey:nil openid:openid fromTable:kNewsTable start:0 length:100];
  792. if (arr.count > 0) {
  793. return [[LXViewControllerManager shareViewControllerManager] getJsonStr:arr];
  794. }
  795. return @"";
  796. }
  797. // 更新消息状态
  798. -(void)jsUpdateMessageState:(NSNumber *)lxID state:(NSNumber *)state{
  799. [[LXDataBaseManager shareDataBaseManager] changeReadedWithID:lxID state:state];
  800. }
  801. // 删除一条数据
  802. -(void)jsDeleteMessageById:(NSNumber *)lxID{
  803. [[LXDataBaseManager shareDataBaseManager] deleteMessage:lxID fromTable:kNewsTable];
  804. }
  805. // 取单条数据
  806. -(NSString *)jsGetMessage:(NSString *)lxID{
  807. return [[LXViewControllerManager shareViewControllerManager] getJsonStr:[[LXDataBaseManager shareDataBaseManager] getMessageWithKey:lxID openid:nil fromTable:kNewsTable start:0 length:0]];
  808. }
  809. // 取未读消息总数
  810. -(int)jsGetUnReadMessageCount:(NSString *)openid{
  811. NSLog(@"openid=%@",openid);
  812. // NSLog(@"%d",[[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid]);
  813. // if([[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid] ==0){
  814. // //显示
  815. // kMainQueue(^{
  816. // [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  817. // });
  818. // }else {
  819. // kMainQueue(^{
  820. // [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  821. // });
  822. // }
  823. return [[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid];
  824. }
  825. // 全部置为已读
  826. -(void)jsUpdateAllUnReadMessage:(NSString *)openid{
  827. [[LXDataBaseManager shareDataBaseManager] updateAllUnReadMessage:openid];
  828. }
  829. // 改变状态栏文字颜色
  830. -(void)jsLightStatusBar:(NSString *)status{
  831. kMainQueue(^{
  832. NSInteger index = 0;
  833. if ([status intValue] == 1) {
  834. index = 1;// hei
  835. }else{
  836. index = 0;// bai
  837. }
  838. [[UIApplication sharedApplication] setStatusBarStyle:index];
  839. });
  840. }
  841. // 打开新页面 加载新web
  842. -(void)jsOpenExternalLink:(NSString *)url title:(NSString *)title{
  843. if (url) {
  844. if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable || [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown) {
  845. // [self addNoNetViews];
  846. }
  847. NewWebController *ctr = [[NewWebController alloc] init];
  848. ctr.url = url;
  849. // 有title的话 会显示自定义的导航栏 没有的话不显示导航栏 显示加载进度条
  850. if (!title || [title isEqualToString:@""] || [title isEqualToString:@"undefined"]) {
  851. ctr.titleShow = nil;
  852. }else{
  853. ctr.titleShow = title;
  854. }
  855. kMainQueue(^{
  856. [self presentViewController:ctr animated:NO completion:nil];
  857. });
  858. }
  859. }
  860. // 获取当前版本号
  861. -(NSString *)jsGetVersion:(NSString *)str{
  862. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  863. }
  864. // web是否可退回上页面
  865. -(int)jsIsCanBack:(NSString *)str{
  866. return self.webView.canGoBack ? 1:0;
  867. }
  868. // 弹框
  869. -(void)jsAlert:(NSString *)content{
  870. [[LXViewControllerManager shareViewControllerManager] showAlertViewWithMessage:content];
  871. }
  872. // 是否安装微信
  873. -(int)jsIsInstallWeixin:(NSString *)str{
  874. return [LXUserDefaults isInstallWeiXin];
  875. }
  876. -(void)jsChangeMessageType:(NSString *)link
  877. {
  878. //已读操作处理
  879. NSLog(@"已读操作处理-更改");
  880. [[LXDataBaseManager shareDataBaseManager] changeCatagoryTypeWithURL:link];
  881. }
  882. -(void)jsOpenActivityPage:(NSString *)url rectype:(NSString *)rectype openid:(NSString *)openid
  883. {
  884. NSDictionary * infoDic = @{@"url":url,
  885. @"rectype":rectype,
  886. @"openid":openid,
  887. };
  888. // NSString *textJS = [NSString stringWithFormat:@"messageAccept('%@','%@','%@')",infoDic[@"mid"],infoDic[@"rectype"],infoDic[@"openid"]];
  889. // JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  890. // [context evaluateScript:textJS];
  891. //post请求
  892. NSLog(@"%@",[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost]);
  893. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost] parameters:infoDic progress:^(NSProgress *progress) {
  894. NSLog(@"成功:%@",progress);
  895. } success:^(id responseObject) {
  896. NSLog(@"responseObject=%@",responseObject);
  897. } failure:^(NSError *error) {
  898. NSLog(@"error=%@",error);
  899. }];
  900. }
  901. -(NSString *)jsGGetCipherText:(NSString *)phone
  902. {
  903. NSDate *date=[NSDate date];
  904. NSDateFormatter *format1=[[NSDateFormatter alloc] init];
  905. [format1 setDateFormat:@"yyyyMMddhhmmss"];
  906. NSString *dateStr;
  907. dateStr=[format1 stringFromDate:date];
  908. NSLog(@"%@",dateStr);
  909. NSString *content = [[NSString stringWithFormat:@"%@_%@",phone,dateStr] stringByAppendingString:[NSString stringWithFormat:@"_%@",[LXMD5 md532BitLower:[NSString stringWithFormat:@"%@&%@",phone,dateStr]]]];
  910. NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
  911. NSUInteger dataLength = contentData.length;
  912. // 为结束符'\\0' +1
  913. char keyPtr[kKeySize_0 + 1];
  914. memset(keyPtr, 0, sizeof(keyPtr));
  915. [AesKey_0 getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
  916. // 密文长度 <= 明文长度 + BlockSize
  917. size_t encryptSize = dataLength + kCCBlockSizeAES128;
  918. void *encryptedBytes = malloc(encryptSize);
  919. size_t actualOutSize = 0;
  920. NSData *initVector = [kInitVector_0 dataUsingEncoding:NSUTF8StringEncoding];
  921. CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
  922. kCCAlgorithmAES,
  923. kCCOptionPKCS7Padding, // 系统默认使用 CBC,然后指明使用 PKCS7Padding
  924. keyPtr,
  925. kKeySize_0,
  926. initVector.bytes,
  927. contentData.bytes,
  928. dataLength,
  929. encryptedBytes,
  930. encryptSize,
  931. &actualOutSize);
  932. if (cryptStatus == kCCSuccess) {
  933. // 对加密后的数据进行 base64 编码
  934. return [[NSData dataWithBytesNoCopy:encryptedBytes length:actualOutSize] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  935. }
  936. free(encryptedBytes);
  937. return nil;
  938. }
  939. //-(void)jsRedirectKeyset:(NSString*)str
  940. //{
  941. // [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshDY" object:nil userInfo:nil];
  942. // [self performSelector:@selector(nextVC) withObject:nil afterDelay:0.5];
  943. //}
  944. //
  945. //
  946. //-(void)nextVC
  947. //{
  948. // AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  949. // JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  950. // tab.selectedIndex = 1;
  951. //
  952. // [self webViewFirstRequest];
  953. //}
  954. //通知刷新页面
  955. //-(void)refreshSS:(NSNotification *)notificaition{
  956. //
  957. // refreshTabBool = YES;
  958. // [self webViewFirstRequest];
  959. //}
  960. -(void)jsHideRedSpotOnMenu:(NSString*)str
  961. {
  962. NSLog(@"search隐藏:%@",str);
  963. if([str isEqualToString:@"subscribe"]) {
  964. kMainQueue(^{
  965. [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
  966. });
  967. }
  968. if([str isEqualToString:@"my"]) {
  969. kMainQueue(^{
  970. [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  971. });
  972. }
  973. }
  974. -(void)jsShowRedSpotOnMenu:(NSString*)str
  975. {
  976. NSLog(@"search展示:%@",str);
  977. if([str isEqualToString:@"subscribe"]) {
  978. kMainQueue(^{
  979. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  980. });
  981. }
  982. if([str isEqualToString:@"my"]) {
  983. kMainQueue(^{
  984. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  985. });
  986. }
  987. }
  988. -(void)jsClearPushMessage:(NSString*)type
  989. {
  990. NSLog(@"清除通知栏");
  991. kMainQueue(^{
  992. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
  993. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  994. });
  995. }
  996. #pragma mark 支付相关
  997. -(void)jsWxPay:(NSString *)jsonString
  998. {
  999. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装wx
  1000. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先安装微信再进行支付!" delay:1.5];
  1001. return;
  1002. }
  1003. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  1004. NSError *err;
  1005. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
  1006. if(err) {
  1007. NSLog(@"json解析失败:%@",err);
  1008. return;
  1009. }
  1010. //吊起微信
  1011. PayReq *request = [[PayReq alloc] init] ;
  1012. request.openID = dic[@"Appid"];
  1013. request.partnerId = dic[@"Partnerid"];
  1014. request.prepayId= dic[@"Prepayid"];
  1015. request.package = @"Sign=WXPay";
  1016. request.nonceStr= dic[@"Noncestr"];
  1017. request.timeStamp= [dic[@"Timestamp"] intValue];
  1018. request.sign= dic[@"Sign"];
  1019. kMainQueue(^{
  1020. [WXApi sendReq:request];
  1021. });
  1022. }
  1023. -(void)jsAliPay:(NSString*)str
  1024. {
  1025. kMainQueue(^{
  1026. [[AlipaySDK defaultService] payOrder:str fromScheme:@"jianyuiosapp" callback:nil];
  1027. });
  1028. }
  1029. #pragma mark 原生通知相关
  1030. -(NSString *)jsGetOtherPushRid:(NSString *)str
  1031. {
  1032. NSLog(@"取deviceToken:%@",[LXUserDefaults deviceToken]);
  1033. return [LXUserDefaults deviceToken];
  1034. }
  1035. -(NSString *)jsGetPhoneBrand:(NSString *)str
  1036. {
  1037. UIDevice *device = [UIDevice currentDevice];
  1038. return device.platformString;
  1039. }
  1040. -(void)jsChooseTab:(int)indexTab
  1041. {
  1042. kMainQueue((^{
  1043. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1044. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  1045. tab.selectedIndex = indexTab;
  1046. pushIndex = indexTab;
  1047. }));
  1048. }
  1049. //刷新页面方法
  1050. -(void)jsCheckLab:(NSString*)str
  1051. {
  1052. [[NSNotificationCenter defaultCenter] postNotificationName:RefreshNonCurVC object:nil userInfo:nil];
  1053. }
  1054. //获取定位相关
  1055. -(NSString *)jsGetLocation:(NSString *)str
  1056. {
  1057. NSLog(@"------开始调用获取位置");
  1058. // 1.检查定位服务是否开启
  1059. if ([self checkLocationServiceIsEnabled]) {
  1060. // 2.创建定位管理器:
  1061. [self createCLManager];
  1062. }else{
  1063. NSLog(@"定位不可用");
  1064. }
  1065. NSLog(@"即将返回城市信息-%@",self.placeAdr);
  1066. return self.placeAdr;
  1067. }
  1068. - (BOOL)checkLocationServiceIsEnabled{
  1069. // 该方法是类方法,和我们创建的管理器没有关系
  1070. if ([CLLocationManager locationServicesEnabled]) {
  1071. return YES;
  1072. }
  1073. return NO;
  1074. }
  1075. - (void)createCLManager{
  1076. // 创建CoreLocation管理对象
  1077. self.locaationManager = [[CLLocationManager alloc]init];
  1078. // 设定定位精准度
  1079. [self.locaationManager setDesiredAccuracy:kCLLocationAccuracyBest];
  1080. // 设定DistanceFilter可以在用户移动指定距离之后触发更新事件(100米更新一次)
  1081. [self.locaationManager setDistanceFilter:100.f];
  1082. // 设置代理
  1083. self.locaationManager.delegate = self;
  1084. // 开始更新定位
  1085. [self.locaationManager startUpdatingLocation];
  1086. }
  1087. // 代理方法,更新位置
  1088. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
  1089. CLLocation * newLocation = [locations lastObject];
  1090. // 判空处理
  1091. if (newLocation.horizontalAccuracy < 0) {
  1092. return;
  1093. }
  1094. CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  1095. [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
  1096. for (CLPlacemark *placeMark in placemarks) {
  1097. //NSLog(@"位置:%@", placeMark.name);
  1098. //NSLog(@"街道:%@", placeMark.thoroughfare);
  1099. //NSLog(@"子街道:%@", placeMark.subThoroughfare);
  1100. //NSLog(@"区\\县:%@", placeMark.subLocality);
  1101. //NSLog(@"市:%@", placeMark.locality);
  1102. //NSLog(@"行政区:%@", placeMark.administrativeArea);
  1103. //NSLog(@"国家:%@", placeMark.country);
  1104. self.placeAdr = [placeMark.administrativeArea stringByAppendingString:[NSString stringWithFormat:@"-%@",placeMark.locality]];
  1105. }
  1106. }];
  1107. // [self.locaationManager stopUpdatingLocation];
  1108. // self.locaationManager.delegate=nil;
  1109. // //获取定位经纬度
  1110. // CLLocationCoordinate2D coor2D = newLocation.coordinate;
  1111. // NSLog(@"纬度为:%f, 经度为:%f", coor2D.latitude, coor2D.longitude);
  1112. //
  1113. // // 获取定位海拔高度
  1114. // CLLocationDistance altitude = newLocation.altitude;
  1115. // NSLog(@"高度为:%f", altitude);
  1116. //
  1117. // // 获取定位水平精确度, 垂直精确度
  1118. // CLLocationAccuracy horizontalAcc = newLocation.horizontalAccuracy;
  1119. // CLLocationAccuracy verticalAcc = newLocation.verticalAccuracy;
  1120. // NSLog(@"%f, %f", horizontalAcc, verticalAcc);
  1121. }
  1122. // 代理方法,定位权限检查
  1123. -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
  1124. switch (status) {
  1125. case kCLAuthorizationStatusNotDetermined:{
  1126. NSLog(@"用户还未决定授权");
  1127. // 主动获得授权
  1128. [self.locaationManager requestWhenInUseAuthorization];
  1129. break;
  1130. }
  1131. case kCLAuthorizationStatusRestricted:
  1132. {
  1133. NSLog(@"访问受限");
  1134. // 主动获得授权
  1135. [self.locaationManager requestWhenInUseAuthorization];
  1136. break;
  1137. }
  1138. case kCLAuthorizationStatusDenied:{
  1139. // 此时使用主动获取方法也不能申请定位权限
  1140. // 类方法,判断是否开启定位服务
  1141. if ([CLLocationManager locationServicesEnabled]) {
  1142. NSLog(@"定位服务开启,被拒绝");
  1143. } else {
  1144. NSLog(@"定位服务关闭,不可用");
  1145. }
  1146. break;
  1147. }
  1148. case kCLAuthorizationStatusAuthorizedAlways:{
  1149. NSLog(@"获得前后台授权");
  1150. break;
  1151. }
  1152. case kCLAuthorizationStatusAuthorizedWhenInUse:{
  1153. NSLog(@"获得前台授权");
  1154. break;
  1155. }
  1156. default:
  1157. break;
  1158. }
  1159. }
  1160. /*
  1161. #pragma mark - Navigation
  1162. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1163. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1164. // Get the new view controller using [segue destinationViewController].
  1165. // Pass the selected object to the new view controller.
  1166. }
  1167. */
  1168. @end