gpt4 book ai didi

ios - 如何快速获取当前订阅的用户收据

转载 作者:行者123 更新时间:2023-11-28 14:08:41 26 4
gpt4 key购买 nike

目前,我正在尝试获取当前登录用户的收据,但每当我尝试从另一个帐户登录时,我仍然会收到相同的收据列表,并且在刷新时总是增加 +1 收据,我只是想在用户订阅后检查我想在服务器上发送收据

获取收据的代码

func receiptValidation() {
let SUBSCRIPTION_SECRET = "xxxx"
let receiptPath = Bundle.main.appStoreReceiptURL?.path
if FileManager.default.fileExists(atPath: receiptPath!)
{
var receiptData:NSData?
do{
receiptData = try NSData(contentsOf: Bundle.main.appStoreReceiptURL!, options: NSData.ReadingOptions.alwaysMapped)
}
catch{
print("ERROR: " + error.localizedDescription)
}
//let receiptString = receiptData?.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
let base64encodedReceipt = receiptData?.base64EncodedString(options: NSData.Base64EncodingOptions.endLineWithCarriageReturn)

print(base64encodedReceipt!)


let requestDictionary = ["receipt-data":base64encodedReceipt!,"password":SUBSCRIPTION_SECRET]

guard JSONSerialization.isValidJSONObject(requestDictionary) else { print("requestDictionary is not valid JSON"); return }
do {
let requestData = try JSONSerialization.data(withJSONObject: requestDictionary)
let validationURLString = "https://sandbox.itunes.apple.com/verifyReceipt" // this works but as noted above it's best to use your own trusted server
guard let validationURL = URL(string: validationURLString) else { print("the validation url could not be created, unlikely error"); return }
let session = URLSession(configuration: URLSessionConfiguration.default)
var request = URLRequest(url: validationURL)
request.httpMethod = "POST"
request.cachePolicy = URLRequest.CachePolicy.reloadIgnoringCacheData
let task = session.uploadTask(with: request, from: requestData) { (data, response, error) in
if let data = data , error == nil {
do {
let appReceiptJSON = try JSONSerialization.jsonObject(with: data)
print("success. here is the json representation of the app receipt: \(appReceiptJSON)")
// if you are using your server this will be a json representation of whatever your server provided
} catch let error as NSError {
print("json serialization failed with error: \(error)")
}
} else {
print("the upload task returned an error: \(error)")
}
}
task.resume()
} catch let error as NSError {
print("json serialization failed with error: \(error)")
}



}
}

和收据信息

"latest_receipt_info" =     (
{
"is_trial_period" = false;
"original_purchase_date" = "2018-10-09 07:14:17 Etc/GMT";
"original_purchase_date_ms" = 1539069257000;
"original_purchase_date_pst" = "2018-10-09 00:14:17 America/Los_Angeles";
"original_transaction_id" = 1000000454564149;
"product_id" = "com.MeetAndEat";
"purchase_date" = "2018-10-09 07:14:17 Etc/GMT";
"purchase_date_ms" = 1539069257000;
"purchase_date_pst" = "2018-10-09 00:14:17 America/Los_Angeles";
quantity = 1;
"transaction_id" = 1000000454564149;
},
{
"is_trial_period" = false;
"original_purchase_date" = "2018-10-09 07:14:54 Etc/GMT";
"original_purchase_date_ms" = 1539069294000;
"original_purchase_date_pst" = "2018-10-09 00:14:54 America/Los_Angeles";
"original_transaction_id" = 1000000454564374;
"product_id" = "com.MeetAndEat";
"purchase_date" = "2018-10-09 07:14:54 Etc/GMT";
"purchase_date_ms" = 1539069294000;
"purchase_date_pst" = "2018-10-09 00:14:54 America/Los_Angeles";
quantity = 1;
"transaction_id" = 1000000454564374;
},
{
"is_trial_period" = false;
"original_purchase_date" = "2018-10-09 08:30:39 Etc/GMT";
"original_purchase_date_ms" = 1539073839000;
"original_purchase_date_pst" = "2018-10-09 01:30:39 America/Los_Angeles";
"original_transaction_id" = 1000000454630243;
"product_id" = "com.MeetAndEat";
"purchase_date" = "2018-10-09 08:30:39 Etc/GMT";
"purchase_date_ms" = 1539073839000;
"purchase_date_pst" = "2018-10-09 01:30:39 America/Los_Angeles";
quantity = 1;
"transaction_id" = 1000000454630243;
},
{
"is_trial_period" = false;
"original_purchase_date" = "2018-10-09 08:31:45 Etc/GMT";
"original_purchase_date_ms" = 1539073905000;
"original_purchase_date_pst" = "2018-10-09 01:31:45 America/Los_Angeles";
"original_transaction_id" = 1000000454630786;
"product_id" = "com.MeetAndEat";
"purchase_date" = "2018-10-09 08:31:45 Etc/GMT";
"purchase_date_ms" = 1539073905000;
"purchase_date_pst" = "2018-10-09 01:31:45 America/Los_Angeles";
quantity = 1;
"transaction_id" = 1000000454630786;
},
{
"is_trial_period" = false;
"original_purchase_date" = "2018-10-09 08:42:01 Etc/GMT";
"original_purchase_date_ms" = 1539074521000;
"original_purchase_date_pst" = "2018-10-09 01:42:01 America/Los_Angeles";
"original_transaction_id" = 1000000454640882;
"product_id" = "com.MeetAndEat";
"purchase_date" = "2018-10-09 08:42:01 Etc/GMT";
"purchase_date_ms" = 1539074521000;
"purchase_date_pst" = "2018-10-09 01:42:01 America/Los_Angeles";
quantity = 1;
"transaction_id" = 1000000454640882;
},

最佳答案

这是完美的代码。没有问题。现在您的测试过程中出现了问题。

A new receipt will appear when StoreKit calls updatedTransactions.  Otherwise there may or may not be a refreshed receipt attached to the binary.

如果您注销会发生什么:

When you logged out from iTunes then you will see your local receipt will be 
removed

我认为您还应该从“设置”->“iTunes 和应用商店”->“点击帐户”注销。

关于ios - 如何快速获取当前订阅的用户收据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52773656/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com