Forráskód Böngészése

【订阅】Appstore 二次验证参数添加

lizhe 1 éve
szülő
commit
8ac3825444

+ 24 - 16
PDF Office/PDF Master/Class/KMLightMember/Controller/ComparativeTable/View/KMComparativeView/View/KMComparativeViewCollectionItem.swift

@@ -87,23 +87,11 @@ class KMComparativeViewCollectionItem: NSCollectionViewItem {
                 }
                 
                 if KMInAppPurchaseManager.manager.availableProducts.count == 0 {
-                    KMInAppPurchaseManager.manager.fetchProducts { [unowned self] isSuccess, products, error in
-                        let productId: String = data["productId"] as! String
-                        for product in KMInAppPurchaseManager.manager.availableProducts {
-                            if product.productIdentifier == productId {
-                                print("-----------------------------")
-                                print(product.priceLocale.currencyCode)
-                                print(product.introductoryPrice?.price)
-                                print(product.price)
-                                print("-----------------------------")
-                                let currencyCode: String = product.priceLocale.currencyCode ?? "$"
-                                let price: String = product.introductoryPrice?.price.description ?? "39.9"
-                                let originPrice: String = product.price.description ?? "79.9"
-                                self.subtitleLabel.stringValue = "\(currencyCode) \(price)"
-                                self.describeLabel.stringValue = "\(currencyCode) \(originPrice) \(describe)"
-                            }
-                        }
+                    KMInAppPurchaseManager.manager.fetchProducts { [weak self] isSuccess, products, error in
+                        self?.updatePrice()
                     }
+                } else {
+                    self.updatePrice()
                 }
             } else {
                 self.describeLabel.isHidden = true
@@ -117,6 +105,26 @@ class KMComparativeViewCollectionItem: NSCollectionViewItem {
             self.contentCollectionView.reloadData()
         }
     }
+    
+    func updatePrice() {
+        for product in KMInAppPurchaseManager.manager.availableProducts {
+            let productId: String = self.data["productId"] as! String
+            let describe = NSLocalizedString(data["describe"] as? String ?? "", comment: "")
+            
+            if product.productIdentifier == productId {
+                print("-----------------------------")
+                print(product.priceLocale.currencyCode)
+                print(product.introductoryPrice?.price)
+                print(product.price)
+                print("-----------------------------")
+                let currencyCode: String = product.priceLocale.currencyCode ?? "$"
+                let price: String = product.introductoryPrice?.price.description ?? "39.9"
+                let originPrice: String = product.price.description ?? "79.9"
+                self.subtitleLabel.stringValue = "\(currencyCode) \(price)"
+                self.describeLabel.stringValue = "\(currencyCode) \(originPrice) \(describe)"
+            }
+        }
+    }
 }
 
 extension KMComparativeViewCollectionItem {

+ 21 - 15
PDF Office/PDF Master/Class/KMLightMember/Controller/SubscriptionView/WaterMark/View/KMSubscribeWaterMarkView.swift

@@ -112,22 +112,11 @@ class KMSubscribeWaterMarkView: KMBaseXibView {
         self.textView.isHidden = false
         
         if KMInAppPurchaseManager.manager.availableProducts.count == 0 {
-            KMInAppPurchaseManager.manager.fetchProducts { [unowned self] isSuccess, products, error in
-                let productId: String = PRODUCT_1
-                for product in KMInAppPurchaseManager.manager.availableProducts {
-                    if product.productIdentifier == productId {
-                        print("-----------------------------")
-                        print(product.priceLocale.currencyCode)
-                        print(product.introductoryPrice?.price)
-                        print(product.price)
-                        print("-----------------------------")
-                        let currencyCode: String = product.priceLocale.currencyCode ?? "$"
-                        let price: String = product.introductoryPrice?.price.description ?? "39.9"
-                        let originPrice: String = product.price.description ?? "79.9"
-                        self.subscribeButton.title = "\(currencyCode) \(price) / year"
-                    }
-                }
+            KMInAppPurchaseManager.manager.fetchProducts { [weak self] isSuccess, products, error in
+                self?.updatePrice()
             }
+        } else {
+            self.updatePrice()
         }
 #endif
 
@@ -144,6 +133,23 @@ class KMSubscribeWaterMarkView: KMBaseXibView {
         }
             
     }
+    
+    func updatePrice() {
+        let productId: String = PRODUCT_1
+        for product in KMInAppPurchaseManager.manager.availableProducts {
+            if product.productIdentifier == productId {
+                print("-----------------------------")
+                print(product.priceLocale.currencyCode)
+                print(product.introductoryPrice?.price)
+                print(product.price)
+                print("-----------------------------")
+                let currencyCode: String = product.priceLocale.currencyCode ?? "$"
+                let price: String = product.introductoryPrice?.price.description ?? "39.9"
+                let originPrice: String = product.price.description ?? "79.9"
+                self.subscribeButton.title = "\(currencyCode) \(price) / year"
+            }
+        }
+    }
 }
 
 extension KMSubscribeWaterMarkView {

+ 1 - 1
PDF Office/PDF Master/Class/KMLightMember/InAppPurchase/Appstore/KMInAppPurchaseManager.swift

@@ -254,7 +254,7 @@ extension KMInAppPurchaseManager: SKPaymentTransactionObserver {
         let tempOrderId = self.orderId ?? ""
         print(receiptString)
         if transaction.transactionState == .restored {
-            KMRequestServerManager.manager.parseVerification(applePayProductId: PRODUCT_1, orderId: tempOrderId, receipt: receiptString) { [unowned self] success, result in
+            KMRequestServerManager.manager.parseVerification(applePayProductId: PRODUCT_1, orderId: tempOrderId, receipt: receiptString, restore: 1) { [unowned self] success, result in
                 if success, let data = result?.result {
                     // 处理服务器返回的验证结果
                     //解析数据

+ 3 - 2
PDF Office/PDF Master/Class/KMLightMember/Manager/KMRequestServerManager.swift

@@ -498,11 +498,12 @@ extension KMRequestServerManager {
         }
     }
     
-    func parseVerification(applePayProductId: String, orderId: String, receipt: String,complete: @escaping KMRequestServerComplete) {
+    func parseVerification(applePayProductId: String, orderId: String, receipt: String, restore: Int = 0, complete: @escaping KMRequestServerComplete) {
         let urlString = KMLightMemberManager.manager.config.kServerURL + "/pdf-office-website/pay/appStoreOrderSucceed"
         let params: [String: Any] = ["applePayProductId": applePayProductId,
                                      "orderId": orderId,
-                                     "receipt": receipt]
+                                     "receipt": receipt,
+                                     "restore": restore]
         print("二次验证上传数据:\(params)")
         let token: String = KMLightMemberManager.manager.token.access_token
         if token == "" {