payapl-nvp-api(退款)通过表单使用时可以工作,但不能使用curl


payapl nvp api (refund) working when using via a form but not working with curl

我正在尝试使用Paypal的退款API。我目前正在使用沙箱帐户。付款情况良好。当我使用表单字段将数据发布到像下面这样的贝宝时,退款工作正常

 <form action="https://api-3t.sandbox.paypal.com/nvp" METHOD="GET">
        <input type="text" name="USER" value="**********"/>
        <input type="text" name="PWD" value="**********"/>
        <input type="text" name="SIGNATURE" value="**********"/>
        <input type="text" name="METHOD" value="RefundTransaction"/>
        <input type="text" name="VERSION" value="94"/>
        <input type="text" name="TRANSACTIONID" value="<?php echo $data['transaction_id']; ?>"/>
        <input type="text" name="REFUNDTYPE" value="Partial"/>
        <input type="text" name="AMT" value="<?php echo $amount; ?>"/>
        <input type="text" name="CURRENCYCODE" value="GBP"/>
        <input type="text" name="NOTE"  value="refund"/>
        <input type="submit" value="pay"/>
    </form>

响应会自动打印在屏幕上,并显示退款成功。但我需要比较响应的ACK,以便在退款后进行其他操作。所以我试着用下面这样的卷发。

$req = array(
    'USER' => urlencode('**************'),
    'PWD' => urlencode('***************'),
    'SIGNATURE' => ************'),
    'METHOD' => 'RefundTransaction',
    'VERSION' => urlencode(119),
    'TRANSACTIONID' => $data[transaction_id],
    'REFUNDTYPE' => 'Partial',
    'AMT' => urlencode($amount),
    'CURRENCYCODE' => 'GBP',
    'NOTE' => urlencode('test'),
    );
$ch = curl_init('https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
if(!($res = curl_exec($ch)) ) {
    error_log("Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);
echo "response is : ".urldecode($res);

curl调用成功,但响应始终是来自paypal的内部错误(10001)。我做错了什么。请帮助

注意:我刚刚用星号替换了凭据。

我认为您不需要对AMT值进行url编码。它应该以正确格式的十进制形式发送。此外,版本号也不必是url编码的,据我所知,目前的最高版本是95,而不是119