我的ipn监听器今天停止工作(1/22/16)。我已经阅读了文章和贝宝文档,我的代码完全按照他们的文档进行,据我所知。我现在正在沙盒中测试。问题是我得到一个http连接错误,并停止了一切。该生产线是:paypal IPN监听器停止工作
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 error'。当然有错误代码可用? – EJP
感谢您的回复。不知道如何得到那个错误代码,但是在几个小时将我的头靠在墙上并使用本页面的cURL方法后,我放弃了这种方法:https://github.com/paypal/ipn-code-samples/斑点/主/ paypal_ipn.php。第一次工作。 Newby到stackoverload - 有什么我应该做的关闭这个线程? – msher220
直到你解决你的问题是无法回答的。当提供的唯一信息是您自己设计的错误信息时,原则上让其他人知道发生了什么。 – EJP