JYSearchViewController.m 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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. @protocol JYSearchViewControllerJSExport<JSExport>
  11. JSExportAs(loginByWeixin, -(NSString *)jsLoginByWeixin:(NSString *)str);// 微信登录 openid
  12. JSExportAs(share, -(void)jsShare:(NSString *)type title:(NSString *)title content:(NSString *)content link:(NSString *)link); // 调用分享
  13. JSExportAs(saveUserToken, -(void)jsSaveUserToken:(NSString *)token);// 登录时获取令牌 保存
  14. JSExportAs(getUserToken, -(NSString *)jsGetUserToken:(NSString *)str);// 取本地存的令牌
  15. JSExportAs(removeUserToken, -(void)jsRemoveUserToken:(NSString *)str); // 退出时清空数据
  16. JSExportAs(checkNoticePermission, -(int)jsCheckNoticePermission:(NSString *)str); // 查询手机通知是否打开
  17. JSExportAs(openSystemNotification, -(void)jsOpenSystemNotification:(NSString *)str);// 跳转到系统设置
  18. JSExportAs(getPushRid, -(NSString *)jsGetPushRid:(NSString *)str);// 返回极光id
  19. JSExportAs(getMessageList, -(NSString *)jsGetMessageList:(NSString *)openid);// 按通知接收时间倒排,取前100条
  20. JSExportAs(updateMessageState, -(void)jsUpdateMessageState:(NSString *)lxID state:(NSString *)state);// 更新状态
  21. JSExportAs(deleteMessageById, -(void)jsDeleteMessageById:(NSString *)lxID);// 删除一条消息
  22. JSExportAs(getMessage, -(NSString *)jsGetMessage:(NSString *)lxID);// 取单条数据
  23. JSExportAs(getUnReadMessageCount, -(int)jsGetUnReadMessageCount:(NSString *)openid);// 获取未读消息总数
  24. JSExportAs(updateAllUnReadMessage, -(void)jsUpdateAllUnReadMessage:(NSString *)openid);// 全部置为已读
  25. JSExportAs(lightStatusBar, -(void)jsLightStatusBar:(NSString *)status);// 导航栏文字颜色
  26. JSExportAs(openExternalLink, -(void)jsOpenExternalLink:(NSString *)url title:(NSString *)title);// 打开新控制器 加载新web
  27. JSExportAs(getVersion, -(NSString *)jsGetVersion:(NSString *)str);// 获取当前版本号
  28. JSExportAs(alert, -(void)jsAlert:(NSString *)content);// 弹框
  29. JSExportAs(isInstallWeixin, -(int)jsIsInstallWeixin:(NSString *)str);// 是否安装微信
  30. JSExportAs(changeMessageType, -(void)jsChangeMessageType:(NSString *)link);//已读操作处理
  31. JSExportAs(openActivityPage, -(void)jsOpenActivityPage:(NSString *)url rectype:(NSString *)rectype openid:(NSString *)openid);
  32. JSExportAs(getCipherText, -(NSString *)jsGGetCipherText:(NSString *)phone);
  33. JSExportAs(business, -(NSInteger)jsBusiness:(NSInteger)shooID shopType:(NSInteger )shopType);
  34. //新增
  35. JSExportAs(hiddenBottom, -(void)jsHiddenBottom:(NSString*)hidden);
  36. JSExportAs(loginSuccess, -(void)jsLoginSuccess:(NSString*)status);
  37. JSExportAs(backUrl, -(void)jsBackUrl:(NSString*)str);
  38. JSExportAs(redirectKeyset, -(void)jsRedirectKeyset:(NSString*)str);
  39. @end
  40. @interface JYSearchViewController ()<UIWebViewDelegate, JYSearchViewControllerJSExport>
  41. {
  42. CGPoint startTouch;
  43. BOOL _isMoving;
  44. NSInteger pushIndex;
  45. NSInteger _timeTick;
  46. NSInteger _time;
  47. BOOL autologin;
  48. BOOL notiFinish;
  49. BOOL expRefreshBool; //实验室 是否刷新
  50. }
  51. @property(nonatomic, strong)UIWebView *webView;
  52. //@property (weak, nonatomic) IBOutlet UIWebView *webView;
  53. @property(nonatomic, assign)BOOL updateNotify;
  54. @property(nonatomic, assign)BOOL afterOpenPushMessage;
  55. @property(nonatomic, strong)NoNetView *noNetView;
  56. @property(nonatomic, strong)NSURLRequest *errRequest;
  57. @property(nonatomic, strong)NSString *signOutContent;
  58. @property (nonatomic, strong)NSMutableDictionary *notiDict;
  59. @property (nonatomic,weak)NSTimer *timer;
  60. @end
  61. NSString *const kInitVector_0 = @"1389461544135476";
  62. size_t const kKeySize_0 = kCCKeySizeAES128;
  63. NSString *const AesKey_0 = @"mGlAgnIBB8bx2nch";
  64. @implementation JYSearchViewController
  65. -(void)viewWillAppear:(BOOL)animated
  66. {
  67. [super viewWillAppear:animated];
  68. [self.navigationController setNavigationBarHidden:YES animated:animated];
  69. }
  70. - (void)viewDidLoad {
  71. [super viewDidLoad];
  72. self.view.backgroundColor = [UIColor whiteColor];
  73. self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT)];
  74. [self.view addSubview: self.webView];
  75. self.webView.scrollView.bounces = NO;
  76. self.webView.delegate = self;
  77. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  78. [self webViewFirstRequest];//请求页面数据
  79. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestWebView:) name:kRequestWebViewWithUrl object:nil];
  80. //点击订阅通知
  81. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickSubNotiMethods:) name:ClickSubNotiMethods object:nil];
  82. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNotifyState) name:kUpdateNotifyState object:nil];
  83. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(afterReceiveNewMsg) name:kAfterReceiveNewMsg object:nil];
  84. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadWebView) name:kReloadWebVIew object:nil];
  85. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut:) name:kLoginOut object:nil];
  86. [[AFNetworkReachabilityManager sharedManager] startMonitoring];
  87. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
  88. //前往登录通知-tabbar
  89. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isLoginTabBar:) name:@"isLoginTabBar" object:nil];
  90. UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)];
  91. [recognizer delaysTouchesBegan];
  92. [self.view addGestureRecognizer:recognizer];
  93. //手势
  94. // [self clearWeb];
  95. //新增监听
  96. self.notiDict = [[NSMutableDictionary alloc]initWithDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"NotiDict"]];
  97. if(self.notiDict.count) {
  98. self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
  99. }
  100. //新增刷新通知
  101. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshSS:) name:@"refreshSS" object:nil];
  102. //展示底部红的通知
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newsRedPoint:) name:JYNewsRedPoint object:nil];
  104. //是否需要显示小红点
  105. [self haveRedPoint];
  106. }
  107. -(void)newsRedPoint:(NSNotification *)notificaition
  108. {
  109. NSDictionary *dict = notificaition.userInfo;
  110. NSLog(@"%@",dict);
  111. NSInteger type = [dict[@"type"] integerValue];
  112. if(type==1) {
  113. //显示
  114. kMainQueue(^{
  115. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  116. });
  117. }else if (type==2) {
  118. //显示
  119. kMainQueue(^{
  120. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  121. });
  122. }else {
  123. }
  124. NSString *textJS = [NSString stringWithFormat:@"afterReceivePushMessage('%@','%@')",dict[@"typeMsg"],dict[@"url"]];
  125. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  126. [context evaluateScript:textJS];
  127. }
  128. -(void)haveRedPoint
  129. {
  130. NSString *token = [LXUserDefaults token];
  131. if (token) {
  132. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/showRedSpotOnMenu",kHost] parameters:@{@"token":token} progress:^(NSProgress *progress) {
  133. NSLog(@"%@",progress);
  134. } success:^(id responseObject) {
  135. NSLog(@"responseObject=%@",responseObject);
  136. if([responseObject[@"subscribe"] integerValue]>=1) {
  137. //显示
  138. kMainQueue(^{
  139. [self.tabBarController.tabBar showBadgeOnItemIndex:1];
  140. });
  141. }else {
  142. kMainQueue(^{
  143. [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
  144. });
  145. }
  146. if([responseObject[@"my"] integerValue]>=1) {
  147. //显示
  148. kMainQueue(^{
  149. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  150. });
  151. }else {
  152. kMainQueue(^{
  153. [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  154. });
  155. }
  156. } failure:^(NSError *error) {
  157. NSLog(@"error=%@",error);
  158. }];
  159. }
  160. }
  161. //2.5.1
  162. -(void)timeFireMethod{
  163. _timeTick++;
  164. NSLog(@"定时器");
  165. if(self.webView&&notiFinish) {
  166. NSString * urlStr = [NSString stringWithFormat:@"%@",self.notiDict[@"info"][@"url"]];
  167. if (urlStr) {
  168. if([self.notiDict[@"type"] isEqualToString:@"bid"]) {
  169. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  170. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  171. tab.selectedIndex = 1;
  172. }else {
  173. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  174. self.afterOpenPushMessage = YES;
  175. [self performSelector:@selector(requestWebTime:) withObject:self.notiDict afterDelay:1];
  176. }
  177. [self.timer invalidate];
  178. self.timer = nil;
  179. _timeTick = 0;
  180. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"NotiDict"];
  181. }
  182. return;
  183. }
  184. if (_timeTick == 60) {
  185. [self.timer invalidate];
  186. self.timer = nil;
  187. _timeTick = 0;
  188. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"NotiDict"];
  189. }
  190. }
  191. -(void)moveViewWithX:(float)x
  192. {
  193. CGRect rect = self.view.bounds;
  194. CGFloat width = CGRectGetWidth(rect);
  195. x = x>width?width:x;
  196. x = x<0?0:x;
  197. CGRect frame = self.webView.frame;
  198. frame.origin.x = x;
  199. self.webView.frame = frame;
  200. }
  201. #pragma mark – Gesture Recognizer –
  202. -(void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer
  203. {
  204. NSString *current_url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  205. NSLog(@"当前页面:%@",current_url);
  206. CGRect rect = self.view.bounds;
  207. CGFloat width = CGRectGetWidth(rect);
  208. if (![self.webView canGoBack]) {
  209. NSLog(@"不可返回");
  210. return;
  211. }
  212. if([current_url containsString:@"jyapp/free/login"]) {
  213. return;
  214. }
  215. // NSString *current_url = self.webView.request.URL.absoluteString;
  216. 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/wxkeyset/keyset/index",kHost]]||[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/mainSearch",kHost]]){
  217. return;
  218. }
  219. //https://www.jianyu360.com/jyapp/free/me
  220. //https://www.jianyu360.com/jyapp/jylab/index
  221. //https://www.jianyu360.com/jyapp/wxkeyset/keyset/index
  222. //https://www.jianyu360.com/jyapp/jylab/mainSearch
  223. CGPoint touchPoint = [recoginzer locationInView:[UIApplication sharedApplication].keyWindow];
  224. if (recoginzer.state==UIGestureRecognizerStateBegan) {
  225. _isMoving = YES;
  226. startTouch = touchPoint;
  227. } else if (recoginzer.state==UIGestureRecognizerStateEnded){
  228. if (touchPoint.x - startTouch.x > width*0.125) {
  229. [UIView animateWithDuration:0.3 animations:^{
  230. [self moveViewWithX:width];
  231. [self.webView goBack];
  232. } completion:^(BOOL finished) {
  233. _isMoving = NO;
  234. [self moveViewWithX:0];
  235. }];
  236. } else {
  237. [UIView animateWithDuration:0.3 animations:^{
  238. [self moveViewWithX:0];
  239. } completion:^(BOOL finished) {
  240. _isMoving = NO;
  241. }];
  242. }
  243. return;
  244. } else if (recoginzer.state==UIGestureRecognizerStateCancelled){
  245. [UIView animateWithDuration:0.3 animations:^{
  246. [self moveViewWithX:0];
  247. } completion:^(BOOL finished) {
  248. _isMoving = NO;
  249. }];
  250. return;
  251. }
  252. if (_isMoving) {
  253. [self moveViewWithX:touchPoint.x - startTouch.x];
  254. }
  255. }
  256. // 监控网络状态变化
  257. -(void)netReachChanged:(NSNotification *)notificaition{
  258. NSDictionary *userInfo = notificaition.userInfo;
  259. if ([userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == 0 || [userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == -1) {
  260. [self addNoNetViews];
  261. }else{
  262. if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"firstLoad"] intValue] == 0) {
  263. [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"firstLoad"];
  264. [self removeNoNetViews];
  265. [self webViewFirstRequest];
  266. }
  267. }
  268. }
  269. // 再次加载页面
  270. -(void)reloadWebView{
  271. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  272. if (!self.webView.canGoBack) {
  273. [self webViewFirstRequest];
  274. }else{
  275. [self.webView reload];
  276. }
  277. }
  278. // 首次加载web
  279. -(void)webViewFirstRequest{
  280. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/index"];
  281. NSString *token = [LXUserDefaults token];
  282. if (token) {
  283. url = [url stringByAppendingString:[NSString stringWithFormat:@"?sign=%@&url=/jyapp/jylab/mainSearch&from=restart", token]];
  284. }
  285. NSLog(@"111第一次加载%@",url);
  286. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  287. //[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:20]];
  288. kMainQueue(^{
  289. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  290. })
  291. }
  292. //收到消息退出并重新加载web
  293. -(void)webViewRequestByMsg{
  294. // NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/kicked"];
  295. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login?back=index&isios=t"];
  296. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  297. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  298. }
  299. -(void)requestWebTime:(NSDictionary *)infoDict
  300. {
  301. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  302. if([infoDict[@"type"] isEqualToString:@"message"]) {
  303. NSString *url = [NSString stringWithFormat:@"%@",urlStr];
  304. NSArray * array = [url componentsSeparatedByString:@"=="];
  305. url = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  306. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  307. [[NSNotificationCenter defaultCenter] postNotificationName:@"kNewWebControllerDismiss" object:nil];
  308. //
  309. }else {
  310. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, urlStr];
  311. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  312. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  313. [[NSNotificationCenter defaultCenter] postNotificationName:@"kNewWebControllerDismiss" object:nil];
  314. }
  315. }
  316. // 点击通知 跳转到通知内url
  317. -(void)requestWebView:(NSNotification *)notification{
  318. NSDictionary * infoDict = [notification object];
  319. if (!infoDict) {
  320. return;
  321. }
  322. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  323. if (urlStr) {
  324. //当前控制器
  325. if(self.tabBarController.selectedIndex != 0) {
  326. return;
  327. }else {
  328. [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshMine" object:nil];;
  329. }
  330. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  331. self.afterOpenPushMessage = YES;
  332. [self performSelector:@selector(requestWebTime:) withObject:infoDict afterDelay:1];
  333. }
  334. }
  335. -(void)clickSubNotiMethods:(NSNotification *)notification{
  336. NSDictionary * infoDict = [notification object][@"info"];
  337. if (!infoDict) {
  338. return;
  339. }
  340. NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
  341. if (urlStr) {
  342. if(self.tabBarController.selectedIndex == 0) {
  343. //底部栏置换到订阅
  344. [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshDY" object:nil userInfo:nil];
  345. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  346. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  347. tab.selectedIndex = 1;
  348. }
  349. }
  350. }
  351. // 收到通知消息
  352. -(void)afterReceiveNewMsg{
  353. NSLog(@"afterReceiveNewMsg");
  354. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  355. [context evaluateScript:@"afterReceiveNewMsg()"];
  356. }
  357. // 收到退出登录消息
  358. -(void)loginOut:(NSNotification *)notification{
  359. if([notification.userInfo[@"item_index"] integerValue]!=0) {
  360. return;
  361. }
  362. self.signOutContent = notification.object;
  363. if (!self.signOutContent) {
  364. self.signOutContent = @"1";
  365. }
  366. NSString *url = [NSString stringWithFormat:@"%@%@?sign=%@", kHost, @"jyapp/free/signOut", [LXUserDefaults token]];
  367. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  368. // UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
  369. // webView.delegate = self;
  370. // [self.view addSubview:webView];
  371. // [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  372. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  373. [self jsRemoveUserToken:nil];
  374. }
  375. //前往登录页面
  376. -(void)isLoginTabBar:(NSNotification *)notification
  377. {
  378. NSDictionary *dict = notification.userInfo;
  379. //
  380. NSLog(@"我从第几个页面过来:%@",dict[@"item_index"]);
  381. pushIndex = [dict[@"item_index"] integerValue];
  382. //
  383. NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login"];
  384. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  385. [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
  386. // NSString *index = [NSString stringWithFormat:@"%ld",pushIndex];
  387. // [[NSNotificationCenter defaultCenter] postNotificationName:@"isLoginTabBar" object:nil userInfo:@{@"item_index":index}];
  388. }
  389. //js返回首页
  390. -(void)jsBackUrl:(NSString*)str
  391. {
  392. NSLog(@"search返回首页,search返回首页,search返回首页,search返回首页,search返回首页,search返回首页");
  393. if([str isEqualToString:@"H"]) {
  394. pushIndex = 0;
  395. [self webViewFirstRequest];
  396. }
  397. }
  398. //js方法登录成功
  399. -(void)jsLoginSuccess:(NSString*)status
  400. {
  401. NSLog(@"Search登录成功提示;;;%@当前下标:%ld",status,(long)pushIndex);
  402. //显示
  403. kMainQueue(^{
  404. [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  405. });
  406. if([status isEqualToString:@"S"]) {
  407. if(pushIndex!=0) {
  408. NSLog(@"SSSSSS");
  409. kMainQueue((^{
  410. NSString *index = [NSString stringWithFormat:@"%ld",pushIndex];
  411. [[NSNotificationCenter defaultCenter] postNotificationName:@"changeItems" object:nil userInfo:@{@"item_index":index}];
  412. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  413. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  414. tab.selectedIndex = pushIndex;
  415. pushIndex = 0;
  416. }));
  417. }else {
  418. [self webViewFirstRequest];
  419. }
  420. }else if ([status isEqualToString:@""]) {
  421. //手动tabbar点击
  422. NSLog(@"statusstatusstatusstatusstatusstatusstatusstatusstatusstatus=======%@",status);
  423. // NSString *index = [NSString stringWithFormat:@"%ld",pushIndex];
  424. // [[NSNotificationCenter defaultCenter] postNotificationName:@"changeItems" object:nil userInfo:@{@"item_index":index}];
  425. // pushIndex = 0;
  426. //刷新 订阅 和 我的
  427. [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshAllVC" object:nil userInfo:nil];
  428. //首页跳转登录刷新 我们+订阅
  429. }else {
  430. }
  431. }
  432. -(void)dealTabBar
  433. {
  434. NSLog(@"刷新第一个页面");
  435. kMainQueue(^{
  436. // [self showTabBar];
  437. // self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
  438. [self webViewFirstRequest];
  439. });
  440. }
  441. - (void)hideTabBar {
  442. NSLog(@"隐藏tabbar");
  443. kMainQueue(^{
  444. if (self.tabBarController.tabBar.hidden == YES) {
  445. return;
  446. }
  447. UIView *contentView;
  448. if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
  449. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  450. else
  451. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  452. 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);
  453. self.tabBarController.tabBar.hidden = YES;
  454. });
  455. }
  456. - (void)showTabBar{
  457. kMainQueue(^{
  458. if (self.tabBarController.tabBar.hidden == NO)
  459. {
  460. return;
  461. }
  462. UIView *contentView;
  463. if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
  464. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  465. else
  466. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  467. 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);
  468. self.tabBarController.tabBar.hidden = NO;
  469. });
  470. }
  471. -(void)jsHiddenBottom:(NSString *)hidden
  472. {
  473. NSLog(@"让我展示隐藏bottom==%@",hidden);
  474. if([hidden integerValue]==0) {
  475. [self hideTabBar];
  476. kMainQueue(^{
  477. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
  478. });
  479. }else {
  480. [self showTabBar];
  481. kMainQueue(^{
  482. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
  483. });
  484. }
  485. }
  486. -(void)judgeIsHidden
  487. {
  488. NSString *current_url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
  489. //[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/index",kHost]]
  490. NSLog(@"%@",current_url);
  491. if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/jylab/mainSearch",kHost]]){
  492. NSLog(@"展示");
  493. [self showTabBar];
  494. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
  495. }else {
  496. NSLog(@"隐藏");
  497. [self hideTabBar];
  498. self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
  499. }
  500. }
  501. #pragma mark 捕获js中调用的方法
  502. //捕获js中调用的方法
  503. - (void)webViewDidFinishLoad:(UIWebView *)webView{
  504. if(!notiFinish) {
  505. notiFinish = YES;
  506. }
  507. if(expRefreshBool) {
  508. expRefreshBool = NO;
  509. }else {
  510. //正常的网页加载
  511. [self judgeIsHidden];//是否隐藏
  512. }
  513. [self removeNoNetViews];
  514. [[LXViewControllerManager shareViewControllerManager] hideHud];
  515. JSContext *context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  516. // Disable user selection
  517. [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
  518. // Disable callout
  519. [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
  520. context[@"JyObj"] = self;
  521. [context evaluateScript:@"afterPageInit()"];
  522. if (self.afterOpenPushMessage) {
  523. self.afterOpenPushMessage = NO;
  524. // [context evaluateScript:@"afterOpenPushMessage()"];
  525. [context evaluateScript:[NSString stringWithFormat:@"afterOpenPushMessage('%d')", [self jsIsCanBack:nil]]];
  526. }
  527. NSString *url = webView.request.URL.absoluteString;
  528. [self doSomeWithLoadUrl:url];
  529. //加载第一次成功的时候 调JS
  530. // if(!autologin&&[LXUserDefaults token]) {
  531. // autologin = YES;
  532. // NSString *textJS = [NSString stringWithFormat:@"refAutoLogin('%@')",@"S"];
  533. // JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  534. // [context evaluateScript:textJS];
  535. // }
  536. if(!autologin) {
  537. //第一次加载页面成功
  538. if([LXUserDefaults token]) {
  539. //如果登录
  540. NSString *textJS = [NSString stringWithFormat:@"refAutoLogin('%@')",@"S"];
  541. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  542. [context evaluateScript:textJS];
  543. }
  544. autologin = YES;
  545. }
  546. }
  547. //15737190152
  548. -(void)doSomeWithLoadUrl:(NSString *)url{
  549. if (!url) {
  550. return;
  551. }
  552. if ([url containsString:@"signOut"]) { // 收到退出消息后 跳转到登录页面
  553. // [self webViewFirstRequest];
  554. [self webViewRequestByMsg];
  555. }else if ([url containsString:@"/free/login"]){ // 如果通过接收消息 跳转到登录页面 展示消息内容
  556. if (self.signOutContent && ![self.signOutContent isEqualToString:@"1"]) {
  557. [[LXViewControllerManager shareViewControllerManager] showAlertViewWithTitle:@"提示" message:self.signOutContent actions:@[[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  558. self.signOutContent = nil;
  559. }]]];
  560. }else{
  561. self.signOutContent = nil;
  562. }
  563. }
  564. }
  565. -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
  566. [[LXViewControllerManager shareViewControllerManager] hideHud];
  567. NSString *url = webView.request.URL.absoluteString;
  568. [self doSomeWithLoadUrl:url];
  569. }
  570. -(void)webViewDidStartLoad:(UIWebView *)webView{
  571. // if ([[UIDevice currentDevice].systemVersion floatValue] < 10) {
  572. // [[LXViewControllerManager shareViewControllerManager] hideHud];
  573. // }
  574. }
  575. - (void)didReceiveMemoryWarning {
  576. [super didReceiveMemoryWarning];
  577. // [self clearWeb];
  578. // Dispose of any resources that can be recreated.
  579. }
  580. -(void)clearWeb{
  581. NSURLCache * cache = [NSURLCache sharedURLCache];
  582. [cache removeAllCachedResponses];
  583. [cache setDiskCapacity:0];
  584. [cache setMemoryCapacity:0];
  585. }
  586. -(void)addNoNetViews{
  587. kMainQueue(^{
  588. [self removeNoNetViews];
  589. self.noNetView = [NoNetView shareView];
  590. [self.view addSubview:self.noNetView];
  591. });
  592. }
  593. -(void)removeNoNetViews{
  594. if (self.noNetView ) {
  595. [self.noNetView removeFromSuperview];
  596. self.noNetView = nil;
  597. }
  598. }
  599. #pragma mark JS 回调
  600. // 微信登录
  601. -(NSString *)jsLoginByWeixin:(NSString *)str{
  602. if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装微信 不走友盟
  603. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"微信登录失败,没有安装微信" delay:1.5];
  604. return nil;
  605. }
  606. kMainQueue(^{
  607. [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
  608. UMSocialUserInfoResponse *resp = result;
  609. [self dealWXDic:(NSDictionary *)resp.originalResponse];
  610. [[LXViewControllerManager shareViewControllerManager] hideHud];
  611. }];
  612. });
  613. return nil;
  614. }
  615. // 处理微信登录获取到的数据
  616. -(void)dealWXDic:(NSDictionary *)dictionary{
  617. [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
  618. //如果获取到用户信息,即用户点击了“登录”,则进行用户信息获取
  619. if (dictionary.count > 0) {
  620. NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dictionary];
  621. if (dic) {
  622. [dic removeObjectForKey:@"privilege"];
  623. [dic removeObjectForKey:@"language"];
  624. double currDouble = [[NSDate date] timeIntervalSince1970];
  625. [dic setObject:[NSNumber numberWithLong:(long)currDouble] forKey:@"createtime"];
  626. // 拼接标志位
  627. 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"]];
  628. sign = [LXMD5 md532BitLower:sign];
  629. [dic setObject:sign forKey:@"sign"];
  630. NSString *endStr = [[LXViewControllerManager shareViewControllerManager] getJsonStr:dic];
  631. NSData *data = [endStr dataUsingEncoding:NSUTF8StringEncoding];
  632. endStr = [data base64EncodedStringWithOptions:0];
  633. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  634. NSString * textJS1 = [NSString stringWithFormat:@"loginByWeixinCallBack('%@')", endStr];
  635. JSValue *value = [context evaluateScript:textJS1];
  636. NSLog(@"%@", value);
  637. }
  638. }
  639. }
  640. // js 调用分享
  641. -(void)jsShare:(NSString *)type title:(NSString *)title content:(NSString *)content link:(NSString *)link{
  642. UMSocialPlatformType shareType;
  643. if ([type intValue] == 1) { // 微信好友
  644. shareType = UMSocialPlatformType_WechatSession;
  645. }else if ([type intValue] == 2){ /// qq好友
  646. shareType = UMSocialPlatformType_QQ;
  647. }else if ([type intValue] == 3){ // 朋友圈
  648. shareType = UMSocialPlatformType_WechatTimeLine;
  649. }else{
  650. shareType = UMSocialPlatformType_WechatSession;
  651. }
  652. kMainQueue((^{
  653. // 没有安装app 不走分享逻辑
  654. if ([type intValue] == 1 || [type intValue] == 3) {
  655. if ([LXUserDefaults isInstallWeiXin] != 1) {
  656. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装微信" delay:1.5];
  657. return;
  658. }
  659. }
  660. // 没有安装app 不走分享逻辑
  661. if ([type intValue] == 2) {
  662. if (![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ]) {
  663. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装QQ" delay:1.5];
  664. return;
  665. }
  666. }
  667. //创建分享消息对象
  668. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  669. //创建网页内容对象
  670. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:content thumImage:[UIImage imageNamed:@"logo"]];
  671. //设置网页地址
  672. shareObject.webpageUrl = link;
  673. messageObject.shareObject = shareObject;
  674. //调用分享接口
  675. [[UMSocialManager defaultManager] shareToPlatform:shareType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  676. if (error) {
  677. NSLog(@"22222222%@",error.userInfo);
  678. if (error.userInfo[@"message"] && [error.userInfo[@"message"] containsString:@"Operation is cancel"]) {
  679. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"取消分享" delay:1];
  680. }else{
  681. [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:error.userInfo[@"message"] delay:1];
  682. }
  683. NSString *textJS = [NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"0"];
  684. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  685. [context evaluateScript:textJS];
  686. }else{
  687. if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  688. UMSocialShareResponse *resp = data;
  689. NSLog(@"33333%@",resp.message);
  690. NSLog(@"44444%@",resp.originalResponse);
  691. NSString *textJS = [NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"1"];
  692. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  693. [context evaluateScript:textJS];
  694. }else{
  695. UMSocialLogInfo(@"response data is %@",data);
  696. NSLog(@"55555%@",data);
  697. }
  698. }
  699. }];
  700. }));
  701. }
  702. // 登录时获取到令牌 并保存
  703. -(void)jsSaveUserToken:(NSString *)token{
  704. NSLog(@"登陆成功");
  705. [[LXViewControllerManager shareViewControllerManager] hideHud];
  706. [LXUserDefaults saveToken:token];
  707. }
  708. // 取本地的用户令牌
  709. -(NSString *)jsGetUserToken:(NSString *)str{
  710. NSLog(@"取用户token");
  711. return [LXUserDefaults token];
  712. }
  713. // 退出时 清空用户数据
  714. -(void)jsRemoveUserToken:(NSString *)str{
  715. NSLog(@"清除用户token");
  716. [LXUserDefaults clearAll];
  717. // [[LXDataBaseManager shareDataBaseManager] clearAll];
  718. }
  719. // 手机通知权限是否打开
  720. -(int)jsCheckNoticePermission:(NSString *)str{
  721. int a = [LXUserDefaults notifyState];
  722. return a;
  723. }
  724. // 跳转到系统设置
  725. -(void)jsOpenSystemNotification:(NSString *)str{
  726. self.updateNotify = YES;
  727. kMainQueue(^{
  728. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  729. });
  730. }
  731. // 调用js方法 刷新推送权限状态
  732. -(void)updateNotifyState{
  733. if (self.updateNotify) {
  734. self.updateNotify = NO;
  735. JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  736. NSString * textJS1 = [NSString stringWithFormat:@"updateNoticeSwitch()"];
  737. [context evaluateScript:textJS1];
  738. }
  739. }
  740. // 获取推送id
  741. -(NSString *)jsGetPushRid:(NSString *)str{
  742. return [LXUserDefaults registrationID];
  743. }
  744. // 按通知取数据
  745. -(NSString *)jsGetMessageList:(NSString *)openid{
  746. NSArray *arr = [[LXDataBaseManager shareDataBaseManager] getMessageWithKey:nil openid:openid fromTable:kNewsTable start:0 length:100];
  747. if (arr.count > 0) {
  748. return [[LXViewControllerManager shareViewControllerManager] getJsonStr:arr];
  749. }
  750. return @"";
  751. }
  752. // 更新消息状态
  753. -(void)jsUpdateMessageState:(NSNumber *)lxID state:(NSNumber *)state{
  754. [[LXDataBaseManager shareDataBaseManager] changeReadedWithID:lxID state:state];
  755. }
  756. // 删除一条数据
  757. -(void)jsDeleteMessageById:(NSNumber *)lxID{
  758. [[LXDataBaseManager shareDataBaseManager] deleteMessage:lxID fromTable:kNewsTable];
  759. }
  760. // 取单条数据
  761. -(NSString *)jsGetMessage:(NSString *)lxID{
  762. return [[LXViewControllerManager shareViewControllerManager] getJsonStr:[[LXDataBaseManager shareDataBaseManager] getMessageWithKey:lxID openid:nil fromTable:kNewsTable start:0 length:0]];
  763. }
  764. // 取未读消息总数
  765. -(int)jsGetUnReadMessageCount:(NSString *)openid{
  766. NSLog(@"openid=%@",openid);
  767. // NSLog(@"%d",[[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid]);
  768. // if([[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid] ==0){
  769. // //显示
  770. // kMainQueue(^{
  771. // [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
  772. // });
  773. // }else {
  774. // kMainQueue(^{
  775. // [self.tabBarController.tabBar showBadgeOnItemIndex:3];
  776. // });
  777. // }
  778. return [[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid];
  779. }
  780. // 全部置为已读
  781. -(void)jsUpdateAllUnReadMessage:(NSString *)openid{
  782. [[LXDataBaseManager shareDataBaseManager] updateAllUnReadMessage:openid];
  783. }
  784. // 改变状态栏文字颜色
  785. -(void)jsLightStatusBar:(NSString *)status{
  786. kMainQueue(^{
  787. NSInteger index = 0;
  788. if ([status intValue] == 1) {
  789. index = 1;// hei
  790. }else{
  791. index = 0;// bai
  792. }
  793. [[UIApplication sharedApplication] setStatusBarStyle:index];
  794. });
  795. }
  796. // 打开新页面 加载新web
  797. -(void)jsOpenExternalLink:(NSString *)url title:(NSString *)title{
  798. if (url) {
  799. if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable || [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown) {
  800. // [self addNoNetViews];
  801. }
  802. NewWebController *ctr = [[NewWebController alloc] init];
  803. ctr.url = url;
  804. // 有title的话 会显示自定义的导航栏 没有的话不显示导航栏 显示加载进度条
  805. if (!title || [title isEqualToString:@""] || [title isEqualToString:@"undefined"]) {
  806. ctr.titleShow = nil;
  807. }else{
  808. ctr.titleShow = title;
  809. }
  810. kMainQueue(^{
  811. [self presentViewController:ctr animated:NO completion:nil];
  812. });
  813. }
  814. }
  815. // 获取当前版本号
  816. -(NSString *)jsGetVersion:(NSString *)str{
  817. return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  818. }
  819. // web是否可退回上页面
  820. -(int)jsIsCanBack:(NSString *)str{
  821. return self.webView.canGoBack ? 1:0;
  822. }
  823. // 弹框
  824. -(void)jsAlert:(NSString *)content{
  825. [[LXViewControllerManager shareViewControllerManager] showAlertViewWithMessage:content];
  826. }
  827. // 是否安装微信
  828. -(int)jsIsInstallWeixin:(NSString *)str{
  829. return [LXUserDefaults isInstallWeiXin];
  830. }
  831. -(void)jsChangeMessageType:(NSString *)link
  832. {
  833. //已读操作处理
  834. NSLog(@"已读操作处理-更改");
  835. [[LXDataBaseManager shareDataBaseManager] changeCatagoryTypeWithURL:link];
  836. }
  837. -(void)jsOpenActivityPage:(NSString *)url rectype:(NSString *)rectype openid:(NSString *)openid
  838. {
  839. NSDictionary * infoDic = @{@"url":url,
  840. @"rectype":rectype,
  841. @"openid":openid,
  842. };
  843. // NSString *textJS = [NSString stringWithFormat:@"messageAccept('%@','%@','%@')",infoDic[@"mid"],infoDic[@"rectype"],infoDic[@"openid"]];
  844. // JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
  845. // [context evaluateScript:textJS];
  846. //post请求
  847. NSLog(@"%@",[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost]);
  848. [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost] parameters:infoDic progress:^(NSProgress *progress) {
  849. NSLog(@"成功:%@",progress);
  850. } success:^(id responseObject) {
  851. NSLog(@"responseObject=%@",responseObject);
  852. } failure:^(NSError *error) {
  853. NSLog(@"error=%@",error);
  854. }];
  855. }
  856. -(NSString *)jsGGetCipherText:(NSString *)phone
  857. {
  858. NSDate *date=[NSDate date];
  859. NSDateFormatter *format1=[[NSDateFormatter alloc] init];
  860. [format1 setDateFormat:@"yyyyMMddhhmmss"];
  861. NSString *dateStr;
  862. dateStr=[format1 stringFromDate:date];
  863. NSLog(@"%@",dateStr);
  864. NSString *content = [[NSString stringWithFormat:@"%@_%@",phone,dateStr] stringByAppendingString:[NSString stringWithFormat:@"_%@",[LXMD5 md532BitLower:[NSString stringWithFormat:@"%@&%@",phone,dateStr]]]];
  865. NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
  866. NSUInteger dataLength = contentData.length;
  867. // 为结束符'\\0' +1
  868. char keyPtr[kKeySize_0 + 1];
  869. memset(keyPtr, 0, sizeof(keyPtr));
  870. [AesKey_0 getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
  871. // 密文长度 <= 明文长度 + BlockSize
  872. size_t encryptSize = dataLength + kCCBlockSizeAES128;
  873. void *encryptedBytes = malloc(encryptSize);
  874. size_t actualOutSize = 0;
  875. NSData *initVector = [kInitVector_0 dataUsingEncoding:NSUTF8StringEncoding];
  876. CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
  877. kCCAlgorithmAES,
  878. kCCOptionPKCS7Padding, // 系统默认使用 CBC,然后指明使用 PKCS7Padding
  879. keyPtr,
  880. kKeySize_0,
  881. initVector.bytes,
  882. contentData.bytes,
  883. dataLength,
  884. encryptedBytes,
  885. encryptSize,
  886. &actualOutSize);
  887. if (cryptStatus == kCCSuccess) {
  888. // 对加密后的数据进行 base64 编码
  889. return [[NSData dataWithBytesNoCopy:encryptedBytes length:actualOutSize] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
  890. }
  891. free(encryptedBytes);
  892. return nil;
  893. }
  894. -(void)jsRedirectKeyset:(NSString*)str
  895. {
  896. [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshDY" object:nil userInfo:nil];
  897. [self performSelector:@selector(nextVC) withObject:nil afterDelay:0.5];
  898. }
  899. -(void)nextVC
  900. {
  901. AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  902. JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
  903. tab.selectedIndex = 1;
  904. [self webViewFirstRequest];
  905. }
  906. //通知刷新页面
  907. -(void)refreshSS:(NSNotification *)notificaition{
  908. expRefreshBool = YES;
  909. [self webViewFirstRequest];
  910. }
  911. /*
  912. #pragma mark - Navigation
  913. // In a storyboard-based application, you will often want to do a little preparation before navigation
  914. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  915. // Get the new view controller using [segue destinationViewController].
  916. // Pass the selected object to the new view controller.
  917. }
  918. */
  919. @end