了解Apple远程收据

时间:2019-05-14 06:58:22

标签: ios in-app-purchase storekit

这是我的iOS项目中的代码:

if let receiptURL = Bundle.main.appStoreReceiptURL, let data = try? Data(contentsOf: receiptURL) {
    //send receipt data.base64EncodedString() to server
} 

我的服务器代码

def verify():
    json_data = request.get_json()
    receipt = json_data["receipt"]
    env = json_data["env"]
    bundle_id = json_data["bundle_id"]

    if env == "production":
        endpoint = "https://buy.itunes.apple.com/verifyReceipt"
    else:
        endpoint = "https://sandbox.itunes.apple.com/verifyReceipt"


    applePayload = {
    "receipt-data":             receipt,
    "password":                 "mysecret",
    "exclude-old-transactions": True

    }
    r = requests.post(endpoint, json=applePayload)
    r.headers['Content-Type'] = "application/json; charset=utf-8"
    return r.text

这是我从测试帐户发送收据时的Apple回复:

{"status":0, "environment":"Sandbox", 
"receipt":{"receipt_type":"ProductionSandbox", "adam_id":0, "app_item_id":0, "bundle_id":"es.mediaregie.wholovesme", "application_version":"2", "download_id":0, "version_external_identifier":0, "receipt_creation_date":"2019-05-11 18:43:58 Etc/GMT", "receipt_creation_date_ms":"1557600238000", "receipt_creation_date_pst":"2019-05-11 11:43:58 America/Los_Angeles", "request_date":"2019-05-14 05:46:18 Etc/GMT", "request_date_ms":"1557812778939", "request_date_pst":"2019-05-13 22:46:18 America/Los_Angeles", "original_purchase_date":"2013-08-01 07:00:00 Etc/GMT", "original_purchase_date_ms":"1375340400000", "original_purchase_date_pst":"2013-08-01 00:00:00 America/Los_Angeles", "original_application_version":"1.0", 
"in_app":[
{"quantity":"1", "product_id":"weekly_subscription", "transaction_id":"1000000526894772", "original_transaction_id":"1000000526894772", "purchase_date":"2019-05-11 16:17:20 Etc/GMT", "purchase_date_ms":"1557591440000", "purchase_date_pst":"2019-05-11 09:17:20 America/Los_Angeles", "original_purchase_date":"2019-05-11 16:17:22 Etc/GMT", "original_purchase_date_ms":"1557591442000", "original_purchase_date_pst":"2019-05-11 09:17:22 America/Los_Angeles", "expires_date":"2019-05-11 16:20:20 Etc/GMT", "expires_date_ms":"1557591620000", "expires_date_pst":"2019-05-11 09:20:20 America/Los_Angeles", "web_order_line_item_id":"1000000044334416", "is_trial_period":"false", "is_in_intro_offer_period":"false"}, 
{"quantity":"1", "product_id":"weekly_subscription", "transaction_id":"1000000526894809", "original_transaction_id":"1000000526894772", "purchase_date":"2019-05-11 16:20:20 Etc/GMT", "purchase_date_ms":"1557591620000", "purchase_date_pst":"2019-05-11 09:20:20 America/Los_Angeles", "original_purchase_date":"2019-05-11 16:17:22 Etc/GMT", "original_purchase_date_ms":"1557591442000", "original_purchase_date_pst":"2019-05-11 09:17:22 America/Los_Angeles", "expires_date":"2019-05-11 16:23:20 Etc/GMT", "expires_date_ms":"1557591800000", "expires_date_pst":"2019-05-11 09:23:20 America/Los_Angeles", "web_order_line_item_id":"1000000044334417", "is_trial_period":"false", "is_in_intro_offer_period":"false"}, 
{"quantity":"1", "product_id":"weekly_subscription", "transaction_id":"1000000526895042", "original_transaction_id":"1000000526894772", "purchase_date":"2019-05-11 16:23:20 Etc/GMT", "purchase_date_ms":"1557591800000", "purchase_date_pst":"2019-05-11 09:23:20 America/Los_Angeles", "original_purchase_date":"2019-05-11 16:17:22 Etc/GMT", "original_purchase_date_ms":"1557591442000", "original_purchase_date_pst":"2019-05-11 09:17:22 America/Los_Angeles", "expires_date":"2019-05-11 16:26:20 Etc/GMT", "expires_date_ms":"1557591980000", "expires_date_pst":"2019-05-11 09:26:20 America/Los_Angeles", "web_order_line_item_id":"1000000044334428", "is_trial_period":"false", "is_in_intro_offer_period":"false"}, 
{"quantity":"1", "product_id":"weekly_subscription", "transaction_id":"1000000526895281", "original_transaction_id":"1000000526894772", "purchase_date":"2019-05-11 16:26:20 Etc/GMT", "purchase_date_ms":"1557591980000", "purchase_date_pst":"2019-05-11 09:26:20 America/Los_Angeles", "original_purchase_date":"2019-05-11 16:17:22 Etc/GMT", "original_purchase_date_ms":"1557591442000", "original_purchase_date_pst":"2019-05-11 09:17:22 America/Los_Angeles", "expires_date":"2019-05-11 16:29:20 Etc/GMT", "expires_date_ms":"1557592160000", "expires_date_pst":"2019-05-11 09:29:20 America/Los_Angeles", "web_order_line_item_id":"1000000044334441", "is_trial_period":"false", "is_in_intro_offer_period":"false"}, 
{"quantity":"1", "product_id":"weekly_subscription", "transaction_id":"1000000526895686", "original_transaction_id":"1000000526894772", "purchase_date":"2019-05-11 16:29:20 Etc/GMT", "purchase_date_ms":"1557592160000", "purchase_date_pst":"2019-05-11 09:29:20 America/Los_Angeles", "original_purchase_date":"2019-05-11 16:17:22 Etc/GMT", "original_purchase_date_ms":"1557591442000", "original_purchase_date_pst":"2019-05-11 09:17:22 America/Los_Angeles", "expires_date":"2019-05-11 16:32:20 Etc/GMT", "expires_date_ms":"1557592340000", "expires_date_pst":"2019-05-11 09:32:20 America/Los_Angeles", "web_order_line_item_id":"1000000044334455", "is_trial_period":"false", "is_in_intro_offer_period":"false"}, 
{"quantity":"1", "product_id":"weekly_subscription", "transaction_id":"1000000526896082", "original_transaction_id":"1000000526894772", "purchase_date":"2019-05-11 16:32:20 Etc/GMT", "purchase_date_ms":"1557592340000", "purchase_date_pst":"2019-05-11 09:32:20 America/Los_Angeles", "original_purchase_date":"2019-05-11 16:17:22 Etc/GMT", "original_purchase_date_ms":"1557591442000", "original_purchase_date_pst":"2019-05-11 09:17:22 America/Los_Angeles", "expires_date":"2019-05-11 16:35:20 Etc/GMT", "expires_date_ms":"1557592520000", "expires_date_pst":"2019-05-11 09:35:20 America/Los_Angeles", "web_order_line_item_id":"1000000044334476", "is_trial_period":"false", "is_in_intro_offer_period":"false"}]}, 
"latest_receipt_info":[
{"quantity":"1", "product_id":"weekly_subscription", "transaction_id":"1000000526896082", "original_transaction_id":"1000000526894772", "purchase_date":"2019-05-11 16:32:20 Etc/GMT", "purchase_date_ms":"1557592340000", "purchase_date_pst":"2019-05-11 09:32:20 America/Los_Angeles", "original_purchase_date":"2019-05-11 16:17:22 Etc/GMT", "original_purchase_date_ms":"1557591442000", "original_purchase_date_pst":"2019-05-11 09:17:22 America/Los_Angeles", "expires_date":"2019-05-11 16:35:20 Etc/GMT", "expires_date_ms":"1557592520000", "expires_date_pst":"2019-05-11 09:35:20 America/Los_Angeles", "web_order_line_item_id":"1000000044334476", "is_trial_period":"false", "is_in_intro_offer_period":"false"}], 
"latest_receipt":"MIIT2gYJKoZIhvcNAQcCoIITyzCCE8cCAQExCzAJBgUrDgMCGgUAMIIDewYJKoZIhvcNAQcBoIIDbASCA2gxggNkMAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgEDAgEBBAMMATIwCwIBCwIBAQQDAgEAMAsCAQ8CAQEEAwIBADALAgEQAgEBBAMCAQAwCwIBGQIBAQQDAgEDMAwCAQoCAQEEBBYCNCswDAIBDgIBAQQEAgIAojANAgENAgEBBAUCAwHViDANAgETAgEBBAUMAzEuMDAOAgEJAgEBBAYCBFAyNTIwGAIBBAIBAgQQ6OK/a51S6iIUQnFSi0P5zTAbAgEAAgEBBBMMEVByb2R1Y3Rpb25TYW5kYm94MBwCAQUCAQEEFFP2sppxWfTXtkBJcsvGvzKITqx/MB4CAQwCAQEEFhYUMjAxOS0wNS0xNFQwNTo0NjoxOFowHgIBEgIBAQQWFhQyMDEzLTA4LTAxVDA3OjAwOjAwWjAiAgECAgEBBBoMGGVzLm1lZGlhcmVnaWUud2hvbG92ZXNtZTAzAgEHAgEBBCsIq51ClKMuBQK1z+iZps39Vi/4u/YplwFSH6+jMq/BAQUFdf2QJhwwPbItMEACAQYCAQEEOGdS2t9XLCpzS7CyzXasBOmlm/vVg7IQpnOVHM1ormnQCDkwB0r5+Shr26dh8lV8LuZhgP/hYLuvMIIBgAIBEQIBAQSCAXYxggFyMAsCAgatAgEBBAIMADALAgIGsAIBAQQCFgAwCwICBrICAQEEAgwAMAsCAgazAgEBBAIMADALAgIGtAIBAQQCDAAwCwICBrUCAQEEAgwAMAsCAga2AgEBBAIMADAMAgIGpQIBAQQDAgEBMAwCAgarAgEBB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MuMSwwKgYDVQQLDCNBcHBsZSBXb3JsZHdpZGUgRGV2ZWxvcGVyIFJlbGF0aW9uczFEMEIGA1UEAww7QXBwbGUgV29ybGR3aWRlIERldmVsb3BlciBSZWxhdGlvbnMgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkCCA7rV4fnngmNMAkGBSsOAwIaBQAwDQYJKoZIhvcNAQEBBQAEggEASyqCJc3ZjAyHmcDPVgrk6zjDxqdf6UaZWkfpU7tlQNKU2GJIZFePKEX+2HnNGQLYnYxuq/vuQ7H6EXnFzGoC8WZ8BK1Xb1+GHeYXxEjMk7XjoAwinTqAfw1aSgOgBH7yS+1dgzCwwR1+lH8oxkgbqMODmytky1NYmKdQ4Xth+WB6MdwCWIBS0Ck55PIzIOrarWnLP6ceA//CxpgVb0F+Wvr8LsVqvViLcXweJLsCnOtZ78cYAkhdQOpblUuUlE5hunhhgeVNE4Yp36/4lZxc+28K50zhYx7vFbD2B7KS9tj+XU3vBQ930G/0/iL7XoX9+AyTnPgRWQTEasHsOo6neg==", 
"pending_renewal_info":[
{"expiration_intent":"1", "auto_renew_product_id":"weekly_subscription", "original_transaction_id":"1000000526894772", "is_in_billing_retry_period":"0", "product_id":"weekly_subscription", "auto_renew_status":"0"}]}

根据此https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW3,如果我理解正确,我应该仅使用latest_receipt_info字段来检查用户订阅当前是否 活跃。

如果还有更多产品(消费品,订阅产品等)怎么办?

可以忽略latest_receipt字段吗?

我应该在iOS设备上对服务器响应进行任何验证吗?

0 个答案:

没有答案