2014-03-20 18:07
浏览 39

Paypal经典API:php CURL失败

I am trying to setup a parallel payment using the paypal classic API. However, I am getting massive errors.

I have 2 test accounts setup in the sandbox as well as a classic application.

I am using PHP CURL to initiate the request. I updated the CURL code from the doc to php curl.

My PHP code as as follow:

$headers = array(
    "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T",

$post_array = array(
    'receiverList.receiver(1).email'=>' ',

$url = '';

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

I am getting the following error response:


What is wrong?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongli2000 2014-03-20 18:19

    At the curl's CURLOPT_POSTFIELDS You are doing url encoding on the whole $parameter, which is wrong urlencode($post).

    For http POST the url encoding is done on this way:

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

    So change your POST parameters urlencoding according to above one and then try again.

    Note: if your key1, key2, etc has special character then you have to do urlencode on them as well. For example if it is xyz%32=value1 the you have to use it like urlencode('xyz%32').'=value1'

    解决 无用
    打赏 举报
  • douxuan0698 2014-03-20 18:25

    Try using http_build_query for the post fields. I usually have success with that.

    so something like

    $post = array('actionType' => "PAY", 'value2 => "etc etc etc );

    Then in your curl options

    curl_setopt($curl_session, CURLOPT_POSTFIELDS, http_build_query($post));
    解决 无用
    打赏 举报

相关推荐 更多相似问题