我使用下面的功能来验证收据。如您所见,我使用了沙箱URL,因为在将收据提交到商店之前我先对其进行了测试。我要学习的是:提交之前,应该在storeUrl部分中写什么?如何访问或找到该URL?根据我的研究,我需要输入服务器地址或其他内容,但是我要提交的产品是非消耗性的,因此我没有任何服务器。
func verifyReciept (transaction : SKPaymentTransaction?) {
let recieptURL = Bundle.main.appStoreReceiptURL!
if let reciept = NSData(contentsOf: recieptURL){
let requestContents = ["receipt-data" : reciept.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue:0))]
do {
let requestData = try JSONSerialization.data(withJSONObject: requestContents, options: JSONSerialization.WritingOptions(rawValue : 0))
let storeURL = NSURL(string: "https:/sandbox.itunes.apple.com/verifyReceipt")
let request = NSMutableURLRequest(url: storeURL! as URL)
request.httpMethod = "Post"
request.httpBody = requestData
let session = URLSession.shared
let task = session.dataTask(with: request as URLRequest, completionHandler: { (responseData: Data?, response : URLResponse?, error : Error?) -> Void in
do {
let json = try JSONSerialization.jsonObject(with: responseData!, options: .mutableLeaves) as! NSDictionary
print(json)
if(json.object(forKey: "status") as! NSNumber) == 0 {
let receipt_dict = json["receipt"] as! NSDictionary
if let purchases = receipt_dict["in_app"] as? NSArray {
self.validatePurchaseArray(purchases: purchases)
}
if transaction != nil {
SKPaymentQueue.default().finishTransaction(transaction!)
}
}
else {
print(json.object(forKey: "status") as! NSNumber)
}
}
catch{
print(error)
}
})
task.resume()
} catch {
print(error)
}
}
else {
print("No Reciept")
}
}
最佳答案
您应将其替换为产品URL以验证收据:
"https://buy.itunes.apple.com/verifyReceipt"
您正在谈论涉及服务器的事情是可以采取的另一项措施。对于服务器端验证,您需要将收据发送到服务器,然后从服务器运行此功能。
关于ios - 在App Store验证应用内购买收据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44522537/