繁体   English   中英

XMLHttpRequest无法加载https://sandbox.itunes.apple.com/verifyReceipt。 Access-Control-Allow-Origin不允许起源

[英]XMLHttpRequest cannot load https://sandbox.itunes.apple.com/verifyReceipt. Origin is not allowed by Access-Control-Allow-Origin

苹果似乎不喜欢我的Ajax请求。 我正在尝试在应用内购买后在PhoneGap应用中验证收据。

// prepare JSON object for Apple
/* Retrieve the receipt data from the transaction’s transactionReceipt property (on iOS) or from the receipt file inside the application bundle (on OS X) and encode it using base64 encoding.
Create a JSON object with a single key named receipt-data and the string you created in step 1. Your JSON code should look like this:
{
    "receipt-data" : "(receipt bytes here)"
} */
var data = JSON.stringify({
    'receipt-data' : btoa(transactionReceipt)
});
if(DEBUG) console.log('Data: ' + data);

var url = 'https://' + (DEBUG ? 'sandbox' : 'buy') + '.itunes.apple.com/verifyReceipt';
if(DEBUG) console.log('URL: ' + url);

// send the POST request
/* Post the JSON object to the App Store using an HTTP POST request. The URL for the store is https://buy.itunes.apple.com/verifyReceipt. */
$.ajax(url, {
    type: 'POST',
    data: data,
    dataType: 'json',
    success: function(data) {
        console.log('Request returned successfully.');

        // parse the response
        /*
        The response received from the App Store is a JSON object with two keys, status and receipt. It should look something like this:
        {
            "status" : 0,
            "receipt" : { (receipt here) }
        }
        If the value of the status key is 0, this is a valid receipt. If the value is anything other than 0, this receipt is invalid.
        */
        if(data.status === 0)
        console.log("Receipt is valid.");
    },
    error : function(jqXHR, textStatus, errorThrown) {
        console.error('Request failed with response code ' + errorThrown);
    }

});

我正在使用jQuery并具有:

$(document).bind("mobileinit", function () {
    // xss
    $.support.cors = true;
    $.mobile.allowCrossDomainPages = true;
}

有没有人尝试过通过ajax验证收据并遇到此问题?

谢谢。

Apache Cordova中的域白名单是一种安全模型,用于控制对外部域(例如http://google.com)的访问 默认的安全策略是阻止所有网络访问

http://docs.phonegap.com/guide_whitelist_index.md.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM