在使用Swift的App Receipt验证中返回代码21002

在使用Swift的App Receipt验证中返回代码21002,第1张

概述我已将数据发送到服务器,希望验证收据并收到错误的响应(21002).我发送给iTunes的json在 JSONlint.org中验证,如下所示: {"receipt-data":"MIIVHAYJKoZIhvcNAQcCoIIVDTCCFQkCAQExCzAJBgUrDgMCGgUAMIIEzQYJKoZIhvcNAQcBoIIEvgSCBLoxggS2MAoCAQgCAQEEAhYAMAoCAR 我已将数据发送到服务器,希望验证收据并收到错误的响应(21002).我发送给iTunes的Json在 JSONlint.org中验证,如下所示:

{"receipt-data":"MIIVHAYJKoZIhvcNAQcCoIIVDTCCFQkCAQExCzAJBgUrDgMCGgUAMIIEzQYJKoZIhvcNAQcBoIIEvgSCBLoxggS2MAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgEDAgEBBAMMATEwCwIBCwIBAQQDAgEAMAsCAQ4CAQEEAwIBYTALAgEPAgEBBAMCAQAwCwIBEAIBAQQDAgEAMAsCARkCAQEEAwIBAzAMAgEKAgEBBAQWAjQrMA0CAQ0CAQEEBQIDATiAMA0CARMCAQEEBQwDMS4wMA4CAQkCAQEEBgIEUDIzMTAYAgEEAgECBBAt7VRGy6HkL8GxL7ZCostRMBsCAQACAQEEEwwRUHJvZHVjdGlvblNhbmRib3gwHAIBBQIBAQQulxX47jCym5JTHsewbqxnmPRNn3MwHQIBAgIBAQQVdbnjb20ubW0yMTQuSW5BcHBEZW1vMB4CAQwCAQEEFhYUMjAxNC0wNy0yOVQwNjowodowM1owHgIBEgIBAQQWFhQyMDEzLTA4LTAxVDA3OjAwOjAwWjBKAgEHAgEBBEJ_kvTvyRgKF9B080GZL0zmZSR93EEtsEyPBqO6PVrSePmQeoK\/vS1k9\/uZdd5XuaQyISrVWC2DpjU6eC_wLlLvqnQwUAIBBgIBAQRI85FUTb1tsun7ZcnNO9jP0Ya3Jpr\/njNS_P11OJ9GD7gbIArIWohrpkX0VN\/kH6KDHUeVPRkug\/\/pQ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mv0f6CQvN5tXx1fWOzEW5BvQ5x\/ZUwElLmnPa05OUPBMZJveU56uo_q8g"}

知道我可能做错了吗?我的斯威夫特如下:

var receiptUrl = NSBundle.mainBundle().appStoreReceiptURL;var receipt: NSData = NSData.dataWithContentsOfURL(receiptUrl,options: nil,error: nil)var receiptdata:Nsstring = receipt.base64EncodedStringWithOptions(NSDataBase64EnCodingOptions.fromraw(0)!)    var requestContents:NSDictionary = ["receipt-data": receiptdata];    var JsonString:NSData = NSJsONSerialization.dataWithJsONObject(requestContents,options:nil,error:nil);    var dta:Nsstring = Nsstring(data: JsonString,enCoding: NSUTF8StringEnCoding)    request.httpBody = dta.dataUsingEnCoding(NSUTF8StringEnCoding,allowLossyConversion: true)     request.httpMethod = "POST"    request.setValue("application/x-www-form-urlencoded",forhttpheaderFIEld: "Content-Type")    // send the request    NSURLConnection.sendSynchronousRequest(request,returningResponse: &response,error: &error)
解决方法 此代码可以帮助您:

func valIDateRecipt(){    var response: NSURLResponse?    var error: NSError?    var recuptUrl = NSBundle.mainBundle().appStoreReceiptURL    var receipt: NSData = NSData(contentsOfURL:recuptUrl!,error: nil)!    //https://buy.itunes.apple.com/verifyReceipt    var request = NSMutableURLRequest(URL: NSURL(string: "https://sandBox.itunes.apple.com/verifyReceipt")!,cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy,timeoutInterval: 10)    var session = NSURLSession.sharedSession()    request.httpMethod = "POST"    var receiptdata:Nsstring = receipt.base64EncodedStringWithOptions(NSDataBase64EnCodingOptions.EnCodingEndlineWithlineFeed)    NSLog("%@",receiptdata)    var payload:Nsstring = "{\"receipt-data\" : \"\(receiptdata)\"}"    var payloadData = payload.dataUsingEnCoding(NSUTF8StringEnCoding)    var err: NSError?    request.httpBody = payloadData    var task = session.dataTaskWithRequest(request,completionHandler:        {data,response,error -> VoID in            var err: NSError?            var Json = NSJsONSerialization.JsONObjectWithData(data,options: .MutableLeaves,error: &err) as? NSDictionary            if(err != nil) {                println(err!.localizedDescription)                let JsonStr = Nsstring(data: data,enCoding: NSUTF8StringEnCoding)                println("Error Could not parse JsON: '\(JsonStr)'")            }            else {                if let parseJsON = Json {                    println("Recipt \(parseJsON)")                }                else {                    let JsonStr = Nsstring(data: data,enCoding: NSUTF8StringEnCoding)                    println("Recipt Error: \(JsonStr)")                }            }    })    task.resume()}
总结

以上是内存溢出为你收集整理的在使用Swift的App Receipt验证中返回代码21002全部内容,希望文章能够帮你解决在使用Swift的App Receipt验证中返回代码21002所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1003819.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存