【问题标题】:Paypal PHP Curl returns nothingPaypal PHP Curl 什么都不返回
【发布时间】:2023-04-10 12:53:02
【问题描述】:

在使用实时凭据在 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}"}]}

奇怪的是,这在 localhost 上有效,但在实时服务器上无效,所以我认为这一定是 PHP、curl 或服务器设置的一些差异......但我真的不知道。

【问题讨论】:

    标签: php curl paypal


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 2011-09-13
      • 2014-10-13
      • 1970-01-01
      • 2015-11-18
      • 2018-10-16
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多