0
我看了一个教程,做了那个人做的。我有我的index.php
以下代码。本教程中的人收到了一个结果(来自$ result变量),但我什么也没得到。Paypal_IPN没有得到结果?
的var_dump在$结果:
string(0) ""
问题出在哪里?
<?php
class Paypal_IPN
{
public function __construct($mode)
{
if ($mode == 'live')
$this->_url = 'https://www.paypal.com/cgi-bin/webscr';
else
$this->_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
}
public function run()
{
$postFields = "cdm=_notify-validate";
foreach ((array)$_POST as $key => $value)
{
$postFields .= "&$key=".urlencode($value);
}
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $this->_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postFields
));
$result = curl_exec($ch);
curl_close($ch);
$fh = fopen('result.txt', 'w');
fwrite($fh, $result . " -- \n" . $postFields);
fclose($fh);
var_dump($result);
}
}
$paypal = new Paypal_IPN('sandbox');
$paypal->run();
我应该已经收到无效或有效的结果......
您可能需要添加一些错误处理你的卷曲执行。可能抛出你不知道的错误。 http://php.net/manual/en/function.curl-error.php – Jestep 2014-09-04 13:16:34