|
@@ -57,6 +57,12 @@ enum KMInAppPurchaseState: String, CaseIterable {
|
|
|
case checkSubscriptionFailed = "checkSubscriptionFailed" //检测是否订阅失败
|
|
|
}
|
|
|
|
|
|
+enum KMInAppPurchaseType: Int, CaseIterable {
|
|
|
+ case unknow = 0
|
|
|
+ case restore
|
|
|
+ case purchase
|
|
|
+}
|
|
|
+
|
|
|
class KMInAppPurchaseManager: NSObject {
|
|
|
public static let manager = KMInAppPurchaseManager()
|
|
|
|
|
@@ -71,6 +77,8 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
return self.updatePurchaseState()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ var type: KMInAppPurchaseType = .unknow
|
|
|
|
|
|
var orderId: String?
|
|
|
|
|
@@ -99,6 +107,7 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
}
|
|
|
|
|
|
func purchaseProduct(productIdentifier: String, orderId: String = "", completion: @escaping KMPurchaseCompletion) {
|
|
|
+ self.type = .purchase
|
|
|
self.purchaseProductCompletion = completion
|
|
|
self.orderId = orderId
|
|
|
if SKPaymentQueue.canMakePayments() {
|
|
@@ -130,6 +139,7 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
|
|
|
func restorePurchases(_ orderId: String = "", _ completetion: @escaping KMPurchaseRestoreCompletion) {
|
|
|
KMPrint("开始restore")
|
|
|
+ self.type = .restore
|
|
|
restoreCompletion = completetion
|
|
|
self.orderId = orderId
|
|
|
SKPaymentQueue.default().restoreCompletedTransactions()
|
|
@@ -191,6 +201,8 @@ class KMInAppPurchaseManager: NSObject {
|
|
|
//刷新用户信息
|
|
|
KMLightMemberManager.manager.reloadUserInfo()
|
|
|
}
|
|
|
+
|
|
|
+ self.type = .unknow
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -322,17 +334,21 @@ extension KMInAppPurchaseManager: SKPaymentTransactionObserver {
|
|
|
sendReceiptToAppleServer(isTestServer, isDebug: isDebug, receiptData: receiptData, transaction: transaction)
|
|
|
|
|
|
//给服务器发送票据验证
|
|
|
- appStoreEquityVerification(receiptData:receiptData)
|
|
|
+ appStoreEquityVerification(receiptData:receiptData, type: self.type)
|
|
|
} else {
|
|
|
self.handleAction(state: .noReceipt)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func appStoreEquityVerification(receiptData: Data) {
|
|
|
+ func appStoreEquityVerification(receiptData: Data, type: KMInAppPurchaseType) {
|
|
|
// 构建请求
|
|
|
+ var isPurchase = false
|
|
|
+ if type == .purchase {
|
|
|
+ isPurchase = true
|
|
|
+ }
|
|
|
let receiptString = receiptData.base64EncodedString(options: [])
|
|
|
KMPrint(receiptString)
|
|
|
- KMRequestServerManager.manager.appStoreEquityVerification(applePayProductId: PRODUCT_1, receipt: receiptString, complete: { [unowned self] success, result in
|
|
|
+ KMRequestServerManager.manager.appStoreEquityVerification(applePayProductId: PRODUCT_1, receipt: receiptString, isPurchase: isPurchase, complete: { [unowned self] success, result in
|
|
|
if success, let data = result?.result {
|
|
|
|
|
|
} else if result?.error != nil {
|