gpt4 book ai didi

php - Paypal 经典 API : Failure with php CURL

转载 作者:太空宇宙 更新时间:2023-11-03 16:31:45 24 4
gpt4 key购买 nike

我正在尝试使用 Paypal 经典 API 设置并行支付。但是,我遇到了很多错误。

我在沙盒中设置了 2 个测试帐户以及一个经典应用程序。

我正在使用 PHP CURL 发起请求。我将文档中的 CURL 代码更新为 php curl。

我的PHP代码如下:

$headers = array(
"X-PAYPAL-SECURITY-USERID: XXXXXX" ,
"X-PAYPAL-SECURITY-PASSWORD: XXXXXX",
"X-PAYPAL-SECURITY-SIGNATURE: XXXXXX" ,
"X-PAYPAL-REQUEST-DATA-FORMAT: NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT: NV",
"X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T",
);

$post_array = array(
'actionType'=>'PAY',
'clientDetails.applicationId'=>'APP-80W284485P519543T',
'currencyCode'=>'USD',
'feesPayer'=>'SECONDARYRECEIVER',
'receiverList.receiver(0).amount'=>'5.00',
'receiverList.receiver(0).email'=>'primaryreceiver1@test.com',
'receiverList.receiver(0).primary'=>'true',
'receiverList.receiver(1).amount'=>'5.00',
'receiverList.receiver(1).email'=>'secondaryreceiver1@test.com ',
'receiverList.receiver(1).primary'=>'false',
'requestEnvelope.errorLanguage'=>'en_US',
'ipnNotificationUrl'=>'http://www.yourdomain.com/ipn_myreceiver',
'returnUrl'=>'http://www.yourdomain.com/success',
'cancelUrl'=>'http://www.yourdomain.com/cancel',
);


$url = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';


$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL,$url);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_POST, 1);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, http_build_query($post_array));
curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curl_session, CURLOPT_TIMEOUT, 10);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_session, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($curl_session);
echo $response;

我收到以下错误响应:

responseEnvelope.timestamp=2014-03-20T11%3A35%3A58.520-07%3A00&responseEnvelope.ack=Failure&responseEnvelope.correlationId=db88a73f724a0&responseEnvelope.build=10175386&error(0).errorId=580022&error(0).domain=PLATFORM&error(0).subdomain=Application&error(0).severity=Error&error(0).category=Application&error(0).message=Invalid+request+parameter%3A+email+secondaryreceiver1%40test.com++is+invalid&error(0).parameter(0)=email&error(0).parameter(1)=secondaryreceiver1%40test.com+

怎么了?

最佳答案

在 curl 的 CURLOPT_POSTFIELDS 中,您正在对整个 $parameter 进行 url 编码,这是错误的 urlencode($post)

对于http POST,url编码是这样完成的:

$param = "key1=".urlencode($value1);
$param = $param . "&" . "key2=".urlencode($value2);
$param = $param . "&" . ".email=".urlencode('primaryreceiver1@test.com');
// and so on.

所以根据上面的改变你的POST参数urlencoding然后再试一次。

注意:如果您的 key1、key2 等具有特殊字符,那么您也必须对它们进行 urlencode。例如,如果它是 xyz%32=value1,您必须像 urlencode('xyz%32').'=value1'

一样使用它

关于php - Paypal 经典 API : Failure with php CURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22541568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com