我需要有关 PayPal 订阅付款 IPN 处理的建议。我已经基于 PayPal 代码示例编写了一个 IPN 处理程序/侦听器。侦听器将 IPN 消息复制回 PayPal,前面带有 cmd=_notify-validate。我可以毫无问题地设置订阅,即用户输入他们的详细信息,并将其连同他们的订单信息一起传递给他们登录到他们的帐户并同意订阅的 PayPal。在 PayPal 成功回复后,订单被确认并更新了我的数据库。我遇到的问题是定期付款通知。我已将订阅设置为每天通过 PayPal 沙盒进行,每次 PayPal 建议客户付款,等待客户登录到他们的 PayPal 帐户并接受付款,这会导致另一个 IPN 确认付款完成。我正在发回验证请求之前的 IPN 消息,并收到来自 PayPal Sandbox 的空响应。根据 PayPal 文档,我希望收到“已验证”或“无效”吗?但是,PayPal 对返回消息的响应是“”还是 null?IPN 验证码如下所示,使用“<a href="https://www.sandbox.paypal.com/cgi-bin/webscr" rel="nofollow">https://www.sandbox.paypal.com /cgi-bin/webscr”作为 URL:
$url_parsed=parse_url($this->paypal_url);
// generate the post string from the _POST vars and load the _POST vars into an array
$post_string = "cmd=_notify-validate"; // start IPN response with validate command
foreach ($_POST as $field=>$value) {
$post_string .= '&';
$this->ipn_data["$field"] = $value;
$post_string .= $field.'='.urlencode(stripslashes($value));
}
// open the connection to PayPal
$fp = fsockopen($url_parsed[host],443,$err_num,$err_str,30);
if(!$fp) {
// could not open the connection. If logging is on, log the error message
$this->last_error = "fsockopen error no. $errnum: $errstr";
$this->log_ipn_results(false);
return false;
} else {
// Post the data back to PayPal
fputs($fp, "POST $url_parsed[path] HTTPS/1.1\r\n");
fputs($fp, "Host: $url_parsed[host]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
// loop through the response from the server and append to variable
while(!feof($fp)) {
$this->ipn_response .= fgets($fp, 1024);
}
fclose($fp); // close connection
/* PayPal sends a single word back, which is VERIFIED if the message originated with PayPal
or INVALID if there is any discrepancy with what was originally sent */
if (strcmp ("INVALID", $this->ipn_response) != 0) {
// The above is a work around to address null response! For now!
// Valid IPN transaction.
$this->log_ipn_results(true);
return true;
} else {
// Invalid IPN transaction. Check the log for details.
$this->last_error = 'IPN Validation Failed.';
$this->log_ipn_results(false);
return false;
}
我已经测试了超时,并相信该过程完全在 30 秒的时间限制内,并确认 $post_string 的结构在开始时使用 cmd 复制了原始消息。我能想到的唯一其他问题是 IPN vars 的返回发布是从受 SSL 证书保护的页面发送的?无论如何,除非我遗漏了一些东西,否则我不相信 PayPal 沙盒实际上正在响应,因此结果为空?任何建议或指导将不胜感激,因为我依靠多个每日订阅付款期来通过沙盒进行测试。