JYSearchViewController.m 44 KB

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