Paypal PHP Curl什么都不返回

时间:2013-07-05 20:34:34

标签: php curl paypal

在使用实时凭据在localhost上成功测试我的付款请求后,我将应用程序移到了网上。

然而,在实时服务器上,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请求。在localhost上,我立即得到正确的回报。在实时服务器上,我首先得到一个“>”签名,如果我再次粘贴命令然后输入,它会给我一些输出。

{"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或服务器设置方面有所不同......但我真的没有线索。

1 个答案:

答案 0 :(得分:1)

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);