【发布时间】:2016-04-29 17:33:12
【问题描述】:
我的 ipn 监听器今天(16 年 1 月 22 日)停止工作。据我所知,我已阅读文章和贝宝文档,我的代码完全遵循他们的文档。我现在正在沙箱中进行测试。问题是我收到一个 http 连接错误,这会停止一切。该行是:
if (!$fp) {
//can't go on
}
这是完整的代码
<?php
$log = fopen("ipn.log", "a");
fwrite($log, "\n\nipn - " . gmstrftime ("%b %d %Y %H:%M:%S", time()) . "\n");
header('HTTP/1.1 200 OK');
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
fwrite($log,"$req is: " . $req."\r\n");
$sandbox=1;
if($sandbox == 1) {
$header = "POST https://www.sandbox.paypal.com/cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen("tls://www.sandbox.paypal.com", "443", $errno, $errstr, 30);
} else {
$header = "POST https://www.paypal.com/cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ("ssl://www.paypal.com", "443", $errno, $errstr, 30);
}
fputs($fp, $header . $req);
fwrite($log,"error no= " . $errno . " errstr= " . $errstr . "\r\n");
// ABOVE RETURNS 0 FOR $errno and null for $errstr
if (!$fp) {
// HTTP ERROR HAPPENS HERE
fwrite($log, "http error\r\n");
} else {
while (!feof($fp)) {
$res = fgets ($fp, 1024);
$res = trim($res);
if (strcmp ($res, "VERIFIED") == 0) {
// do stuff here
fwrite($log, "verified\r\n");
}
else if (strcmp ($res, "INVALID") == 0) {
fwrite($log, "invalid\r\n");
}
}
fclose ($fp);
}
fclose ($log);
?>
================== 运行后的日志文件是这样的:
ipn - Jan 23 2016 00:06:14
$req is: cmd=_notify-validate&payment_type=instant&payment_date=Fri+Jan+22+2016+15%3A30%3A44+GMT-0800+%28Pacific+Standard+Time%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer%40paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John+Smith&address_country=United+States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San+Jose&address_street=123+any+street&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=seller%40paypalsandbox.com&residence_country=US&item_name1=something&item_number1=AK-1234&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=378619000¬ify_version=2.1&custom=2_2%2Bxc&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AIlWjbxX7iz7ACchkv5lDNHsBr8a
error no= 0 errstr=
http error
【问题讨论】:
-
您的代码应该记录的不仅仅是“http 错误”。确定有可用的错误代码吗?
-
感谢您的回复。不知道如何获取该错误代码,但我在头撞墙数小时后放弃了这种方法,并使用了此页面中的 cURL 方法:github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php。第一次工作。新手到 stackoverload - 我应该做些什么来关闭这个线程?
-
直到您解决您的问题无法回答。当提供的唯一信息是您自己设计的错误消息时,原则上其他人会知道发生了什么。
-
不是完全无法回答,因为它是最新的帖子。
标签: paypal paypal-ipn