Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 贝宝api:我不断得到;身份验证失败。API凭证不正确。”;_Jquery_Paypal - Fatal编程技术网

Jquery 贝宝api:我不断得到;身份验证失败。API凭证不正确。”;

Jquery 贝宝api:我不断得到;身份验证失败。API凭证不正确。”;,jquery,paypal,Jquery,Paypal,我正试图发布一个请求,请求: https://svcs.sandbox.paypal.com/AdaptivePayments/Pay 使用jquerymobile。 我在《邮递员》里试过,一切都很顺利,收到了钥匙和我需要的一切。但是使用Ajax时,它会返回一个错误: Authentication failed. API credentials are incorrect. 我使用的是相同的标题(appid、userid、密码、签名和数据格式) 以下是我发布请求的方法: function s

我正试图
发布一个请求,请求:

https://svcs.sandbox.paypal.com/AdaptivePayments/Pay
使用jquerymobile。 我在《邮递员》里试过,一切都很顺利,收到了钥匙和我需要的一切。但是使用Ajax时,它会返回一个错误:

Authentication failed. API credentials are incorrect.
我使用的是相同的标题(appid、userid、密码、签名和数据格式) 以下是我发布请求的方法:

function sendPayment(amount){
$.ajax({
    method:'POST',
    dataType: "jsonp",
    url:"https://svcs.sandbox.paypal.com/AdaptivePayments/Pay",
    headers:{
        "X-PAYPAL-APPLICATION-ID" : "APP-80W284485P519543T",
        "X-PAYPAL-SECURITY-USERID" : "mysandboxemail.gmail.com",
        "X-PAYPAL-SECURITY-PASSWORD" : "mysandboxpass",
        "X-PAYPAL-SECURITY-SIGNATURE" : "mysandboxsignature",
        "X-PAYPAL-REQUEST-DATA-FORMAT" : "JSON",
        "X-PAYPAL-RESPONSE-DATA-FORMAT" : "JSON"
    },
    data:JSON.stringify({
        "actionType":"PAY",
        "currencyCode":"USD",
        "receiverList":{"receiver":[{
            "amount":"1.0",
            "email":"myreceiveremail@gmail.com"}]
        },
        "returnUrl":"http://Payment-Success-URL",
        "cancelUrl":"http://Payment-Cancel-URL",
        "requestEnvelope":{
            "errorLanguage":"en_US",
            "detailLevel":"ReturnAll"
        }
    }),
    success:function(data, status, xhr){
        console.log(data);
    },
    error:function(data){
        console.log(data);
    },
    timeout: 3000
});
}
你知道我做错了什么吗?
(我当然使用的是沙盒)

因此我们发现JQuery在标题中添加了其他内容,或者是其他内容,因此导致请求混乱。 因此,不要使用Jquery的$.ajax方法,而是使用老式的方法:

var toSend={
    "actionType": "PAY",
    "currencyCode": "USD",
    "receiverList": {
        "receiver": [{
            "amount": 1.2,
            "email": "killer123@gmail.com"
        }]
    },
    "returnUrl": "http://google.com",
    "cancelUrl": "http://yahoo.com",
    "requestEnvelope": {
        "errorLanguage": "en_US",
        "detailLevel":'ReturnAll'
    }
};


var xhr = new XMLHttpRequest();
xhr.open('POST', "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay", true);    // plug-in desired URL
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
        if (xhr.status == 200) {
            alert('Success: ' + xhr.responseText);  // the response json here
            alert(JSON.stringify(xhr)); //for debugging

        } else {
            alert('Error submitting image: ' + xhr.status);
            alert(JSON.stringify(xhr));

        }
    }
};
//form.append('file', dataUrl);
xhr.setRequestHeader( "X-PAYPAL-APPLICATION-ID", "APP-coolioApp");
xhr.setRequestHeader( "X-PAYPAL-SECURITY-USERID", "senderman.gmail.com");
xhr.setRequestHeader( "X-PAYPAL-SECURITY-PASSWORD", "supersecretpass");
xhr.setRequestHeader( "X-PAYPAL-SECURITY-SIGNATURE", "supersecrensignature-asdasd");
xhr.setRequestHeader( "X-PAYPAL-REQUEST-DATA-FORMAT", "JSON");
xhr.setRequestHeader( "X-PAYPAL-RESPONSE-DATA-FORMAT", "JSON");
xhr.send(JSON.stringify(toSend));