Bladeren bron

1.增加订阅上报过程
2.会员收到价格后,主动刷新订阅页面

100Years 1 week geleden
bovenliggende
commit
1f51905d7d

+ 13 - 8
AIEmoji/Business/TSAILIstVC/TSAILIstVC/TSAILIstCell.swift

@@ -67,10 +67,20 @@ class TSAILIstCell: TSBaseCollectionCell {
             make.bottom.leading.trailing.equalTo(0)
             make.height.equalTo(90*kDesignScale)
         }
- 
+        submitBtn.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
+        bgContentView.addSubview(submitBtn)
+        submitBtn.snp.makeConstraints { make in
+            make.trailing.equalTo(-16)
+            make.bottom.equalTo(-27)
+            make.height.equalTo(24)
+            // 设置按钮宽度根据内容自适应
+            make.width.equalTo(submitBtn.intrinsicContentSize.width)
+        }
+        
+        leftSubLab.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
         bgContentView.addSubview(leftSubLab)
         leftSubLab.snp.makeConstraints { make in
-            make.trailing.equalTo(-110*kDesignScale)
+            make.trailing.equalTo(submitBtn.snp.leading).offset(-15)
             make.leading.equalTo(16)
             make.bottom.equalTo(-12)
         }
@@ -82,12 +92,7 @@ class TSAILIstCell: TSBaseCollectionCell {
             make.bottom.equalTo(leftSubLab.snp.top).offset(-8)
         }
         
-        bgContentView.addSubview(submitBtn)
-        submitBtn.snp.makeConstraints { make in
-            make.trailing.equalTo(-16)
-            make.bottom.equalTo(-27)
-            make.height.equalTo(24)
-        }
+
     }
     
 }

+ 5 - 0
AIEmoji/Business/TSPurchaseMembershipVC/TSPurchaseVC.swift

@@ -141,11 +141,16 @@ class TSPurchaseVC: TSBaseVC {
         hostVc.view.snp.makeConstraints { make in
             make.leading.trailing.bottom.top.equalToSuperview()
         }
+        
     }
     
     override func dealThings() {
         addNotifaction()
         onPurchaseStateChanged()
+        NotificationCenter.default.addObserver(forName: .kPurchasePrepared, object: nil, queue: OperationQueue.main) { [weak self] _ in
+            guard let self = self else { return }
+            viewModel.selectedType = viewModel.selectedType
+        }
     }
     
     

+ 48 - 1
AIEmoji/Common/Purchase/TSPurchaseManager+DataReport.swift

@@ -14,18 +14,65 @@ extension PurchaseManager {
     case result = "subscription_result"
     }
     
-
     func subscriptionApple(type:ReportType,jsonString:String){
+
         let postDict:[String:Any] = [
             "type":type.rawValue,
             "data":jsonString,
             "device":getUserInfoJsonString()
         ]
+    
+//        debugPrint("postDict=\(postDict)")
 
         TSNetworkShared.post(urlType: .subscriptionApple,parameters: postDict) { _,_ in
             
         }
     }
     
+    func simplifyVerifyPayResult(resp:[String: Any])->String {
+        
+        var dict:[String: Any] = [:]
+        if let info = resp["pending_renewal_info"] {
+            dict["pending_renewal_info"] = info
+        }
+        
+        if let info = resp["environment"] {
+            dict["environment"] = info
+        }
+        
+        if let info = resp["status"] {
+            dict["status"] = info
+        }
+        
+        if let receiptDict = resp["receipt"] as? [String: Any] {
+            var receiptDict = receiptDict
+    
+            //in_app 是数据,里面存放了所有购买的记录,按照product_id有远到近排列
+            //目的是,每个product_id,只要最近的一条
+            if let in_appArray = receiptDict["in_app"] as? [[String: Any]]{
+                var haveDict:[String:String] = [:]
+                var smallInAppList:[[String: Any]] = []
+                let array = in_appArray.reversed()
+                for dic in array{
+                    if let product_id = dic["product_id"] as? String{
+                        if let _ = haveDict[product_id] {
+                            
+                        }else{
+                            haveDict[product_id] = "1"
+                            smallInAppList.append(dic)
+                        }
+                    }
+                }
+                
+                receiptDict["in_app"] = smallInAppList
+            }
+            
+            dict["receipt"] = receiptDict
+        }
+        debugPrint("dict=\(dict)")
+        return dict.toJSONString() ?? ""
+    }
+    
+    
     
 }

+ 11 - 4
AIEmoji/Common/Purchase/TSPurchaseManager.swift

@@ -143,9 +143,9 @@ public class PurchaseManager: NSObject {
     }
 
     @objc public var isVip: Bool {
-        #if DEBUG
-            return true
-        #endif
+//        #if DEBUG
+//            return true
+//        #endif
         guard let expiresDate = expiredDate else {
             return false
         }
@@ -252,6 +252,8 @@ extension PurchaseManager {
         purchase(self, didChaged: .restoreing, object: nil)
         SKPaymentQueue.default().restoreCompletedTransactions()
         debugPrint("PurchaseManager restoreCompletedTransactions")
+        
+        subscriptionApple(type: .created, jsonString: "Payment restore")
     }
 
     /// 购买支付
@@ -271,6 +273,8 @@ extension PurchaseManager {
             let payment = SKPayment(product: product)
             SKPaymentQueue.default().add(payment)
             debugPrint("PurchaseManager pay period = \(period)")
+            
+            subscriptionApple(type: .created, jsonString: "Payment period = \(product)")
         }else{
             purchase(self, didChaged: .payFail, object: "Payment failed, no this item")
         }
@@ -339,7 +343,7 @@ extension PurchaseManager: SKPaymentTransactionObserver {
                     message = "The subscription was canceled"
                 }
                 purchase(self, didChaged: .payFail, object: message)
-
+                subscriptionApple(type: .result, jsonString: message)
             case .restored:
                 SKPaymentQueue.default().finishTransaction(transaction)
                 //同样的原始订单,只处理一次.
@@ -357,6 +361,7 @@ extension PurchaseManager: SKPaymentTransactionObserver {
                     #endif
                 } else {
                     purchase(self, didChaged: .restoreFail, object: "Failed to restore subscribe, please try again")
+                    subscriptionApple(type: .result, jsonString: "Failed to restore subscribe, please try again")
                 }
                 
             case .deferred: // The transaction is in the queue, but its final status is pending external action.
@@ -484,6 +489,8 @@ extension PurchaseManager {
                 self.purchase(self, didChaged: .paySuccess, object: nil)
             }
         }
+        
+        subscriptionApple(type: .result, jsonString: simplifyVerifyPayResult(resp: resp))
     }
     
     // 终生会员过期时间:100年