1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060 |
- //
- // JYSubViewController.m
- // JianYuIOS
- //
- // Created by apple on 2018/11/8.
- // Copyright © 2018年 lixianglan. All rights reserved.
- //
- #import "JYSubViewController.h"
- #import "JYTabBarController.h"
- @protocol JYSubViewControllerJSExport<JSExport>
- JSExportAs(loginByWeixin, -(NSString *)jsLoginByWeixin:(NSString *)str);// 微信登录 openid
- JSExportAs(share, -(void)jsShare:(NSString *)type title:(NSString *)title content:(NSString *)content link:(NSString *)link); // 调用分享
- JSExportAs(saveUserToken, -(void)jsSaveUserToken:(NSString *)token);// 登录时获取令牌 保存
- JSExportAs(getUserToken, -(NSString *)jsGetUserToken:(NSString *)str);// 取本地存的令牌
- JSExportAs(removeUserToken, -(void)jsRemoveUserToken:(NSString *)str); // 退出时清空数据
- JSExportAs(checkNoticePermission, -(int)jsCheckNoticePermission:(NSString *)str); // 查询手机通知是否打开
- JSExportAs(openSystemNotification, -(void)jsOpenSystemNotification:(NSString *)str);// 跳转到系统设置
- JSExportAs(getPushRid, -(NSString *)jsGetPushRid:(NSString *)str);// 返回极光id
- JSExportAs(getMessageList, -(NSString *)jsGetMessageList:(NSString *)openid);// 按通知接收时间倒排,取前100条
- JSExportAs(updateMessageState, -(void)jsUpdateMessageState:(NSString *)lxID state:(NSString *)state);// 更新状态
- JSExportAs(deleteMessageById, -(void)jsDeleteMessageById:(NSString *)lxID);// 删除一条消息
- JSExportAs(getMessage, -(NSString *)jsGetMessage:(NSString *)lxID);// 取单条数据
- JSExportAs(getUnReadMessageCount, -(int)jsGetUnReadMessageCount:(NSString *)openid);// 获取未读消息总数
- JSExportAs(updateAllUnReadMessage, -(void)jsUpdateAllUnReadMessage:(NSString *)openid);// 全部置为已读
- JSExportAs(lightStatusBar, -(void)jsLightStatusBar:(NSString *)status);// 导航栏文字颜色
- JSExportAs(openExternalLink, -(void)jsOpenExternalLink:(NSString *)url title:(NSString *)title);// 打开新控制器 加载新web
- JSExportAs(getVersion, -(NSString *)jsGetVersion:(NSString *)str);// 获取当前版本号
- JSExportAs(alert, -(void)jsAlert:(NSString *)content);// 弹框
- JSExportAs(isInstallWeixin, -(int)jsIsInstallWeixin:(NSString *)str);// 是否安装微信
- JSExportAs(changeMessageType, -(void)jsChangeMessageType:(NSString *)link);//已读操作处理
- JSExportAs(openActivityPage, -(void)jsOpenActivityPage:(NSString *)url rectype:(NSString *)rectype openid:(NSString *)openid);
- JSExportAs(getCipherText, -(NSString *)jsGGetCipherText:(NSString *)phone);
- JSExportAs(business, -(NSInteger)jsBusiness:(NSInteger)shooID shopType:(NSInteger )shopType);
- JSExportAs(loginSuccess, -(void)jsLoginSuccess:(NSString*)status);
- JSExportAs(backUrl, -(void)jsBackUrl:(NSString*)str);
- JSExportAs(hideRedSpotOnMenu, -(void)jsHideRedSpotOnMenu:(NSString*)str);
- JSExportAs(showRedSpotOnMenu, -(void)jsShowRedSpotOnMenu:(NSString*)str);
- JSExportAs(clearPushMessage, -(void)jsClearPushMessage:(NSString*)type);
- //支付相关
- JSExportAs(wxPay, -(void)jsWxPay:(NSString *)jsonString);
- JSExportAs(aliPay, -(void)jsAliPay:(NSString*)str);
- @end
- @interface JYSubViewController ()<UIWebViewDelegate, JYSubViewControllerJSExport>
- {
- CGPoint startTouch;
- BOOL _isMoving;
- }
- @property(nonatomic, strong)UIWebView *webView;
- @property(nonatomic, assign)BOOL updateNotify;
- @property(nonatomic, assign)BOOL afterOpenPushMessage;
- @property(nonatomic, strong)NoNetView *noNetView;
- @property(nonatomic, strong)NSURLRequest *errRequest;
- @end
- NSString *const kInitVector_1 = @"1389461544135476";
- size_t const kKeySize_1 = kCCKeySizeAES128;
- NSString *const AesKey_1 = @"mGlAgnIBB8bx2nch";
- @implementation JYSubViewController
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:YES animated:animated];
-
- if([GlobalData shareInstance].isReLogin) {
- [GlobalData shareInstance].isReLogin = NO;
- [self webViewFirstRequest];
- }else {
- if([GlobalData shareInstance].subIsRed) {
- [GlobalData shareInstance].subIsRed = NO;
- [self webViewFirstRequest];
- }
- }
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT)];
- [self.view addSubview: self.webView];
- self.webView.scrollView.bounces = NO;
- self.webView.delegate = self;
-
- [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
- [self webViewFirstRequest];//请求页面数据
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestWebView:) name:kRequestWebViewWithUrl object:nil];
-
- //点击订阅通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickSubNotiMethods:) name:ClickSubNotiMethods object:nil];
- //点击支付通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickPayMethods:) name:ClickPayMethods object:nil];
-
- //支付状态通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayWXpayStatus:) name:AlipayWXpayStatus object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateNotifyState) name:kUpdateNotifyState object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(afterReceiveNewMsg) name:kAfterReceiveNewMsg object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadWebView) name:kReloadWebVIew object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut:) name:kLoginOut object:nil];
-
- [[AFNetworkReachabilityManager sharedManager] startMonitoring];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachChanged:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newsRedPoint:) name:JYNewsRedPoint object:nil];
-
- UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)];
- [recognizer delaysTouchesBegan];
- [self.view addGestureRecognizer:recognizer];
- //手势
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshDY:) name:@"refreshDY" object:nil];
-
-
-
-
- // [self clearWeb];
- }
- -(void)newsRedPoint:(NSNotification *)notificaition
- {
- NSDictionary *dict = notificaition.userInfo;
-
-
-
- if(self.tabBarController.selectedIndex == 1) {
-
- NSString *textJS = [NSString stringWithFormat:@"afterReceivePushMessage('%@','%@')",dict[@"typeMsg"],dict[@"url"]];
- NSLog(@"%@",textJS);
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- [context evaluateScript:textJS];
- }
- }
- -(void)moveViewWithX:(float)x
- {
- CGRect rect = self.view.bounds;
- CGFloat width = CGRectGetWidth(rect);
- x = x>width?width:x;
- x = x<0?0:x;
- CGRect frame = self.webView.frame;
- frame.origin.x = x;
- self.webView.frame = frame;
- }
- #pragma mark – Gesture Recognizer –
- -(void)paningGestureReceive:(UIPanGestureRecognizer *)recoginzer
- {
- CGRect rect = self.view.bounds;
- CGFloat width = CGRectGetWidth(rect);
- if (![self.webView canGoBack]) {
- NSLog(@"不可返回");
- return;
- }
-
- NSString *current_url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
- NSLog(@"当前页面:%@",current_url);
-
- if([current_url containsString:@"jyapp/free/login"]) {
- return;
- }
- // NSString *current_url = self.webView.request.URL.absoluteString;
- 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]]){
- return;
- }
-
- //https://www.jianyu360.com/jyapp/free/me
- //https://www.jianyu360.com/jyapp/jylab/index
- //https://www.jianyu360.com/jyapp/wxkeyset/keyset/index
- //https://www.jianyu360.com/jyapp/jylab/mainSearch
-
- CGPoint touchPoint = [recoginzer locationInView:[UIApplication sharedApplication].keyWindow];
- if (recoginzer.state==UIGestureRecognizerStateBegan) {
- _isMoving = YES;
- startTouch = touchPoint;
- } else if (recoginzer.state==UIGestureRecognizerStateEnded){
- if (touchPoint.x - startTouch.x > width*0.125) {
- [UIView animateWithDuration:0.3 animations:^{
- [self moveViewWithX:width];
- [self.webView goBack];
- } completion:^(BOOL finished) {
- _isMoving = NO;
- [self moveViewWithX:0];
- }];
- } else {
- [UIView animateWithDuration:0.3 animations:^{
- [self moveViewWithX:0];
- } completion:^(BOOL finished) {
- _isMoving = NO;
- }];
- }
- return;
- } else if (recoginzer.state==UIGestureRecognizerStateCancelled){
- [UIView animateWithDuration:0.3 animations:^{
- [self moveViewWithX:0];
- } completion:^(BOOL finished) {
- _isMoving = NO;
- }];
- return;
- }
- if (_isMoving) {
- [self moveViewWithX:touchPoint.x - startTouch.x];
- }
- }
- // 监控网络状态变化
- -(void)netReachChanged:(NSNotification *)notificaition{
- NSDictionary *userInfo = notificaition.userInfo;
- if ([userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == 0 || [userInfo[@"AFNetworkingReachabilityNotificationStatusItem"] intValue] == -1) {
- [self addNoNetViews];
- }else{
- [self removeNoNetViews];
- }
- }
- // 再次加载页面
- -(void)reloadWebView{
- [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
- if (!self.webView.canGoBack) {
- [self webViewFirstRequest];
- }else{
- [self.webView reload];
- }
-
- }
- // 首次加载web
- -(void)webViewFirstRequest{
-
- NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/swordfish/historypush"];
- //swordfish/historypush swordfish/historypush
- NSLog(@"222第一次加载%@",url);
- url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- kMainQueue(^{
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
- })
-
- }
- //收到消息退出并重新加载web
- -(void)webViewRequestByMsg{
- NSString *url = [NSString stringWithFormat:@"%@%@", kHost, @"jyapp/free/login?back=index&isios=t&flag=kicked"];
- url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
- }
- -(void)requestWebTime:(NSDictionary *)infoDict
- {
- NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
-
- if([infoDict[@"type"] isEqualToString:@"message"]) {
- NSString *url = [NSString stringWithFormat:@"%@",urlStr];
- NSArray * array = [url componentsSeparatedByString:@"=="];
- url = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"kNewWebControllerDismiss" object:nil];
- //
- }else {
- NSString *url = [NSString stringWithFormat:@"%@%@", kHost, urlStr];
- url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"kNewWebControllerDismiss" object:nil];
- }
-
- }
- // 点击通知 跳转到通知内url
- -(void)requestWebView:(NSNotification *)notification{
- NSDictionary * infoDict = [notification object];
- if (!infoDict) {
- return;
- }
- NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"info"][@"url"]];
-
- if (urlStr) {
-
- if(self.tabBarController.selectedIndex != 1) {
- return;
- }else {
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshMine" object:nil];;
- }
- [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
- self.afterOpenPushMessage = YES;
-
-
- [self performSelector:@selector(requestWebTime:) withObject:infoDict afterDelay:1];
- }
-
-
- }
- -(void)clickSubNotiMethods:(NSNotification *)notification{
- NSDictionary * infoDict = [notification object][@"info"];
- if (!infoDict) {
- return;
- }
- NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
- if (urlStr) {
- if(self.tabBarController.selectedIndex == 1) {
-
- //刷新新订阅消息
- NSString *infoUrl = [NSString stringWithFormat:@"%@%@", kHost, urlStr];
-
- infoUrl = [infoUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:infoUrl]]];
- }
- }
- }
- //点击支付通知
- -(void)clickPayMethods:(NSNotification *)notification{
- NSDictionary * infoDict = [notification object][@"info"];
- if (!infoDict) {
- return;
- }
- NSString * urlStr = [NSString stringWithFormat:@"%@",infoDict[@"url"]];
- NSArray * array = [urlStr componentsSeparatedByString:@"=="];
- urlStr = [array.firstObject stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- NSString * titleStr = @"消息通知";
- titleStr = [NSString stringWithFormat:@"%@",infoDict[@"title"]];
- if (urlStr) {
- if(self.tabBarController.selectedIndex == 1) {
- [self jsOpenExternalLink:urlStr title:titleStr];
- }
- }
- }
- #pragma mark 收到z支付通知
- -(void)alipayWXpayStatus:(NSNotification *)notification{
-
- NSString * status = [notification object];
- [self performSelector:@selector(payStatus:) withObject:status afterDelay:2];
- }
- -(void)payStatus:(NSString *)status
- {
- //目前延时两秒
- NSLog(@"支付状态:%@",status);
- if(self.tabBarController.selectedIndex == 1) {
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- NSString * textJS1 = [NSString stringWithFormat:@"payCallBack('%@')", status];
- [context evaluateScript:textJS1];
- }
- }
- // 收到通知消息
- -(void)afterReceiveNewMsg{
- NSLog(@"afterReceiveNewMsg");
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- [context evaluateScript:@"afterReceiveNewMsg()"];
- }
- // 收到退出登录消息
- -(void)loginOut:(NSNotification *)notification{
- if([notification.userInfo[@"item_index"] integerValue]!=1) {
- return;
- }
-
- [self webViewRequestByMsg];
- }
- - (void)hideTabBar {
- kMainQueue(^{
- if (self.tabBarController.tabBar.hidden == YES) {
- return;
- }
- UIView *contentView;
- if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
- contentView = [self.tabBarController.view.subviews objectAtIndex:1];
- else
- contentView = [self.tabBarController.view.subviews objectAtIndex:0];
- 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);
- self.tabBarController.tabBar.hidden = YES;
-
- });
-
- }
- - (void)showTabBar{
- kMainQueue(^{
- if (self.tabBarController.tabBar.hidden == NO)
- {
- return;
- }
- UIView *contentView;
- if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
-
- contentView = [self.tabBarController.view.subviews objectAtIndex:1];
-
- else
-
- contentView = [self.tabBarController.view.subviews objectAtIndex:0];
- 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);
- self.tabBarController.tabBar.hidden = NO;
-
- });
- }
- //
- -(void)dealTabBar
- {
- NSLog(@"刷新第二个页面");
- kMainQueue(^{
- [self webViewFirstRequest];
- });
- }
- -(void)judgeIsHidden
- {
- NSString *current_url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
- //http://w4blmjy.qmx.top/jyapp/free/login?back=index
- NSLog(@"%@",current_url);
- if([current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/swordfish/historypush",kHost]]||[current_url isEqualToString:[NSString stringWithFormat:@"%@jyapp/free/login?back=index",kHost]]){
- NSLog(@"展示");
- [self showTabBar];
- self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT-TAB_BAR_HEIGHT+STATUS_BAR_HEIGHT);
- }else {
- NSLog(@"隐藏");
- [self hideTabBar];
- self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
- }
- }
- #pragma mark webView代理方法
- - (void)webViewDidFinishLoad:(UIWebView *)webView{
-
-
-
- [self judgeIsHidden];//是否隐藏
-
-
- [self removeNoNetViews];
- [[LXViewControllerManager shareViewControllerManager] hideHud];
- JSContext *context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- // Disable user selection
- [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
- // Disable callout
- [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
-
- context[@"JyObj"] = self;
-
- [context evaluateScript:@"afterPageInit()"];
- if (self.afterOpenPushMessage) {
- self.afterOpenPushMessage = NO;
- // [context evaluateScript:@"afterOpenPushMessage()"];
- [context evaluateScript:[NSString stringWithFormat:@"afterOpenPushMessage('%d')", [self jsIsCanBack:nil]]];
- }
- }
- -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
- [[LXViewControllerManager shareViewControllerManager] hideHud];
- }
- -(void)webViewDidStartLoad:(UIWebView *)webView{
- // if ([[UIDevice currentDevice].systemVersion floatValue] < 10) {
- // [[LXViewControllerManager shareViewControllerManager] hideHud];
- // }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // [self clearWeb];
- // Dispose of any resources that can be recreated.
- }
- -(void)clearWeb{
- NSURLCache * cache = [NSURLCache sharedURLCache];
- [cache removeAllCachedResponses];
- [cache setDiskCapacity:0];
- [cache setMemoryCapacity:0];
- }
- -(void)addNoNetViews{
- kMainQueue(^{
- [self removeNoNetViews];
- self.noNetView = [NoNetView shareView];
- [self.view addSubview:self.noNetView];
- });
- }
- -(void)removeNoNetViews{
- if (self.noNetView ) {
- [self.noNetView removeFromSuperview];
- self.noNetView = nil;
- }
- }
- #pragma mark JS 回调
- // 微信登录
- -(NSString *)jsLoginByWeixin:(NSString *)str{
-
- if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装微信 不走友盟
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"微信登录失败,没有安装微信" delay:1.5];
- return nil;
- }
-
- kMainQueue(^{
-
- [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:self completion:^(id result, NSError *error) {
-
- UMSocialUserInfoResponse *resp = result;
-
- [self dealWXDic:(NSDictionary *)resp.originalResponse];
-
- [[LXViewControllerManager shareViewControllerManager] hideHud];
- }];
-
-
-
- });
-
- return nil;
- }
- // 处理微信登录获取到的数据
- -(void)dealWXDic:(NSDictionary *)dictionary{
-
- [[LXViewControllerManager shareViewControllerManager] showHudText:nil];
- //如果获取到用户信息,即用户点击了“登录”,则进行用户信息获取
- if (dictionary.count > 0) {
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:dictionary];
-
- if (dic) {
- [dic removeObjectForKey:@"privilege"];
- [dic removeObjectForKey:@"language"];
- double currDouble = [[NSDate date] timeIntervalSince1970];
- [dic setObject:[NSNumber numberWithLong:(long)currDouble] forKey:@"createtime"];
-
- // 拼接标志位
- 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"]];
- sign = [LXMD5 md532BitLower:sign];
- [dic setObject:sign forKey:@"sign"];
- NSString *endStr = [[LXViewControllerManager shareViewControllerManager] getJsonStr:dic];
- NSData *data = [endStr dataUsingEncoding:NSUTF8StringEncoding];
- endStr = [data base64EncodedStringWithOptions:0];
-
-
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- NSString * textJS1 = [NSString stringWithFormat:@"loginByWeixinCallBack('%@')", endStr];
- JSValue *value = [context evaluateScript:textJS1];
- NSLog(@"%@", value);
-
- }
- }
-
- }
- // js 调用分享
- -(void)jsShare:(NSString *)type title:(NSString *)title content:(NSString *)content link:(NSString *)link{
- UMSocialPlatformType shareType;
-
- if ([type intValue] == 1) { // 微信好友
- shareType = UMSocialPlatformType_WechatSession;
- }else if ([type intValue] == 2){ /// qq好友
- shareType = UMSocialPlatformType_QQ;
- }else if ([type intValue] == 3){ // 朋友圈
- shareType = UMSocialPlatformType_WechatTimeLine;
- }else{
- shareType = UMSocialPlatformType_WechatSession;
- }
-
- kMainQueue((^{
-
- // 没有安装app 不走分享逻辑
- if ([type intValue] == 1 || [type intValue] == 3) {
- if ([LXUserDefaults isInstallWeiXin] != 1) {
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装微信" delay:1.5];
- return;
- }
- }
- // 没有安装app 不走分享逻辑
- if ([type intValue] == 2) {
- if (![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ]) {
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"没有安装QQ" delay:1.5];
- return;
- }
- }
-
- //创建分享消息对象
- UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
- //创建网页内容对象
- UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:content thumImage:[UIImage imageNamed:@"logo"]];
- //设置网页地址
- shareObject.webpageUrl = link;
- messageObject.shareObject = shareObject;
- //调用分享接口
- [[UMSocialManager defaultManager] shareToPlatform:shareType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
- if (error) {
- NSLog(@"22222222%@",error.userInfo);
- if (error.userInfo[@"message"] && [error.userInfo[@"message"] containsString:@"Operation is cancel"]) {
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"取消分享" delay:1];
- }else{
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:error.userInfo[@"message"] delay:1];
- }
-
- NSString *textJS = [NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"0"];
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- [context evaluateScript:textJS];
-
- }else{
- if ([data isKindOfClass:[UMSocialShareResponse class]]) {
- UMSocialShareResponse *resp = data;
- NSLog(@"33333%@",resp.message);
- NSLog(@"44444%@",resp.originalResponse);
-
- NSString *textJS = [NSString stringWithFormat:@"shareCallBack('%@','%@')",type,@"1"];
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- [context evaluateScript:textJS];
-
- }else{
- UMSocialLogInfo(@"response data is %@",data);
- NSLog(@"55555%@",data);
- }
- }
- }];
- }));
- }
- // 登录时获取到令牌 并保存
- -(void)jsSaveUserToken:(NSString *)token{
- [[LXViewControllerManager shareViewControllerManager] hideHud];
- [LXUserDefaults saveToken:token];
- }
- // 取本地的用户令牌
- -(NSString *)jsGetUserToken:(NSString *)str{
- return [LXUserDefaults token];
- }
- // 退出时 清空用户数据
- -(void)jsRemoveUserToken:(NSString *)str{
- [LXUserDefaults clearAll];
- // [[LXDataBaseManager shareDataBaseManager] clearAll];
-
- }
- // 手机通知权限是否打开
- -(int)jsCheckNoticePermission:(NSString *)str{
- int a = [LXUserDefaults notifyState];
- return a;
- }
- // 跳转到系统设置
- -(void)jsOpenSystemNotification:(NSString *)str{
- self.updateNotify = YES;
- kMainQueue(^{
- [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
- });
- }
- // 调用js方法 刷新推送权限状态
- -(void)updateNotifyState{
- if (self.updateNotify) {
- self.updateNotify = NO;
- JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- NSString * textJS1 = [NSString stringWithFormat:@"updateNoticeSwitch()"];
- [context evaluateScript:textJS1];
- }
- }
- // 获取推送id
- -(NSString *)jsGetPushRid:(NSString *)str{
- return [LXUserDefaults registrationID];
- }
- // 按通知取数据
- -(NSString *)jsGetMessageList:(NSString *)openid{
- NSArray *arr = [[LXDataBaseManager shareDataBaseManager] getMessageWithKey:nil openid:openid fromTable:kNewsTable start:0 length:100];
- if (arr.count > 0) {
- return [[LXViewControllerManager shareViewControllerManager] getJsonStr:arr];
- }
- return @"";
- }
- // 更新消息状态
- -(void)jsUpdateMessageState:(NSNumber *)lxID state:(NSNumber *)state{
- [[LXDataBaseManager shareDataBaseManager] changeReadedWithID:lxID state:state];
- }
- // 删除一条数据
- -(void)jsDeleteMessageById:(NSNumber *)lxID{
- [[LXDataBaseManager shareDataBaseManager] deleteMessage:lxID fromTable:kNewsTable];
- }
- // 取单条数据
- -(NSString *)jsGetMessage:(NSString *)lxID{
- return [[LXViewControllerManager shareViewControllerManager] getJsonStr:[[LXDataBaseManager shareDataBaseManager] getMessageWithKey:lxID openid:nil fromTable:kNewsTable start:0 length:0]];
- }
- // 取未读消息总数
- -(int)jsGetUnReadMessageCount:(NSString *)openid{
- NSLog(@"openid=%@",openid);
- // NSLog(@"%d",[[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid]);
-
- return [[LXDataBaseManager shareDataBaseManager] getUnReadMessageCount:openid];
- }
- // 全部置为已读
- -(void)jsUpdateAllUnReadMessage:(NSString *)openid{
- [[LXDataBaseManager shareDataBaseManager] updateAllUnReadMessage:openid];
- }
- // 改变状态栏文字颜色
- -(void)jsLightStatusBar:(NSString *)status{
- kMainQueue(^{
- NSInteger index = 0;
- if ([status intValue] == 1) {
- index = 1;// hei
- }else{
- index = 0;// bai
- }
- [[UIApplication sharedApplication] setStatusBarStyle:index];
- });
-
- }
- // 打开新页面 加载新web
- -(void)jsOpenExternalLink:(NSString *)url title:(NSString *)title{
- if (url) {
- if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable || [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusUnknown) {
- // [self addNoNetViews];
- }
- NewWebController *ctr = [[NewWebController alloc] init];
- ctr.url = url;
- // 有title的话 会显示自定义的导航栏 没有的话不显示导航栏 显示加载进度条
- if (!title || [title isEqualToString:@""] || [title isEqualToString:@"undefined"]) {
- ctr.titleShow = nil;
- }else{
- ctr.titleShow = title;
- }
- kMainQueue(^{
- [self presentViewController:ctr animated:NO completion:nil];
- });
- }
- }
- // 获取当前版本号
- -(NSString *)jsGetVersion:(NSString *)str{
- return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
- }
- // web是否可退回上页面
- -(int)jsIsCanBack:(NSString *)str{
- return self.webView.canGoBack ? 1:0;
- }
- // 弹框
- -(void)jsAlert:(NSString *)content{
- [[LXViewControllerManager shareViewControllerManager] showAlertViewWithMessage:content];
- }
- // 是否安装微信
- -(int)jsIsInstallWeixin:(NSString *)str{
- return [LXUserDefaults isInstallWeiXin];
- }
- -(void)jsChangeMessageType:(NSString *)link
- {
- //已读操作处理
- NSLog(@"已读操作处理-更改");
- [[LXDataBaseManager shareDataBaseManager] changeCatagoryTypeWithURL:link];
- }
- -(void)jsOpenActivityPage:(NSString *)url rectype:(NSString *)rectype openid:(NSString *)openid
- {
- NSDictionary * infoDic = @{@"url":url,
- @"rectype":rectype,
- @"openid":openid,
- };
-
- // NSString *textJS = [NSString stringWithFormat:@"messageAccept('%@','%@','%@')",infoDic[@"mid"],infoDic[@"rectype"],infoDic[@"openid"]];
- // JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- // [context evaluateScript:textJS];
-
-
- //post请求
- NSLog(@"%@",[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost]);
- [[LXNetworkManager shareLXNetworkManager]postWithURLStr:[NSString stringWithFormat:@"%@jyapp/free/message/receive",kHost] parameters:infoDic progress:^(NSProgress *progress) {
- NSLog(@"成功:%@",progress);
- } success:^(id responseObject) {
- NSLog(@"responseObject=%@",responseObject);
- } failure:^(NSError *error) {
- NSLog(@"error=%@",error);
- }];
-
-
- }
- -(NSString *)jsGGetCipherText:(NSString *)phone
- {
-
- NSDate *date=[NSDate date];
- NSDateFormatter *format1=[[NSDateFormatter alloc] init];
- [format1 setDateFormat:@"yyyyMMddhhmmss"];
- NSString *dateStr;
- dateStr=[format1 stringFromDate:date];
- NSLog(@"%@",dateStr);
-
- NSString *content = [[NSString stringWithFormat:@"%@_%@",phone,dateStr] stringByAppendingString:[NSString stringWithFormat:@"_%@",[LXMD5 md532BitLower:[NSString stringWithFormat:@"%@&%@",phone,dateStr]]]];
- NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
- NSUInteger dataLength = contentData.length;
- // 为结束符'\\0' +1
- char keyPtr[kKeySize_1 + 1];
- memset(keyPtr, 0, sizeof(keyPtr));
- [AesKey_1 getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
- // 密文长度 <= 明文长度 + BlockSize
- size_t encryptSize = dataLength + kCCBlockSizeAES128;
- void *encryptedBytes = malloc(encryptSize);
- size_t actualOutSize = 0;
- NSData *initVector = [kInitVector_1 dataUsingEncoding:NSUTF8StringEncoding];
- CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
- kCCAlgorithmAES,
- kCCOptionPKCS7Padding, // 系统默认使用 CBC,然后指明使用 PKCS7Padding
- keyPtr,
- kKeySize_1,
- initVector.bytes,
- contentData.bytes,
- dataLength,
- encryptedBytes,
- encryptSize,
- &actualOutSize);
- if (cryptStatus == kCCSuccess) {
- // 对加密后的数据进行 base64 编码
- return [[NSData dataWithBytesNoCopy:encryptedBytes length:actualOutSize] base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
- }
- free(encryptedBytes);
- return nil;
- }
- //通知刷新页面
- -(void)refreshDY:(NSNotification *)notificaition{
-
-
- // NSDictionary * infoDict = [notificaition object][@"userInfo"];
-
- NSDictionary *infoDict = notificaition.userInfo;
- NSLog(@"%@",infoDict);
- if (!infoDict) {
- [self webViewFirstRequest];
- }else {
- NSString *infoUrl = [NSString stringWithFormat:@"%@%@", kHost, infoDict[@"url"]];
-
- infoUrl = [infoUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:infoUrl]]];
- }
- }
- -(void)jsBackUrl:(NSString*)str
- {
- NSLog(@"Mine返回首页%@",str);
- if([str isEqualToString:@"H"]) {
- //测试返回首页
- kMainQueue(^{
- AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
- tab.selectedIndex = 0;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"changeItems" object:nil userInfo:@{@"item_index":@"0"}];
-
- [self dealTabBar];
- });
-
- }
-
-
- }
- -(void)jsLoginSuccess:(NSString*)status
- {
- NSLog(@"sub登录成功提示");
- [GlobalData shareInstance].isReLogin = YES;
- if([status isEqualToString:@"S"]) {
- kMainQueue(^{
- AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- JYTabBarController *tab = (JYTabBarController *)delegate.window.rootViewController;
- tab.selectedIndex = 0;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:@"changeItems" object:nil userInfo:@{@"item_index":@"5"}];
- });
- }else {
-
- }
- }
- -(void)jsHideRedSpotOnMenu:(NSString*)str
- {
- NSLog(@"sub隐藏:%@",str);
- if([str isEqualToString:@"subscribe"]) {
- kMainQueue(^{
- [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
- });
- }
-
-
- if([str isEqualToString:@"my"]) {
- kMainQueue(^{
- [self.tabBarController.tabBar hideBadgeOnItemIndex:3];
- });
- }
- }
- -(void)jsShowRedSpotOnMenu:(NSString*)str
- {
- NSLog(@"sub展示:%@",str);
- if([str isEqualToString:@"subscribe"]) {
- kMainQueue(^{
- [self.tabBarController.tabBar showBadgeOnItemIndex:1];
- });
- }
-
-
- if([str isEqualToString:@"my"]) {
- kMainQueue(^{
- [self.tabBarController.tabBar showBadgeOnItemIndex:3];
- });
- }
-
- }
- -(void)jsClearPushMessage:(NSString*)type
- {
- NSLog(@"清除通知栏");
- kMainQueue(^{
- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
- });
- }
- #pragma mark 支付相关
- -(void)jsWxPay:(NSString *)jsonString
- {
- if ([LXUserDefaults isInstallWeiXin] != 1) { // 没有安装wx
- [[LXViewControllerManager shareViewControllerManager] showHudOnlyText:@"请先下载微信再进行支付!" delay:1.5];
- return;
- }
-
- NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
-
- NSError *err;
-
- NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
-
- options:NSJSONReadingMutableContainers
-
- error:&err];
-
- NSLog(@"%@",dic);
-
- if(err) {
-
- NSLog(@"json解析失败:%@",err);
-
- return;
-
- }
-
-
-
- //吊起微信
- PayReq *request = [[PayReq alloc] init] ;
- request.openID = dic[@"Appid"];
-
-
- request.partnerId = dic[@"Partnerid"];
- request.prepayId= dic[@"Prepayid"];
- request.package = @"Sign=WXPay";
- request.nonceStr= dic[@"Noncestr"];
- request.timeStamp= [dic[@"Timestamp"] intValue];
- request.sign= dic[@"Sign"];
-
-
-
- kMainQueue(^{
- [WXApi sendReq:request];
- });
-
-
-
-
-
- }
- -(void)jsAliPay:(NSString*)str
- {
- kMainQueue(^{
- [[AlipaySDK defaultService] payOrder:str fromScheme:@"jianyuiosapp" callback:nil];
- });
-
-
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|