我有一个代码可以让我请求错误。如果我使用沙盒网址,则可以正常工作,但在实时网址上,则无法正常工作。谁能告诉我为什么?
$request = curl_init();
curl_setopt_array($request, array
(
CURLOPT_URL => 'https://www.paypal.com/cgi-bin/webscr',
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_SSLVERSION => 6,
CURLOPT_TIMEOUT => 5,
CURLOPT_POSTFIELDS => http_build_query(array
(
'cmd' => '_notify-synch',
'tx' => $GET['tx'],
'at' => /* my code */,
)),
CURLOPT_HEADER => FALSE
));
$response = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
var_dump($response);
答案 0 :(得分:0)
经过16小时的搜索,我在这里找到了解决方法-https://github.com/apih/paypal-ipn-pdt
代码如下:
$query_data = [
'cmd' => '_notify-synch',
'tx' => $GET['tx'],
'at' => $this->token
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'PayPal');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($query_data));
curl_setopt($ch, CURLOPT_URL, $this->url);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);