JYSearchViewController.m 43 KB

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