2

在使用实时凭据在 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 请求。在本地主机上,我立即得到正确的回报。在实时服务器上,我首先得到一个“>”符号,如果我再次粘贴命令并输入,它会给我一些输出。

{"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}"}]}

奇怪的是,这适用于本地主机,但不适用于实时服务器,所以我认为 PHP、curl 或服务器设置一定有一些不同......但我真的不知道。

4

1 回答 1

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);
于 2013-07-05T21:40:03.510 回答