在使用实时凭据成功在本地主机上测试我的付款请求之后,我将应用程序联机。
但是,在实时服务器上,curl请求没有任何回报,甚至没有错误消息。这是完全相同的请求,可以完美地在localhost上运行。
$url = 'curl -s --insecure -H "X-PAYPAL-SECURITY-USERID: '.$userId.'" -H "X-PAYPAL-SECURITY-PASSWORD: '.$password.'" -H "X-PAYPAL-SECURITY-SIGNATURE: '.$signature.'" -H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" -H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON" -H "X-PAYPAL-APPLICATION-ID: '.$applicationId.'" https://svcs.paypal.com/AdaptivePayments/Pay -d "{\"actionType\":\"PAY\", \"currencyCode\":\"'.$currency.'\", \"receiverList\":{\"receiver\":[{\"amount\":\"'.$amount.'\",\"email\":\"'.$receiverEmail.'\"}]}, \"returnUrl\":\"'.$successUrl.'\", \"cancelUrl\":\"'.$failUrl.'\", \"requestEnvelope\":{\"errorLanguage\":\"en_US\", \"detailLevel\":\"ReturnAll\"}}';
$result = json_decode(exec($url));
现在就是PHP。我试图在命令行中运行curl请求。在本地主机上,我立即获得正确的回报。在实时服务器上,我首先得到一个“>”符号,然后再次粘贴命令并输入,它会给我一些输出。
{"responseEnvelope":{"timestamp":"2013-07-05T13:16:26.305-07:00","ack":"Failure","correlationId":"2b8ab6998078e","build":"6520082"},"error":[{"errorId":"580001","domain":"PLATFORM","subdomain":"Application","severity":"Error","category":"Application","message":"Invalid request: {0}"}]}
奇怪的是,它可以在localhost上运行,但不能在实时服务器上运行,因此我认为这在PHP,curl或服务器设置上一定有所不同...但是我真的没有任何线索。
最佳答案
echo $ url的输出是什么?
为什么通过exec运行curl?为什么不使用mod_curl?
例如...
$API_Endpoint = "";
if ($sandbox) {
$API_Endpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments";
}
else{
$API_Endpoint = "https://svcs.paypal.com/AdaptivePayments";
}
$API_Endpoint .= "/" . $methodName;
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the HTTP Headers
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-PAYPAL-REQUEST-DATA-FORMAT: NV',
'X-PAYPAL-RESPONSE-DATA-FORMAT: NV',
'X-PAYPAL-SECURITY-USERID: '. $API_UserName,
'X-PAYPAL-SECURITY-PASSWORD: '. $API_Password,
'X-PAYPAL-SECURITY-SIGNATURE: '. $API_Signature,
'X-PAYPAL-APPLICATION-ID: '. $API_AppID
));
// RequestEnvelope fields
$detail_level = urlencode("ReturnAll"); // See DetailLevelCode in the WSDL for valid enumerations
$error_language = urlencode("en_US"); // This should be the standard RFC 3066 language identification tag, e.g., en_US
// NVPRequest for submitting to server
$nvp_req = "requestEnvelope.errorLanguage=$error_language&requestEnvelope.detailLevel=$detail_level";
$nvp_req .= "&$nvp_str";
//setting the nvp_req as POST FIELD to curl
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp_req);
//getting response from server
$response = curl_exec($ch);