Răsfoiți Sursa

内购修改

apple 5 ani în urmă
părinte
comite
b738aacd4d

BIN
ios/JianYuIOS/JianYuIOS.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate


+ 2 - 2
ios/JianYuIOS/JianYuIOS/BaseClass1/PrefixHeader.pch

@@ -142,7 +142,7 @@ _Pragma("clang diagnostic pop")\
 
 //#define kHost @"http://web-jydev-zyh.jianyu360.cn/" //张雨涵
 
-//#define kHost @"http://web-jydev-wcj.jianyu360.cn/" //王传近
+#define kHost @"http://web-jydev-wcj.jianyu360.cn/" //王传近
 
 //#define kHost @"http://web-jydev-wky.jianyu360.cn/" //王凯悦
 
@@ -150,7 +150,7 @@ _Pragma("clang diagnostic pop")\
 
 //#define kHost @"http://web-jydev-xzh.jianyu360.cn/" //徐志恒
 
-#define kHost @"http://web-jydev-zyx.jianyu360.cn/" 
+//#define kHost @"http://web-jydev-zyx.jianyu360.cn/"
 
 //#define kHost @"https://app-jytest.jianyu360.cn/"  //老测试
 //#define kHost @"http://anti.jianyu360.cn/"         //新测试

+ 64 - 2
ios/JianYuIOS/JianYuIOS/Classes(模块)/JYNewExpViewController.m

@@ -11,7 +11,7 @@
 #import "JYTabBarController.h"
 #import <CoreLocation/CoreLocation.h>
 
-@interface JYNewExpViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
+@interface JYNewExpViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,SKProductsRequestDelegate>
 {
     CGPoint startTouch;
     BOOL _isMoving;
@@ -165,6 +165,9 @@ NSString *const new_AesKey_3 = @"mGlAgnIBB8bx2nch";
     
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshExpAndMine:) name:RefreshExpAndMine object:nil];
     
+    
+    //监听购买结果
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiptData:) name:@"receiptData" object:nil];
 }
 
 #pragma mark – Gesture Recognizer –
@@ -271,6 +274,10 @@ NSString *const new_AesKey_3 = @"mGlAgnIBB8bx2nch";
        [self jsSkipAlbum:message.body];
     }else if ([message.name isEqualToString:@"openActivityPage"]) {
        [self jsOpenActivityPage:message.body];
+    }else if ([message.name isEqualToString:@"callPhone"]) {
+       [self jsCallPhone:message.body];
+    }else if ([message.name isEqualToString:@"inPurchasingVip"]) {
+       [self jsInPurchasingVip:message.body];
     }else {
         
     }
@@ -798,6 +805,51 @@ NSString *const new_AesKey_3 = @"mGlAgnIBB8bx2nch";
     
 }
 
+//拨打电话
+-(void)jsCallPhone:(NSDictionary *)dict {
+    NSString *phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
+    NSMutableString *tel = [[NSMutableString alloc]initWithFormat:@"telprompt://%@",phone];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
+    });
+}
+
+//内购VIP
+-(void)jsInPurchasingVip:(NSDictionary *)dict {
+    NSString *productid = [NSString stringWithFormat:@"%@",dict[@"productid"]];
+    //产品id
+    if ([productid isEqualToString:@""]) {
+        NSLog(@"订单号 有问题");
+        [[LXDataBaseManager shareDataBaseManager]showHudOnlyText:@"订单号异常,请重试" delay:1];
+        return;
+    }
+    [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果支付中"];
+    if([SKPaymentQueue canMakePayments]){
+        [self requestProductData:productid];
+    }else{
+        [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"不允许程序内付费" delay:1];
+    }
+}
+
+//去苹果服务器请求商品
+- (void)requestProductData:(NSString *)type {
+    NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
+    NSSet *nsset = [NSSet setWithArray:product];
+    SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
+    request.delegate = self;
+    [request start];
+}
+- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
+    NSArray *myProduct = response.products;
+    if (myProduct.count == 0) {
+        NSLog(@"无法获取产品信息,购买失败。");
+        [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"无法获取产品信息,购买失败。" delay:1];
+        return;
+    }
+    SKPayment * payment = [SKPayment paymentWithProduct:myProduct[0]];
+    [[SKPaymentQueue defaultQueue] addPayment:payment];
+}
+
 // web是否可退回上页面
 -(int)jsIsCanBack:(NSString *)str{
     return self.webView.canGoBack ? 1:0;
@@ -906,7 +958,6 @@ NSString *const new_AesKey_3 = @"mGlAgnIBB8bx2nch";
         if (iPhoneX) {
             if (@available(iOS 11.0, *)) {
                 self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
-                NSLog(@"%@",self.webView)
             }
         }else {
             self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
@@ -1228,6 +1279,17 @@ NSString *const new_AesKey_3 = @"mGlAgnIBB8bx2nch";
     [self webViewFirstRequest];
 }
 
+//内购相关
+-(void)receiptData:(NSNotification *)notificaition{
+    if(self.tabBarController.selectedIndex == 2) {
+        NSDictionary *infoDict = notificaition.userInfo;
+        if (infoDict) {
+            NSString *receipt = [NSString stringWithFormat:@"%@", infoDict[@"receipt"]];
+            [self isExitCallToJS:[NSString stringWithFormat:@"getReceipt('%@')", receipt] withMethodName:@"getReceipt"];
+        }
+    }
+}
+
 -(void)clearWeb{
     NSURLCache * cache = [NSURLCache sharedURLCache];
     [cache removeAllCachedResponses];

+ 64 - 2
ios/JianYuIOS/JianYuIOS/Classes(模块)/JYNewMineViewController.m

@@ -21,7 +21,7 @@
 
 
 
-@interface JYNewMineViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
+@interface JYNewMineViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,SKProductsRequestDelegate>
 {
     CGPoint startTouch;
     BOOL _isMoving;
@@ -178,6 +178,9 @@ NSString *const new_AesKey_4 = @"mGlAgnIBB8bx2nch";
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNonCurVC:) name:RefreshNonCurVC object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAllVC:) name:RefreshAllVC object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshExpAndMine:) name:RefreshExpAndMine object:nil];
+    
+    //监听购买结果
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiptData:) name:@"receiptData" object:nil];
 
 }
 
@@ -286,6 +289,10 @@ NSString *const new_AesKey_4 = @"mGlAgnIBB8bx2nch";
        [self jsSkipAlbum:message.body];
     }else if ([message.name isEqualToString:@"openActivityPage"]) {
        [self jsOpenActivityPage:message.body];
+    }else if ([message.name isEqualToString:@"callPhone"]) {
+       [self jsCallPhone:message.body];
+    }else if ([message.name isEqualToString:@"inPurchasingVip"]) {
+       [self jsInPurchasingVip:message.body];
     }else {
         
     }
@@ -815,6 +822,52 @@ NSString *const new_AesKey_4 = @"mGlAgnIBB8bx2nch";
     
 }
 
+
+//拨打电话
+-(void)jsCallPhone:(NSDictionary *)dict {
+    NSString *phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
+    NSMutableString *tel = [[NSMutableString alloc]initWithFormat:@"telprompt://%@",phone];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
+    });
+}
+
+//内购VIP
+-(void)jsInPurchasingVip:(NSDictionary *)dict {
+    NSString *productid = [NSString stringWithFormat:@"%@",dict[@"productid"]];
+    //产品id
+    if ([productid isEqualToString:@""]) {
+        NSLog(@"订单号 有问题");
+        [[LXDataBaseManager shareDataBaseManager]showHudOnlyText:@"订单号异常,请重试" delay:1];
+        return;
+    }
+    [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果支付中"];
+    if([SKPaymentQueue canMakePayments]){
+        [self requestProductData:productid];
+    }else{
+        [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"不允许程序内付费" delay:1];
+    }
+}
+
+//去苹果服务器请求商品
+- (void)requestProductData:(NSString *)type {
+    NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
+    NSSet *nsset = [NSSet setWithArray:product];
+    SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
+    request.delegate = self;
+    [request start];
+}
+- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
+    NSArray *myProduct = response.products;
+    if (myProduct.count == 0) {
+        NSLog(@"无法获取产品信息,购买失败。");
+        [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"无法获取产品信息,购买失败。" delay:1];
+        return;
+    }
+    SKPayment * payment = [SKPayment paymentWithProduct:myProduct[0]];
+    [[SKPaymentQueue defaultQueue] addPayment:payment];
+}
+
 // web是否可退回上页面
 -(int)jsIsCanBack:(NSString *)str{
     return self.webView.canGoBack ? 1:0;
@@ -922,7 +975,6 @@ NSString *const new_AesKey_4 = @"mGlAgnIBB8bx2nch";
         if (iPhoneX) {
             if (@available(iOS 11.0, *)) {
                 self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
-                NSLog(@"%@",self.webView)
             }
         }else {
             self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
@@ -1246,6 +1298,16 @@ NSString *const new_AesKey_4 = @"mGlAgnIBB8bx2nch";
     [self webViewFirstRequest];
 }
 
+//内购相关
+-(void)receiptData:(NSNotification *)notificaition{
+    if(self.tabBarController.selectedIndex == 3) {
+        NSDictionary *infoDict = notificaition.userInfo;
+        if (infoDict) {
+            NSString *receipt = [NSString stringWithFormat:@"%@", infoDict[@"receipt"]];
+            [self isExitCallToJS:[NSString stringWithFormat:@"getReceipt('%@')", receipt] withMethodName:@"getReceipt"];
+        }
+    }
+}
 -(void)clearWeb{
     NSURLCache * cache = [NSURLCache sharedURLCache];
     [cache removeAllCachedResponses];

+ 25 - 18
ios/JianYuIOS/JianYuIOS/Classes(模块)/JYNewSearchViewController.m

@@ -1062,13 +1062,13 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
     //产品id
     if ([productid isEqualToString:@""]) {
         NSLog(@"订单号 有问题");
-        [[LXDataBaseManager shareDataBaseManager]showHudOnlyText:@"订单号异常" delay:1];
+        [[LXDataBaseManager shareDataBaseManager]showHudOnlyText:@"订单号异常,请重试" delay:1];
         return;
     }
     [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果支付中"];
     //监听购买结果
     if([SKPaymentQueue canMakePayments]){
-        [self requestProductData:@"com.topnet.vip.000001"];
+        [self requestProductData:productid];
     }else{
         NSLog(@"不允许程序内付费");
         [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"不允许程序内付费" delay:1];
@@ -1116,23 +1116,31 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
         }
     }
 }
- - (void)completeTransaction:(SKPaymentTransaction *)transaction {
-     // Your application should implement these two methods.
-     
-     [[LXViewControllerManager shareViewControllerManager] hideHud];
-     NSString * productIdentifier = transaction.payment.productIdentifier;
-//     NSString * receipt = [transaction.transactionReceipt base64EncodedString];
+- (void)completeTransaction:(SKPaymentTransaction *)transaction {
+    // Your application should implement these two methods.
+    [[LXViewControllerManager shareViewControllerManager] hideHud];
+    NSString * productIdentifier = transaction.payment.productIdentifier;
+    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] appStoreReceiptURL]];
+    NSData *receiptData;
+    NSError *error = nil;
+    receiptData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:&error];
+    NSString *receipt = [receiptData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
      if ([productIdentifier length] > 0) {
          // 向自己的服务器验证购买凭证
-         
-         
-         
+         if(self.tabBarController.selectedIndex == 0) {
+              [self isExitCallToJS:[NSString stringWithFormat:@"getReceipt('%@')", receipt] withMethodName:@"getReceipt"];
+         }else {
+             [[NSNotificationCenter defaultCenter] postNotificationName:@"receiptData" object:nil userInfo:@{@"receipt":receipt}];
+         }
      }
      // Remove the transaction from the payment queue.
      [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
   
- }
- - (void)failedTransaction:(SKPaymentTransaction *)transaction {
+}
+
+
+
+- (void)failedTransaction:(SKPaymentTransaction *)transaction {
      [[LXViewControllerManager shareViewControllerManager] hideHud];
      if(transaction.error.code != SKErrorPaymentCancelled) {
          NSLog(@"购买失败");
@@ -1142,14 +1150,13 @@ NSString *const new_AesKey_1 = @"mGlAgnIBB8bx2nch";
          [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"取消交易" delay:1];
      }
      [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
- }
- - (void)restoreTransaction:(SKPaymentTransaction *)transaction {\
-   // 对于已购商品,处理恢复购买的逻辑
+}
+- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
+     // 对于已购商品,处理恢复购买的逻辑
      NSLog(@"对于已购商品,处理恢复购买的逻辑");
      [[LXViewControllerManager shareViewControllerManager] hideHud];
      [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
- }
-
+}
 
 
 

+ 75 - 3
ios/JianYuIOS/JianYuIOS/Classes(模块)/JYNewSubViewController.m

@@ -11,7 +11,7 @@
 #import "JYTabBarController.h"
 #import <CoreLocation/CoreLocation.h>
 
-@interface JYNewSubViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
+@interface JYNewSubViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,CLLocationManagerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,SKProductsRequestDelegate>
 {
     CGPoint startTouch;
     BOOL _isMoving;
@@ -172,6 +172,8 @@ NSString *const new_AesKey_2 = @"mGlAgnIBB8bx2nch";
     //接收全新通知
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNonCurVC:) name:RefreshNonCurVC object:nil];
 
+    //监听购买结果
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiptData:) name:@"receiptData" object:nil];
 }
 
 #pragma mark – Gesture Recognizer –
@@ -278,6 +280,10 @@ NSString *const new_AesKey_2 = @"mGlAgnIBB8bx2nch";
        [self jsSkipAlbum:message.body];
     }else if ([message.name isEqualToString:@"openActivityPage"]) {
        [self jsOpenActivityPage:message.body];
+    }else if ([message.name isEqualToString:@"callPhone"]) {
+       [self jsCallPhone:message.body];
+    }else if ([message.name isEqualToString:@"inPurchasingVip"]) {
+       [self jsInPurchasingVip:message.body];
     }else {
         
     }
@@ -367,7 +373,7 @@ NSString *const new_AesKey_2 = @"mGlAgnIBB8bx2nch";
     }];
 }
 -(void)executeCallJS:(NSString *)jsStr {
-     NSLog(@"OC调JS交互%@:",jsStr);
+//     NSLog(@"OC调JS交互%@:",jsStr);
     [_webView evaluateJavaScript:jsStr completionHandler:^(id _Nullable result, NSError * _Nullable error) {
        if (error!=nil) {
            NSLog(@"result:%@,error:%@",result,error);
@@ -397,6 +403,9 @@ NSString *const new_AesKey_2 = @"mGlAgnIBB8bx2nch";
     
     //监听底部栏
     [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(bottomTwoListening) userInfo:nil repeats:YES];
+
+    
+    
 }
 -(void)bottomTwoListening {
     if(self.tabBarController.selectedIndex == 1) {
@@ -807,12 +816,64 @@ NSString *const new_AesKey_2 = @"mGlAgnIBB8bx2nch";
     
 }
 
+//拨打电话
+-(void)jsCallPhone:(NSDictionary *)dict {
+    NSString *phone = [NSString stringWithFormat:@"%@",dict[@"phone"]];
+    NSMutableString *tel = [[NSMutableString alloc]initWithFormat:@"telprompt://%@",phone];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
+    });
+}
+
+//内购VIP
+-(void)jsInPurchasingVip:(NSDictionary *)dict {
+    NSString *productid = [NSString stringWithFormat:@"%@",dict[@"productid"]];
+    //产品id
+    if ([productid isEqualToString:@""]) {
+        NSLog(@"订单号 有问题");
+        [[LXDataBaseManager shareDataBaseManager]showHudOnlyText:@"订单号异常,请重试" delay:1];
+        return;
+    }
+    [[LXViewControllerManager shareViewControllerManager] showHudText:@"苹果支付中"];
+    if([SKPaymentQueue canMakePayments]){
+        [self requestProductData:productid];
+    }else{
+        [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"不允许程序内付费" delay:1];
+    }
+}
+
+//去苹果服务器请求商品
+- (void)requestProductData:(NSString *)type {
+    NSArray *product = [[NSArray alloc] initWithObjects:type,nil];
+    NSSet *nsset = [NSSet setWithArray:product];
+    SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:nsset];
+    request.delegate = self;
+    [request start];
+}
+- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
+    NSArray *myProduct = response.products;
+    if (myProduct.count == 0) {
+        NSLog(@"无法获取产品信息,购买失败。");
+        [[LXViewControllerManager shareViewControllerManager]showHudOnlyText:@"无法获取产品信息,购买失败。" delay:1];
+        return;
+    }
+    SKPayment * payment = [SKPayment paymentWithProduct:myProduct[0]];
+    [[SKPaymentQueue defaultQueue] addPayment:payment];
+}
+ 
+
+
+
+
+
+
 // web是否可退回上页面
 -(int)jsIsCanBack:(NSString *)str{
     return self.webView.canGoBack ? 1:0;
 }
 
 
+
 #pragma mark   *****其他方法
 -(void)judgeIsHiddenBottom {
     if(self.tabBarController.selectedIndex == 1) {
@@ -911,7 +972,6 @@ NSString *const new_AesKey_2 = @"mGlAgnIBB8bx2nch";
         if (iPhoneX) {
             if (@available(iOS 11.0, *)) {
                 self.webView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
-                NSLog(@"%@",self.webView)
             }
         }else {
             self.webView.frame = CGRectMake(0, -STATUS_BAR_HEIGHT, WIDTH, HEIGHT+STATUS_BAR_HEIGHT);
@@ -1231,6 +1291,18 @@ NSString *const new_AesKey_2 = @"mGlAgnIBB8bx2nch";
 
 
 
+//内购相关
+-(void)receiptData:(NSNotification *)notificaition{
+    if(self.tabBarController.selectedIndex == 1) {
+        NSDictionary *infoDict = notificaition.userInfo;
+        if (infoDict) {
+            NSString *receipt = [NSString stringWithFormat:@"%@", infoDict[@"receipt"]];
+            [self isExitCallToJS:[NSString stringWithFormat:@"getReceipt('%@')", receipt] withMethodName:@"getReceipt"];
+        }
+    }
+}
+
+
 
 -(void)clearWeb{
     NSURLCache * cache = [NSURLCache sharedURLCache];