1

我正在尝试让订阅正常工作。我的收据验证在沙盒模式下工作,但是当我使用实时 url 进行收据验证时它还不起作用。这是我的代码:

func receiptValidation() {

    // appStoreReceiptURL still says sandboxReceipt

    if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL,
        FileManager.default.fileExists(atPath: appStoreReceiptURL.path) {

        do {
            let receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped)

            let receiptString = receiptData.base64EncodedString(options: [])
            let dict = ["receipt-data" : receiptString, "password" : iTunesMasterAppSecret] as [String : Any]

            do {
                let jsonData = try JSONSerialization.data(withJSONObject: dict, options: .prettyPrinted)

var receiptUrl:String
                    if (liveMode) {
                        receiptUrl = "https://buy.itunes.apple.com/verifyReceipt"
                    }
                    else {
                        receiptUrl = "https://sandbox.itunes.apple.com/verifyReceipt"
                    }

                // appStoreReceiptURL still says sandboxReceipt

                if let sandboxURL = Foundation.URL(string:receiptUrl) {
                    var request = URLRequest(url: sandboxURL)
                    request.httpMethod = "POST"
                    request.httpBody = jsonData
                    let session = URLSession(configuration: URLSessionConfiguration.default)
                    let task = session.dataTask(with: request) {
 if let receivedData = data,
                                let httpResponse = response as? HTTPURLResponse,
                                error == nil,
                                httpResponse.statusCode == 200 {
                                do {
                                    if let jsonResponse = try JSONSerialization.jsonObject(with: receivedData, options: JSONSerialization.ReadingOptions.mutableContainers) as? Dictionary<String, AnyObject>

当我得到 jsonResponse 时,我得到 "[\"status\": 21007]",它在 Apple 文档中被描述为:

21007 -- This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.

有人可以帮我让订阅进入实时模式吗?

4

1 回答 1

1

测试您的应用内购买(包括和不包括 TestFlight)将始终在沙盒模式下进行。购买 IAP 时,只有经过 Apple 签名以在 App Store 中分发的应用程序才会投入生产。如果您的 IAP 流程在沙盒中运行,那么您在生产中也应该没问题。

顺便说一句:我不确定您如何确定您处于“实时”模式,但 Apple 建议始终先将收据发送到生产 URL,如果您收到错误代码21007,则将其作为沙盒 URL 发送到沙盒 URL倒退。而且你真的需要那种后备机制。作为审核流程的一部分,Apple 将测试您的 IAP 流程。他们的测试将在沙盒模式下进行,因此如果您将liveModebool 硬编码到true沙盒验证 URL 并且从未点击过沙盒验证 URL,则 IAP 购买将失败并且您的构建将不会被批准。

于 2017-08-12T18:23:05.210 回答