我已经设置了响应PayPal IPN呼叫的代码,该代码过去一直有效,但是由于某种原因最近中断了。 (在上个月内)。我回去用PayPal IPN模拟器对其进行了测试,现在看到了一些非常奇怪的行为。如果我将模拟器指向我网站上的响应者,并选择web_accept(未对其他任何字段进行更改),然后单击“发送IPN”,则会返回“已发送IPN并且握手已通过验证。”
但是,如果我将所有字段都填写为真实的购买商品,然后单击“发送IPN”,则会收到消息“未发送IPN,并且握手未验证。请查看您的信息。”如果我仔细查看数据库和记录的错误,我的服务器将执行我设置的代码以将该人输入到组中,就像他们已经付款并记录了交易一样,就像我希望它被记录下来一样。仅当接收到来自PayPal的交易并且PayPal发回已验证的代码时,此代码才会触发。有什么作用?
我通过Stack Overflow进行了挖掘,并尝试了所有建议以及我能找到的其他任何东西。没运气。我尝试过上线只是为了看看它是否是IPN模拟器中的错误,但交易未得到处理。
这是我的验证码...
public function processIpn($post_data = null) {
$encoded_data = 'cmd=_notify-validate';
if ($post_data === null) {
// use raw POST data
if (!empty($_POST)) {
$raw_post_data = file_get_contents('php://input');
$ray_post_array = explode('&', $raw_post_data);
$myPost = [];
foreach($ray_post_array as $keyval){
$keyval = explode('=', $keyval);
if(count($keyval) == 2){
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
}
foreach($myPost as $key => $value){
$encoded_data .= "&$key=" . urlencode($value);
}
$this->entryData = $encoded_data;
} else {
throw new Exception("No POST data found.");
}
} else {
// use provided data array
$this->post_data = $post_data;
foreach ($this->post_data as $key => $value) {
$encoded_data .= "&$key=" . urlencode($value);
}
}
if ($this->debug) {
$this->response = "VERIFIED";
$this->response_status = '200 OK';
} else {
$this->curlPost($encoded_data);
}
if (strpos($this->response_status, '200') === false) {
throw new Exception("Invalid response status: " . $this->response_status . $encoded_data);
}
if (strpos($this->response, "VERIFIED") !== false) {
return true;
} elseif (strpos($this->response, "INVALID") !== false) {
return false;
} else {
throw new Exception("Unexpected response from PayPal. " . $encoded_data);
}
}
protected function curlPost($encoded_data) {
$uri = $this->getPaypalHost();
$ch = curl_init($uri);
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, $encoded_data);
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'));
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . "/cacert.pem");
$this->response = curl_exec($ch);
$this->response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
if ($this->response === false || $this->response_status == '0') {
$errno = curl_errno($ch);
$errstr = curl_error($ch);
curl_close($ch);
throw new Exception("cURL error: [$errno] $errstr");
}
curl_close($ch);
}