我正在使用这个类
<?php
class paypalIPN {
//sandbox:
private $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
//live site:
//private $paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
private $data = null;
public function __construct()
{
$this->data = new stdClass;
}
public function isa_dispute()
{
//is it some sort of dispute.
return $this->data->txn_type == "new_case";
}
public function validate()
{
// parse the paypal URL
$response = "";
$url_parsed = parse_url($this->paypal_url);
// generate the post string from the _POST vars aswell as load the
// _POST vars into an arry so we can play with them from the calling
// script.
$post_string = '';
foreach ($_POST as $field=>$value) {
$this->data->$field = $value;
$post_string .= $field.'='.urlencode(stripslashes($value)).'&';
}
$post_string.="cmd=_notify-validate"; // append ipn command
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->paypal_url);
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
//keep the peer and server verification on, recommended
//(can switch off if getting errors, turn to false)
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);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
$response = curl_exec($ch);
if (curl_errno($ch))
{
die("Curl Error: " . curl_errno($ch) . ": " . curl_error($ch));
}
curl_close($ch);
return $response;
if (preg_match("/VERIFIED/", $response))
{
// Valid IPN transaction.
return $this->data;
}
else
{
return false;
}
}
}
我记得在这种模式下:
public function get_ipn()
{
$ipn = new paypalIPN();
$result = $ipn->validate();
$logger = new Log('/error.log');
$logger->write(print_r($result));
}
但我只获得“VERIFIED”或“1”(whitout 或使用 print_r 函数)。
我也只是尝试直接返回原始卷曲响应
return $response;
或者
return $this->response;
或者也
return $this->parse_string;
但每次我只收到“1”或“已验证”......
非常感谢