فهرست منبع

Merge branch 'develop_PDFReaderPro_V4.7.0' of git.kdan.cc:Mac_PDF/PDF_Office into develop_PDFReaderPro_V4.7.0

niehaoyu 3 ماه پیش
والد
کامیت
05e8e1a4d4

+ 15 - 15
PDF Office/PDF Master/Class/Purchase/IAPProductsManager.m

@@ -1368,12 +1368,12 @@ NSString * const KMIAPSubscriptionLoadedNotification = @"KMIAPSubscriptionLoaded
         self.allAccessPackNew6months_lite.isSubscribed = YES;
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
     } else if ([productIdentifier isEqualToString:self.allAccessPack12months_lite.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.allAccessPack12months_lite.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.allAccessPackPermanent_lite.productIdentifier]) {
@@ -1401,73 +1401,73 @@ NSString * const KMIAPSubscriptionLoadedNotification = @"KMIAPSubscriptionLoaded
     } else if ([productIdentifier isEqualToString:self.fourDevicesAllAccessPackNew6Months_lite.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.fourDevicesAllAccessPackNew6Months_lite.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.fourDevicesAllAccessPackNew12months_lite.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.fourDevicesAllAccessPackNew12months_lite.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.advancedAddDevicesAllAccessPack12months_lite.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.advancedAddDevicesAllAccessPack12months_lite.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.advancedAdd2DevicesAllAccessPack12months_lite.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.advancedAdd2DevicesAllAccessPack12months_lite.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.aiAllAccessPack12month_lite.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.aiAllAccessPack12month_lite.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.aiAllAccessPack12month_pro.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.aiAllAccessPack12month_pro.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.standardAddDevicesAllAccessPack12months_pro.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.standardAddDevicesAllAccessPack12months_pro.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.advancedAddDevicesAllAccessPack12months_pro.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.advancedAddDevicesAllAccessPack12months_pro.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.advancedAdd2DevicesAllAccessPack12months_pro.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.advancedAdd2DevicesAllAccessPack12months_pro.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.aiAllAccessPack1month_lite.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.aiAllAccessPack1month_lite.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.aiAllAccessPack1month_pro.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.aiAllAccessPack1month_pro.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.fourDevicesAllAccessPack12months_pro.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
             [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:nil];
+                                                                object:transaction];
         }];
         self.fourDevicesAllAccessPack12months_pro.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.allAccessProduct.productIdentifier]) {
@@ -1513,7 +1513,6 @@ NSString * const KMIAPSubscriptionLoadedNotification = @"KMIAPSubscriptionLoaded
                                          NSLocalizedString(@"—》Due to Apple needs to confirm your purchase info, you may be required to sign in with your Apple ID. When you restore your purchase, make sure you use the same Apple ID that you previously used.", nil),
                                          NSLocalizedString(@"—》Once you see the \"Restore Successfully\" message, you will be able to access the advanced features, including PDF to Office, PDF Watermark, Page Editor, and more.", nil)];
             }
-            
             NSAlert *alert = [[[NSAlert alloc] init] autorelease];
             [alert addButtonWithTitle:NSLocalizedString(@"OK", nil)];
             [alert setAlertStyle:NSAlertStyleWarning];
@@ -1760,6 +1759,7 @@ NSString * const KMIAPSubscriptionLoadedNotification = @"KMIAPSubscriptionLoaded
                 break;
             case SKPaymentTransactionStateRestored:
                 [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
+                [self productDidPurchased:transaction];
                 break;
         }
     }

+ 27 - 22
PDF Office/PDF Master/MemberCenter/Model/KMMemberCenterManager.swift

@@ -1497,35 +1497,40 @@ class KMMemberCenterManager: NSObject {
             return
         }
         let urlString = configuration.activityBaseURL() + "/member-system-website/applePay/appStoreEquityVerification"
-        let params: [String: Any] = ["userId": KMMemberInfo.shared.userID,
+        let bundleID = Bundle.main.object(forInfoDictionaryKey: "CFBundleIdentifier") ?? ""
+        let params: [String: Any] = ["appBundleId": bundleID,
                                      "applePayProductId": applePayProductId,
                                      "transactionId": transactionId,
                                      "productCode": productCode]
-        KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
-            requestSerializer.setValue("Bearer " + token, forHTTPHeaderField: "Authorization")
-        } completion: { [weak self] (task, responseObject, error) in
-            var dic: NSDictionary = [:]
-            if error == nil, let responseObject = responseObject as? NSDictionary {
-                dic = responseObject
-            } else {
-                var info = responseObject
-                if let error = error {
-                    if let data = error.userInfo["com.alamofire.serialization.response.error.data"] as? Data {
-                        info = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? NSDictionary
-                    }
-                }
-                dic = (info as? NSDictionary) ?? [:]
+        let postData  = try! JSONSerialization.data(withJSONObject: params)
+        
+        var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
+        request.addValue("Bearer " + token, forHTTPHeaderField: "Authorization")
+        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
+        request.httpMethod = "POST"
+        request.httpBody = postData
+        
+        let task = URLSession.shared.dataTask(with: request) { data, response, error in
+            guard let data = data else {
+                print(String(describing: error))
+                return
             }
-            let code: Int = dic["code"] as? Int ?? 0
-            let result: NSDictionary = dic["result"] as? NSDictionary ?? [:]
-            let message: String = dic["msg"] as? String ?? ""
-            let result1 = KMMemberProductResult(code: code, msg: message, result: "")
-            if code == 200 {
-                complete(true, result1)
+            let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:]
+            if jsonObject != nil {
+                let code: Int = jsonObject!["code"] as? Int ?? 0
+                let result: NSDictionary = jsonObject!["result"] as? NSDictionary ?? [:]
+                let message: String = jsonObject!["msg"] as? String ?? ""
+                let result1 = KMMemberProductResult(code: code, msg: message, result: "")
+                if code == 200 {
+                    complete(true, result1)
+                } else {
+                    complete(false, result1)
+                }
             } else {
-                complete(false, result1)
+                complete(false, KMMemberProductResult(code: 0, msg: "", result: ""))
             }
         }
+        task.resume()
     }
 
 

+ 14 - 9
PDF Office/PDF Master/MemberCenter/ViewModel/KMProductModel.swift

@@ -7,6 +7,9 @@
 
 import Foundation
 import Combine
+#if !VERSION_DMG
+import StoreKit
+#endif
 
 @objc enum KMCompareTableType : Int {
     case trial = 0 // 试用比较表
@@ -503,9 +506,9 @@ class KMProductModel: ObservableObject {
     }
     
     func appStoreEquityVerification(_ notification: Notification,_ complete: @escaping KMMemberProductComplete) -> Void {
-        if let userInfo = notification.userInfo,
-           let transactionId = userInfo["transactionId"] as? String,
-           let productId = userInfo["productId"] as? String {
+        if let userInfo = notification.object as? SKPaymentTransaction,
+           let transactionId = userInfo.transactionIdentifier as? String,
+           let productId = userInfo.payment.productIdentifier as? String {
             print("Transaction ID: \(transactionId)")
             print("product ID: \(productId)")
             
@@ -592,13 +595,15 @@ class KMProductModel: ObservableObject {
                 }
             }
 #endif
-            KMMemberCenterManager.manager.appStoreEquityVerification(applePayProductId: productId, transactionId: transactionId, productCode: productCode) { success, result in
-                if success {
-                    complete(true, result)
-                } else {
-                    complete(false, result)
-                }
+            if isSubscribed {
+                KMMemberCenterManager.manager.appStoreEquityVerification(applePayProductId: productId, transactionId: transactionId, productCode: productCode) { success, result in
+                    if success {
+                        complete(true, result)
+                    } else {
+                        complete(false, result)
+                    }
 
+                }
             }
         } else {
             print("Transaction ID not found in notification.")