From e57895d3e36ef1f2d41a057e557943158b875af1 Mon Sep 17 00:00:00 2001 From: eggmanQQQ <3671373519@qq.com> Date: Tue, 9 Jul 2024 15:02:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=8B=89=E8=B5=B7=E6=94=AF?= =?UTF-8?q?=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Content/MessageContentChatHallHeadView.m | 5 - .../Presenter/XPMineRechargePresenter.m | 3 + .../Recharge/XPIAPRechargeViewController.m | 28 +- .../View/XPHomePagingViewController.m | 25 +- .../AnimationView/XPRoomGiftBroadcastView.m | 37 +- .../MsRoomMessagChatHallView.m | 1 - .../Setting/Presenter/XPRoomTopicPresenter.m | 1 - YuMi/Modules/YMWeb/XPWebViewController.m | 655 +++++++++++------- YuMi/Tools/PIIAPTool/PIIAPRegulate.swift | 4 +- 9 files changed, 458 insertions(+), 301 deletions(-) diff --git a/YuMi/Modules/YMMessage/View/Session/Content/MessageContentChatHallHeadView.m b/YuMi/Modules/YMMessage/View/Session/Content/MessageContentChatHallHeadView.m index 42f105aa..c523c530 100644 --- a/YuMi/Modules/YMMessage/View/Session/Content/MessageContentChatHallHeadView.m +++ b/YuMi/Modules/YMMessage/View/Session/Content/MessageContentChatHallHeadView.m @@ -184,11 +184,6 @@ } } -- (NSString *)cellContent:(MessageBaseModel *)model { -// MessageHeadlinesTextModel *imageModel = (MessageHeadlinesTextModel *)model; - return @"123";//[NSString stringWithFormat:@"%@", model.f]; -} - #pragma mark - 懒加载 - (NetImageView *)avatarView{ if(!_avatarView){ diff --git a/YuMi/Modules/YMMine/Presenter/XPMineRechargePresenter.m b/YuMi/Modules/YMMine/Presenter/XPMineRechargePresenter.m index e39c697e..66df1ad3 100644 --- a/YuMi/Modules/YMMine/Presenter/XPMineRechargePresenter.m +++ b/YuMi/Modules/YMMine/Presenter/XPMineRechargePresenter.m @@ -48,11 +48,14 @@ NSString * ticket = [AccountInfoStorage instance].getTicket; NSString * deviceInfo = [YYUtility deviceID]; NSString * clientIp= [YYUtility ipAddress]; + @kWeakify(self); [Api requestIAPRecharge:[self createHttpCompletion:^(BaseModel * _Nonnull data) { + @kStrongify(self); NSString *orderId = (NSString *)data.data[@"recordId"]; NSString *uuid = (NSString *)data.data[@"appAccountToken"]; [[self getView] requestIAPRechargeOrderSuccess:orderId chargeProdId:chargeProdId uuid:uuid]; } fail:^(NSInteger code, NSString * _Nullable msg) { + @kStrongify(self); if(code != 50000){ [[self getView]showErrorToast:msg]; } diff --git a/YuMi/Modules/YMMine/View/Recharge/XPIAPRechargeViewController.m b/YuMi/Modules/YMMine/View/Recharge/XPIAPRechargeViewController.m index 00bf00bc..d922001d 100644 --- a/YuMi/Modules/YMMine/View/Recharge/XPIAPRechargeViewController.m +++ b/YuMi/Modules/YMMine/View/Recharge/XPIAPRechargeViewController.m @@ -92,6 +92,7 @@ [self createUI]; [self initHttpData]; } + - (void)createUI { self.view.backgroundColor = UIColorFromRGB(0xF4F5FA); @@ -145,7 +146,7 @@ [self getRechargeList]; [self.presenter getBannerList]; [self getUserWalletBalanceInfo]; - [self checkTranscationIds]; + [self checkTransactionIds]; } /// 返回 @@ -211,7 +212,7 @@ [self.collectionView reloadData]; } ///批量验证 -- (void)checkTranscationIds { +- (void)checkTransactionIds { NSString * uid = [AccountInfoStorage instance].getUid; NSArray * array = [RechargeStorage getAllReciptsWithUid:uid]; @@ -282,10 +283,10 @@ #pragma mark - XPIAPHelperDelegate ///当前充值的状态 - (void)rechargeNewProcessStatus:(StoreConditionResult)status { - dispatch_async(dispatch_get_main_queue(), ^{ - if (status == StoreConditionResultPay || status == StoreConditionResultStart || status == StoreConditionResultVerifiedServer) { - + if (status == StoreConditionResultPay || + status == StoreConditionResultStart || + status == StoreConditionResultVerifiedServer) { }else if (status == StoreConditionResultUnowned) { [XNDJTDDLoadingTool hideHUDInView:kWindow]; [self showErrorToast:YMLocalizedString(@"XPIAPRechargeViewController1")]; @@ -293,8 +294,7 @@ [XNDJTDDLoadingTool hideHUDInView:kWindow]; [self showErrorToast:YMLocalizedString(@"XPIAPRechargeViewController0")]; } - }); - + }); } ///充值成功回调id @@ -302,8 +302,7 @@ ///保存唯一凭证 [self saveRechageReciptWithTransactionIdentifier:transactionIdentifier]; ///二次验证 - [self.presenter checkReceiptWithOrderId:self.orderId transcationId:transactionIdentifier errorToast:YES]; - + [self.presenter checkReceiptWithOrderId:self.orderId transcationId:transactionIdentifier errorToast:YES]; } #pragma mark - XPMineRechargeProtocol - (void)requestRechargeListSucccess:(NSArray *)list { @@ -333,27 +332,16 @@ NSString *transactionId = result[@"transactionId"]; [self rechargeSuccess:transactionId]; - } break; - default: - { - - - } break; } }; - } else { [XNDJTDDLoadingTool hideHUDInView:kWindow]; [self showErrorToast:YMLocalizedString(@"XPIAPRechargeViewController10")]; } - - - - }else{ [XNDJTDDLoadingTool hideHUDInView:kWindow]; } diff --git a/YuMi/Modules/YMNewHome/View/XPHomePagingViewController.m b/YuMi/Modules/YMNewHome/View/XPHomePagingViewController.m index 0571d566..f5aee27d 100644 --- a/YuMi/Modules/YMNewHome/View/XPHomePagingViewController.m +++ b/YuMi/Modules/YMNewHome/View/XPHomePagingViewController.m @@ -11,7 +11,7 @@ #import "XPHomeMineViewController.h" #import "XPRoomSearchContainerViewController.h" -#import "FeedBackViewController.h" +#import "XPWebViewController.h" @interface XPHomePagingViewController () @@ -146,10 +146,31 @@ make.height.mas_equalTo(4); make.centerX.mas_equalTo(self.recommendButton.mas_centerX); }]; + +#if DEBUG + @kWeakify(self); + UIButton *b = [UIButton buttonWithType:UIButtonTypeClose primaryAction:[UIAction actionWithHandler:^(__kindof UIAction * _Nonnull action) { + @kStrongify(self); + [self __testMethod]; + }]]; + [self.topControlView addSubview:b]; + [b mas_makeConstraints:^(MASConstraintMaker *make) { + make.centerY.mas_equalTo(self.mineButton); + if (isMSRTL()) { + make.left.mas_equalTo(self.topControlView).offset(16); + } else { + make.right.mas_equalTo(self.topControlView).offset(-36); + } + make.width.height.mas_equalTo(36); + }]; +#endif } - (void)__testMethod { - FeedBackViewController *vc = [[FeedBackViewController alloc] init]; +// FeedBackViewController *vc = [[FeedBackViewController alloc] init]; +// [self.navigationController pushViewController:vc animated:YES]; + XPWebViewController *vc = [[XPWebViewController alloc]init]; + vc.url = @"http://beta.api.molistar.xyz/molistar/modules/order/index.html";//[NSURL URLWithString:]; [self.navigationController pushViewController:vc animated:YES]; } diff --git a/YuMi/Modules/YMRoom/View/AnimationView/XPRoomGiftBroadcastView.m b/YuMi/Modules/YMRoom/View/AnimationView/XPRoomGiftBroadcastView.m index 33286ffe..764181a0 100644 --- a/YuMi/Modules/YMRoom/View/AnimationView/XPRoomGiftBroadcastView.m +++ b/YuMi/Modules/YMRoom/View/AnimationView/XPRoomGiftBroadcastView.m @@ -66,7 +66,6 @@ #pragma mark - Private Method - (void)initSubViews { [self addSubview:self.backImageView]; - [self.backImageView addSubview:self.senderAvatarView]; [self.backImageView addSubview:self.pi_contentView]; @@ -75,13 +74,10 @@ [self.backImageView addSubview:self.circuseeBtn]; [self.backImageView addSubview:self.giftImageView]; [self.backImageView addSubview:self.countLabel]; - - } - (void)initSubViewConstraints { - [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self); }]; @@ -126,11 +122,6 @@ make.leading.mas_equalTo(self.giftImageView.mas_trailing).offset(kGetScaleWidth(2)); make.centerY.mas_equalTo(self.backImageView); }]; - - - - - } - (void)initEvents { @@ -141,59 +132,34 @@ UIColor * lineColor; UIColor *bgBtnColor; NSString * bgImageName; - - - + switch (level) { case BroadCastLevel_Normal: { - - lineColor = UIColorFromRGB(0x66B5FF); bgBtnColor = UIColorFromRGB(0x283889); bgImageName = @"pi_room_gift_broadcast_low_bg"; - - } break; case BroadCastLevel_Middle: { - - - lineColor = UIColorFromRGB(0xFE9FFF); bgBtnColor = UIColorFromRGB(0x49157D); - bgImageName = @"pi_room_gift_broadcast_middle_bg"; - - } break; case BroadCastLevel_High: { - - - - lineColor = UIColorFromRGB(0xFFED77); bgBtnColor = UIColorFromRGB(0x87152D); - bgImageName = @"pi_room_gift_broadcast_high_bg"; - - } break; default: { - - - lineColor = UIColorFromRGB(0x66B5FF); bgBtnColor = UIColorFromRGB(0x283889); - bgImageName = @"pi_room_gift_broadcast_low_bg"; - - } break; } @@ -205,6 +171,7 @@ -(void)showRoomVC{ [self didClickEnterRoom]; } + #pragma mark - Getters And Setters - (void)setBroadcastModel:(GiftReceiveInfoModel *)broadcastModel { _broadcastModel = broadcastModel; diff --git a/YuMi/Modules/YMRoom/View/MessageContainerView/MsRoomMessagChatHallView.m b/YuMi/Modules/YMRoom/View/MessageContainerView/MsRoomMessagChatHallView.m index 2f65d322..27682c3f 100644 --- a/YuMi/Modules/YMRoom/View/MessageContainerView/MsRoomMessagChatHallView.m +++ b/YuMi/Modules/YMRoom/View/MessageContainerView/MsRoomMessagChatHallView.m @@ -116,7 +116,6 @@ make.leading.mas_equalTo(self).offset(15); make.top.trailing.mas_equalTo(self); make.height.mas_equalTo(0); - }]; } } diff --git a/YuMi/Modules/YMRoom/View/Setting/Presenter/XPRoomTopicPresenter.m b/YuMi/Modules/YMRoom/View/Setting/Presenter/XPRoomTopicPresenter.m index 74cfdb25..e12dd29b 100644 --- a/YuMi/Modules/YMRoom/View/Setting/Presenter/XPRoomTopicPresenter.m +++ b/YuMi/Modules/YMRoom/View/Setting/Presenter/XPRoomTopicPresenter.m @@ -62,7 +62,6 @@ [[self getView] updateRoomTopicFail:YMLocalizedString(@"XPRoomTopicPresenter0")]; } }]; - } @end diff --git a/YuMi/Modules/YMWeb/XPWebViewController.m b/YuMi/Modules/YMWeb/XPWebViewController.m index 890e3e81..f396af57 100644 --- a/YuMi/Modules/YMWeb/XPWebViewController.m +++ b/YuMi/Modules/YMWeb/XPWebViewController.m @@ -18,6 +18,10 @@ #import "XCCurrentVCStackManager.h" #import "XPMineUserInfoViewController.h" +#import "Api+Mine.h" +#import "YuMi-swift.h" +#import "RechargeStorage.h" + ///vc #import "XPMineDressUpViewController.h" #import "XPDressUpShopViewController.h" @@ -89,6 +93,10 @@ typedef NS_ENUM(NSUInteger, RightNavigationPushType){ /// @property (nonatomic,assign) BOOL isCustom; @property(nonatomic,strong) PIWebViewSavePhotoView *saveView; + +/// 订单编号 +@property (nonatomic,copy) NSString *orderId; + @end NSString * const kJSOpenPurse = @"openPurse"; @@ -113,6 +121,8 @@ NSString * const kJSOpenChatPage = @"geToChatPage"; NSString * const kJSOpenAppConcernedChat = @"openAppConcernedChat"; NSString * const kJSSavePictureShare = @"savePictureShare"; NSString * const kJSGoToExchangeGold = @"goToExchangeGold"; +NSString * const kJSOpenPayment = @"openPayment"; +NSString * const kJSOpenPaymentCallback = @"openPaymentCallback"; @implementation XPWebViewController @@ -229,9 +239,6 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold"; }]; } - - - NSString * uid = [AccountInfoStorage instance].getUid; NSString * ticket = [AccountInfoStorage instance].getTicket; [Api getUserWalletInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { @@ -279,7 +286,7 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold"; - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { NSURL *URL = navigationAction.request.URL; NSString *scheme = [URL scheme]; - NSURLRequest *request = navigationAction.request; + NSURLRequest *request = navigationAction.request; // Judge is whether to jump to other app. if (![scheme isEqualToString:@"https"] && ![scheme isEqualToString:@"http"]) { BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:request.URL]; @@ -299,215 +306,394 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold"; NSURLCredential *card = [[NSURLCredential alloc]initWithTrust:challenge.protectionSpace.serverTrust]; completionHandler(NSURLSessionAuthChallengeUseCredential,card); }); - - } } -- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message { - [self.webview evaluateJavaScript:@"document.location.href" completionHandler:^(id _Nullable response, NSError * _Nullable error) { - NSLog(@"%@", response); - NSString *currentUrl = [NSString stringWithFormat:@"%@", response]; - ///测试环境只要有host就执行,方便h5连接本地调试 +- (void)userContentController:(WKUserContentController *)userContentController + didReceiveScriptMessage:(WKScriptMessage *)message { + [self.webview evaluateJavaScript:@"document.location.href" + completionHandler:^(id _Nullable response, NSError * _Nullable error) { + NSLog(@"%@", response); + NSLog(@"-- -- - -- - -%@: %@", message.name, message.body); + NSString *currentUrl = [NSString stringWithFormat:@"%@", response]; + ///测试环境只要有host就执行,方便h5连接本地调试 + + BOOL condition = currentUrl != nil && [currentUrl containsString:API_HOST_URL]; #ifdef DEBUG - if (currentUrl != nil) { -#else - if (currentUrl != nil && [currentUrl containsString:API_HOST_URL]) { + condition = currentUrl != nil; #endif - if ([message.name isEqualToString:kJSOpenSharePage]) { - if (message.body && message.body != [NSNull null]) { - NSDictionary *body; - //不知道是哪个蓝精灵弄的,变成了个dic,所以我们要判断类型 - if ([message.body isKindOfClass:[NSDictionary class]]) { - body = message.body; - } else if ([message.body isKindOfClass:[NSString class]]) { - body = [message.body toJSONObject]; - } - self.shareDic = body[@"data"]; - [self showSharePanel]; - } - } else if ([message.name isEqualToString:kJSGetUid]) { - NSString *uid = [[AccountInfoStorage instance] getUid]; - NSString *js = [NSString stringWithFormat:@"getMessage(\"uid\",%@)", uid]; - [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) { - NSLog(@"%@",error); - }]; - } else if ([message.name isEqualToString:kJSGetTicket]) { - NSString *ticket = [[AccountInfoStorage instance] getTicket]; - NSString *js = [NSString stringWithFormat:@"getMessage(\"ticket\",\"%@\")",ticket]; - [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) { - NSLog(@"%@",error); - }]; - } else if ([message.name isEqualToString:kJSGetDeviceId]) { - NSString *js = [NSString stringWithFormat:@"getMessage(\"deviceId\",\"%@\")",[YYUtility deviceUniqueIdentification]]; - [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) { - NSLog(@"%@",error); - }]; - } else if ([message.name isEqualToString:kJSGetDeviceInfo]) { - NSDictionary *basicParmars = [HttpRequestHelper configBaseParmars:[[NSDictionary alloc] init]]; - NSString *json = [basicParmars mj_JSONString]; - NSString *js = [NSString stringWithFormat:@"getMessage(\"deviceInfo\",%@)", json]; - [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable ohter, NSError * _Nullable error) { - NSLog(@"%@", error); - }]; - } else if ([message.name isEqualToString:kJSOpenPurse]) { - - }else if([message.name isEqualToString:kJSChargePayPage]){ -// NSString *money = [NSString stringWithFormat:@"%@",message.body] ; - - }else if([message.name isEqualToString:kJSChargePayClickPage]){ - if(message.body != nil && self.model.diamonds != nil){ -// NSString *type = [NSString stringWithFormat:@"%@",message.body]; - } - }else if ([message.name isEqualToString:kJSOpenChargePage]) { - if(self.delegate && [self.delegate respondsToSelector:@selector(payHandler)]){ - [self.delegate payHandler]; - return; + if(condition) { + if ([message.name isEqualToString:kJSOpenSharePage]) { + if (message.body && message.body != [NSNull null]) { + NSDictionary *body; + //不知道是哪个蓝精灵弄的,变成了个dic,所以我们要判断类型 + if ([message.body isKindOfClass:[NSDictionary class]]) { + body = message.body; + } else if ([message.body isKindOfClass:[NSString class]]) { + body = [message.body toJSONObject]; } + self.shareDic = body[@"data"]; + [self showSharePanel]; + } + } else if ([message.name isEqualToString:kJSGetUid]) { + NSString *uid = [[AccountInfoStorage instance] getUid]; + NSString *js = [NSString stringWithFormat:@"getMessage(\"uid\",%@)", uid]; + [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) { + NSLog(@"%@",error); + }]; + } else if ([message.name isEqualToString:kJSGetTicket]) { + NSString *ticket = [[AccountInfoStorage instance] getTicket]; + NSString *js = [NSString stringWithFormat:@"getMessage(\"ticket\",\"%@\")",ticket]; + [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) { + NSLog(@"%@",error); + }]; + } else if ([message.name isEqualToString:kJSGetDeviceId]) { + NSString *js = [NSString stringWithFormat:@"getMessage(\"deviceId\",\"%@\")",[YYUtility deviceUniqueIdentification]]; + [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) { + NSLog(@"%@",error); + }]; + } else if ([message.name isEqualToString:kJSGetDeviceInfo]) { + NSDictionary *basicParmars = [HttpRequestHelper configBaseParmars:[[NSDictionary alloc] init]]; + NSString *json = [basicParmars mj_JSONString]; + NSString *js = [NSString stringWithFormat:@"getMessage(\"deviceInfo\",%@)", json]; + [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable ohter, NSError * _Nullable error) { + NSLog(@"%@", error); + }]; + } else if ([message.name isEqualToString:kJSOpenPurse]) { + + }else if([message.name isEqualToString:kJSChargePayPage]){ + // NSString *money = [NSString stringWithFormat:@"%@",message.body] ; + + }else if([message.name isEqualToString:kJSChargePayClickPage]){ + if(message.body != nil && self.model.diamonds != nil){ + // NSString *type = [NSString stringWithFormat:@"%@",message.body]; + } + }else if ([message.name isEqualToString:kJSOpenChargePage]) { + if(self.delegate && [self.delegate respondsToSelector:@selector(payHandler)]){ + [self.delegate payHandler]; + return; + } + [TTPopup dismiss]; + if(self.isPush){ + XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init]; + webVC.type = @"4"; + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES]; + return; + } + UIViewController *controller = [XCCurrentVCStackManager shareManager].getCurrentVC; + if (controller.presentingViewController) { + [controller dismissViewControllerAnimated:NO completion:nil]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + + XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init]; + webVC.type = @"4"; + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES]; + }); + }else { + XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init]; + webVC.type = @"4"; + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES]; + } + } else if ([message.name isEqualToString:kOpenPersonPage]) { + NSString *uid = [NSString stringWithFormat:@"%@",message.body]; + if (uid.integerValue > 0) { [TTPopup dismiss]; - if(self.isPush){ - XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init]; - webVC.type = @"4"; - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES]; - return; - } - UIViewController *controller = [XCCurrentVCStackManager shareManager].getCurrentVC; - if (controller.presentingViewController) { - [controller dismissViewControllerAnimated:NO completion:nil]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - - XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init]; - webVC.type = @"4"; - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES]; - }); - }else { - XPIAPRechargeViewController * webVC =[[XPIAPRechargeViewController alloc] init]; - webVC.type = @"4"; - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:webVC animated:YES]; - } - } else if ([message.name isEqualToString:kOpenPersonPage]) { - NSString *uid = [NSString stringWithFormat:@"%@",message.body]; - if (uid.integerValue > 0) { - [TTPopup dismiss]; - XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init]; - userInfoVC.uid = uid.integerValue; - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:userInfoVC animated:YES]; - } - } else if([message.name isEqualToString:kJSInitNav]) { - [self initNav:message.body]; - } else if([message.name isEqualToString:kJSGetRoomUid]) { - NSString *js = [NSString stringWithFormat:@"getMessage(\"roomUid\",\"%@\")",self.roomUid]; - [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) { - NSLog(@"%@",error); - }]; - } else if([message.name isEqualToString:kInitShowNav]) { - if (((NSNumber *)message.body).intValue == 0) { - if (self.InitShowNavBlock) { - self.InitShowNavBlock(YES); - return; - } - if (self.navigationController) { - [self.navigationController setNavigationBarHidden:YES]; - } - } - } else if([message.name isEqualToString:kCloseWebView]) { - if (self.CloseWebViewBlock) { - self.CloseWebViewBlock(YES); + XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init]; + userInfoVC.uid = uid.integerValue; + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:userInfoVC animated:YES]; + } + } else if([message.name isEqualToString:kJSInitNav]) { + [self initNav:message.body]; + } else if([message.name isEqualToString:kJSGetRoomUid]) { + NSString *js = [NSString stringWithFormat:@"getMessage(\"roomUid\",\"%@\")",self.roomUid]; + [self.webview evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) { + NSLog(@"%@",error); + }]; + } else if([message.name isEqualToString:kInitShowNav]) { + if (((NSNumber *)message.body).intValue == 0) { + if (self.InitShowNavBlock) { + self.InitShowNavBlock(YES); return; } if (self.navigationController) { - [self.navigationController popViewControllerAnimated:YES]; + [self.navigationController setNavigationBarHidden:YES]; } - } else if ([message.name isEqualToString:kJumpAppointPage]) { - // h5与原生交互新协议 - NSDictionary *bodyDict; - if ([message.body isKindOfClass:[NSDictionary class]]) { - bodyDict = message.body; - } else if ([message.body isKindOfClass:[NSString class]]) { - NSString *str = (NSString *)message.body; - bodyDict = [str toJSONObject]; - } - NSInteger skyType = [bodyDict[@"routerType"] integerValue]; - [self handleRouterType:skyType message:message]; - }else if ([message.name isEqualToString:kJSOpenChatPage]){ - NSString *uid = [NSString stringWithFormat:@"%@",message.body]; - if (uid.length > 0) { - NIMSession * session = [NIMSession session:uid type:NIMSessionTypeP2P]; - SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session]; - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:sessionVC animated:YES]; - } - }else if([message.name isEqualToString:kJSOpenAppConcernedChat]){ - NSString *uid = [NSString stringWithFormat:@"%@",message.body]; - if (uid.length > 0) { - NIMSession * session = [NIMSession session:uid type:NIMSessionTypeP2P]; - SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session]; - sessionVC.isAttention = YES; - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:sessionVC animated:YES]; - } - }else if ([message.name isEqualToString:kJSOpenRoom]) { - NSString *uid = [NSString stringWithFormat:@"%@",message.body]; - if (uid.length > 0) { - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - if ([obj isKindOfClass:[XPRoomViewController class]]) { - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController popToRootViewControllerAnimated:NO]; - XPRoomViewController * rooomVC = obj; - [rooomVC exitRoom]; - *stop = YES; - } - }]; - if(self.view.superview){ - [TTPopup dismiss]; - } - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [XPRoomViewController openRoom:uid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC]; - }); - } - } else if([message.name isEqualToString:kJSOpenRoomForGiftId]) { - NSLog(@"%@", message.body); - NSDictionary *bodyDict; - if ([message.body isKindOfClass:[NSDictionary class]]) { - bodyDict = message.body; - } else if ([message.body isKindOfClass:[NSString class]]) { - NSString *str = (NSString *)message.body; - bodyDict = [str toJSONObject]; - } - //房间页 传参:uid - NSString *uid = [NSString stringWithFormat:@"%@", bodyDict[@"uid"]]; - NSString *giftId = [NSString stringWithFormat:@"%@", bodyDict[@"giftId"]]; - if (uid.length) { - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - if ([obj isKindOfClass:[XPRoomViewController class]]) { - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController popToRootViewControllerAnimated:NO]; - XPRoomViewController * rooomVC = obj; - [rooomVC exitRoom]; - *stop = YES; - } - }]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [XPRoomViewController openRoom:uid giftId:giftId viewController:[XCCurrentVCStackManager shareManager].getCurrentVC]; - }); - } - - }else if ([message.name isEqualToString:kJSSavePictureShare]){ - NSDictionary *bodyDic; - if ([message.body isKindOfClass:[NSDictionary class]]) { - bodyDic = message.body; - } else if ([message.body isKindOfClass:[NSString class]]) { - bodyDic = [message.body toJSONObject]; - } - NSString *type = [NSString stringWithFormat:@"%@",bodyDic[@"type"]]; - if ([type isEqualToString:@"2"]){ - [self saveImageToPhotoAlbum:bodyDic]; - }else if ([type isEqualToString:@"1"]){ - self.savePhotoDic = bodyDic; - [self showShareSavePhote]; - } - }else if([message.name isEqualToString:kJSGoToExchangeGold]){ - XPIncomeRecordVC *incomeRecordVC = [XPIncomeRecordVC new]; - [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:incomeRecordVC animated:YES]; } - } - }]; - } + } else if([message.name isEqualToString:kCloseWebView]) { + if (self.CloseWebViewBlock) { + self.CloseWebViewBlock(YES); + return; + } + if (self.navigationController) { + [self.navigationController popViewControllerAnimated:YES]; + } + } else if ([message.name isEqualToString:kJumpAppointPage]) { + // h5与原生交互新协议 + NSDictionary *bodyDict; + if ([message.body isKindOfClass:[NSDictionary class]]) { + bodyDict = message.body; + } else if ([message.body isKindOfClass:[NSString class]]) { + NSString *str = (NSString *)message.body; + bodyDict = [str toJSONObject]; + } + NSInteger skyType = [bodyDict[@"routerType"] integerValue]; + [self handleRouterType:skyType message:message]; + }else if ([message.name isEqualToString:kJSOpenChatPage]){ + NSString *uid = [NSString stringWithFormat:@"%@",message.body]; + if (uid.length > 0) { + NIMSession * session = [NIMSession session:uid type:NIMSessionTypeP2P]; + SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session]; + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:sessionVC animated:YES]; + } + }else if([message.name isEqualToString:kJSOpenAppConcernedChat]){ + NSString *uid = [NSString stringWithFormat:@"%@",message.body]; + if (uid.length > 0) { + NIMSession * session = [NIMSession session:uid type:NIMSessionTypeP2P]; + SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session]; + sessionVC.isAttention = YES; + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:sessionVC animated:YES]; + } + }else if ([message.name isEqualToString:kJSOpenRoom]) { + NSString *uid = [NSString stringWithFormat:@"%@",message.body]; + if (uid.length > 0) { + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + if ([obj isKindOfClass:[XPRoomViewController class]]) { + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController popToRootViewControllerAnimated:NO]; + XPRoomViewController * rooomVC = obj; + [rooomVC exitRoom]; + *stop = YES; + } + }]; + if(self.view.superview){ + [TTPopup dismiss]; + } + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [XPRoomViewController openRoom:uid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC]; + }); + } + } else if([message.name isEqualToString:kJSOpenRoomForGiftId]) { + NSLog(@"%@", message.body); + NSDictionary *bodyDict; + if ([message.body isKindOfClass:[NSDictionary class]]) { + bodyDict = message.body; + } else if ([message.body isKindOfClass:[NSString class]]) { + NSString *str = (NSString *)message.body; + bodyDict = [str toJSONObject]; + } + //房间页 传参:uid + NSString *uid = [NSString stringWithFormat:@"%@", bodyDict[@"uid"]]; + NSString *giftId = [NSString stringWithFormat:@"%@", bodyDict[@"giftId"]]; + if (uid.length) { + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + if ([obj isKindOfClass:[XPRoomViewController class]]) { + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController popToRootViewControllerAnimated:NO]; + XPRoomViewController * rooomVC = obj; + [rooomVC exitRoom]; + *stop = YES; + } + }]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [XPRoomViewController openRoom:uid giftId:giftId viewController:[XCCurrentVCStackManager shareManager].getCurrentVC]; + }); + } + + }else if ([message.name isEqualToString:kJSSavePictureShare]){ + NSDictionary *bodyDic; + if ([message.body isKindOfClass:[NSDictionary class]]) { + bodyDic = message.body; + } else if ([message.body isKindOfClass:[NSString class]]) { + bodyDic = [message.body toJSONObject]; + } + NSString *type = [NSString stringWithFormat:@"%@",bodyDic[@"type"]]; + if ([type isEqualToString:@"2"]){ + [self saveImageToPhotoAlbum:bodyDic]; + }else if ([type isEqualToString:@"1"]){ + self.savePhotoDic = bodyDic; + [self showShareSavePhote]; + } + }else if([message.name isEqualToString:kJSGoToExchangeGold]){ + XPIncomeRecordVC *incomeRecordVC = [XPIncomeRecordVC new]; + [[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:incomeRecordVC animated:YES]; + }else if([message.name isEqualToString:kJSOpenPayment]) { + [self handleOpenPayment:message.body]; + } + } + }]; +} + +#pragma mark - Payment Method +- (void)handleOpenPayment:(NSString *)chargeProdId { +#if DEBUG + chargeProdId = @"com.hflighting.yumi.first.10"; +#endif + if (chargeProdId.length == 0) { + [self showErrorToast:@"no charge ID"]; + return; + } + + [self showLoading]; + + @kWeakify(self); + [Api requestIAPRecharge:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { + @kStrongify(self); + [self showErrorToast:@"苹果下单 成功"]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + switch (code) { + case 200: { + NSString *orderId = (NSString *)data.data[@"recordId"]; + NSString *uuid = (NSString *)data.data[@"appAccountToken"]; + [self handleGetIAPRechargeSuccess:orderId + uuid:uuid + chargeProdId:chargeProdId]; + } + break; + case 50000: + [self showErrorToast:msg]; + break; + default: + break; + } + }); + + } + chargeProdId:chargeProdId + uid:[AccountInfoStorage instance].getUid + ticket:[AccountInfoStorage instance].getTicket + deviceInfo:[YYUtility deviceID] + clientIp:[YYUtility ipAddress]]; +} + +- (void)handleGetIAPRechargeSuccess:(NSString *)orderID + uuid:(NSString *)uuid + chargeProdId:(NSString *)chargeProdId { + if (orderID.length > 0) { + self.orderId = orderID; + if (@available(iOS 15.0, *)) { + PIIAPRegulate *iap = [PIIAPRegulate shared]; + [iap demandCommodityThingWithProductId:chargeProdId + uuid:uuid + completionHandler:^(NSError * _Nullable error) { + + }]; + @kWeakify(self); + iap.ConditionBlock = ^(enum StoreConditionResult state, NSDictionary * _Nullable result) { + @kStrongify(self); + switch (state) { + case StoreConditionResultVerifiedServer: { + NSString *transactionId = result[@"transactionId"]; + NSLog(@"-- -- - -- - - transactionId: %@, orderID: %@", transactionId, orderID); + [self rechargeSuccess:transactionId]; + } + break; + case StoreConditionResultUnowned: { + dispatch_async(dispatch_get_main_queue(), ^{ + [XNDJTDDLoadingTool hideHUDInView:kWindow]; + [self showErrorToast:YMLocalizedString(@"XPIAPRechargeViewController1")]; + }); + } + break; + case StoreConditionResultPay: + case StoreConditionResultStart: + break; + default: { + dispatch_async(dispatch_get_main_queue(), ^{ + [XNDJTDDLoadingTool hideHUDInView:kWindow]; + [self showErrorToast:YMLocalizedString(@"XPIAPRechargeViewController1")]; + }); + } + break; + } + }; + } else { + [XNDJTDDLoadingTool hideHUDInView:kWindow]; + [self showErrorToast:YMLocalizedString(@"XPIAPRechargeViewController10")]; + } + }else{ + [XNDJTDDLoadingTool hideHUDInView:kWindow]; + } +} + +///充值成功回调id +- (void)rechargeSuccess:(NSString *)transactionIdentifier { + ///保存唯一凭证 + [self saveRechageReciptWithTransactionIdentifier:transactionIdentifier]; + + ///二次验证 + @kWeakify(self); + [Api checkReceipt:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { + @kStrongify(self); + if (code == 200) { + + } else { + + } + } + chooseEnv:@"true" + chargeRecordId:self.orderId + transcationId:transactionIdentifier + uid:[AccountInfoStorage instance].getUid + ticket:[AccountInfoStorage instance].getTicket]; +} + +///充值成功之后保存订单到钥匙串 +- (void)saveRechageReciptWithTransactionIdentifier:(NSString *)transactionIdentifier { + NSData *receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]]; + NSString *encodeStr = [receipt base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]; + NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; + if(transactionIdentifier != nil){ + [dictionary setObject:transactionIdentifier forKey:@"transcationId"]; + } + if(encodeStr != nil){ + [dictionary setObject:encodeStr forKey:@"recipt"]; + } + if(self.orderId != nil){ + [dictionary setObject:self.orderId forKey:@"orderId"]; + } + if(dictionary.allKeys.count == 0)return; + NSString *reciptJson = [dictionary toJSONString]; + NSString * uid = [AccountInfoStorage instance].getUid; + BOOL saveSuccess = [RechargeStorage saveTranscationId:transactionIdentifier recipt:reciptJson uid:uid]; + if (!saveSuccess) { + NSLog(@"保存订单失败"); + } +} + +///二次验证成功 +- (void)checkReceiptSuccess:(NSString *)transcationId { + [XNDJTDDLoadingTool hideHUDInView:kWindow]; + if (@available(iOS 15.0, *)) { + PIIAPRegulate *iap = [PIIAPRegulate shared]; + [iap verifyBusinessAccomplishWithTransaction:[NSString stringWithFormat:@"%@",transcationId] completionHandler:^{ + + }]; + } + [self deleteRechageReciptWithTransactionIdentifier:transcationId]; + + [self triggerOpenPaymentCallback:200 + orderID:self.orderId + productID:transcationId]; +} + +///删除本地保存的 +- (void)deleteRechageReciptWithTransactionIdentifier:(NSString *)transactionIdentifier { + NSString * uid = [AccountInfoStorage instance].getUid; + BOOL deleteSuccess = [RechargeStorage delegateTranscationId:transactionIdentifier + uid:uid]; + if (deleteSuccess) { + NSLog(@"删除本地账单失败"); + } +} + +- (void)triggerOpenPaymentCallback:(NSInteger)code + orderID:(NSString *)orderID + productID:(NSString *)productID { + NSDictionary *dic = @{@"code":@(code), @"orderId":orderID, @"productId":productID}; + NSString *js = [NSString stringWithFormat:@"openPaymentCallback(%@)", dic.toJSONString]; + [self.webview evaluateJavaScript:js + completionHandler:^(id _Nullable result, NSError * _Nullable error) { + + }]; +} #pragma mark - private method - (void)handleRouterType:(NSInteger)skyType message:(WKScriptMessage *)message { @@ -635,38 +821,37 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold"; } - (void)showSharePanel { - if (self.shareDic.allKeys.count <= 0) { - return; - } - NSDictionary * dic = self.shareDic; - XPShareInfoModel * shareInfo = [[XPShareInfoModel alloc] init]; - shareInfo.shareTitle = self.shareDic[@"title"]; - shareInfo.shareContent = dic[@"desc"]; - shareInfo.shareImageUrl = dic[@"imgUrl"]; - shareInfo.type = ShareType_H5; - shareInfo.uid = [AccountInfoStorage instance].getUid; - NSString *urlStr = ((NSString *)dic[@"url"]).length > 0 ? dic[@"url"] : dic[@"showUrl"]; - if (urlStr.length) { - if ([urlStr containsString:@"?"]) { - urlStr = [NSString stringWithFormat:@"%@&shareUid=%@",urlStr,[AccountInfoStorage instance].getUid]; - } else { - urlStr = [NSString stringWithFormat:@"%@?shareUid=%@",urlStr,[AccountInfoStorage instance].getUid]; - } - } - shareInfo.shareUrl = urlStr; - XPShareItem *cycle = [XPShareItem itemWitTag:XPShareItemTagFaceBook title:@"FaceBook" imageName:@"share_fb" disableImageName:@"share_fb"]; - XPShareItem *wechat = [XPShareItem itemWitTag:XPShareItemTagLine title:@"Line" imageName:@"share_line" disableImageName:@"share_line"]; - XPShareItem *qq = [XPShareItem itemWitTag:XPShareItemTagCopyLink title:YMLocalizedString(@"XPWebViewNavView1") imageName:@"share_copy_link" disableImageName:@"share_copy_link"]; - XPShareItem *save = [XPShareItem itemWitTag:XPShareItemTagAppSaveAlbum title:YMLocalizedString(@"PIWebViewSavePhotoView4") imageName:@"share_save_icon" disableImageName:@"share_save_icon"]; - - NSArray * items = @[wechat,cycle, qq,save]; - CGFloat margin = 15; - CGSize itemSize = CGSizeMake((KScreenWidth-2*margin)/4, 65); - XPShareView *shareView = [[XPShareView alloc] initWithItems:items itemSize:itemSize shareInfo:shareInfo]; - shareView.delegate = self; + if (self.shareDic.allKeys.count <= 0) { + return; + } + NSDictionary * dic = self.shareDic; + XPShareInfoModel * shareInfo = [[XPShareInfoModel alloc] init]; + shareInfo.shareTitle = self.shareDic[@"title"]; + shareInfo.shareContent = dic[@"desc"]; + shareInfo.shareImageUrl = dic[@"imgUrl"]; + shareInfo.type = ShareType_H5; + shareInfo.uid = [AccountInfoStorage instance].getUid; + NSString *urlStr = ((NSString *)dic[@"url"]).length > 0 ? dic[@"url"] : dic[@"showUrl"]; + if (urlStr.length) { + if ([urlStr containsString:@"?"]) { + urlStr = [NSString stringWithFormat:@"%@&shareUid=%@",urlStr,[AccountInfoStorage instance].getUid]; + } else { + urlStr = [NSString stringWithFormat:@"%@?shareUid=%@",urlStr,[AccountInfoStorage instance].getUid]; + } + } + shareInfo.shareUrl = urlStr; + XPShareItem *cycle = [XPShareItem itemWitTag:XPShareItemTagFaceBook title:@"FaceBook" imageName:@"share_fb" disableImageName:@"share_fb"]; + XPShareItem *wechat = [XPShareItem itemWitTag:XPShareItemTagLine title:@"Line" imageName:@"share_line" disableImageName:@"share_line"]; + XPShareItem *qq = [XPShareItem itemWitTag:XPShareItemTagCopyLink title:YMLocalizedString(@"XPWebViewNavView1") imageName:@"share_copy_link" disableImageName:@"share_copy_link"]; + XPShareItem *save = [XPShareItem itemWitTag:XPShareItemTagAppSaveAlbum title:YMLocalizedString(@"PIWebViewSavePhotoView4") imageName:@"share_save_icon" disableImageName:@"share_save_icon"]; - [TTPopup popupView:shareView style:TTPopupStyleActionSheet]; + NSArray * items = @[wechat,cycle, qq,save]; + CGFloat margin = 15; + CGSize itemSize = CGSizeMake((KScreenWidth-2*margin)/4, 65); + XPShareView *shareView = [[XPShareView alloc] initWithItems:items itemSize:itemSize shareInfo:shareInfo]; + shareView.delegate = self; + [TTPopup popupView:shareView style:TTPopupStyleActionSheet]; } #pragma mark - XCShareViewDelegate @@ -856,8 +1041,10 @@ NSString * const kJSGoToExchangeGold = @"goToExchangeGold"; [_pi_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSSavePictureShare]; ///兑换金币 [_pi_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSGoToExchangeGold]; - - + ///周卡内购 + [_pi_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSOpenPayment]; + [_pi_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSOpenPaymentCallback]; + } return _pi_userContentController; diff --git a/YuMi/Tools/PIIAPTool/PIIAPRegulate.swift b/YuMi/Tools/PIIAPTool/PIIAPRegulate.swift index 0b9fbc04..212ba3c5 100644 --- a/YuMi/Tools/PIIAPTool/PIIAPRegulate.swift +++ b/YuMi/Tools/PIIAPTool/PIIAPRegulate.swift @@ -70,13 +70,11 @@ public class PIIAPRegulate: NSObject { if let scene = await view.window?.windowScene{ try await Transaction.beginRefundRequest(for:transactionId , in: scene) } - }catch{ print("iap error") } } - - + // 购买某个产品 @objc public func demandCommodityThing(productId:String, uuid: String) async throws { if(ConditionBlock != nil ){