沙盒/阶段的贝宝超级慢.大约20秒来响应我的IPN处理程序.现在根本没有回应



我以paypal官方网站的IPN处理程序的实现为例

现在这在一开始效果很好。但答案越来越慢。有一段时间,他们工作良好,延迟了20秒。现在我有几分钟没有交通了。发生了什么事?也许贝宝的沙盒ipn处理程序本身即将关闭?他们的设置不好?

我想提到这篇文章(它有点启发)

注意,我甚至没有得到一个初始日志。贝宝似乎再也不支持我了。

IPN是可调用的,我可以从中调用它,比如说一个匿名窗口,它会写入日志文件。

为了完整起见,这里是我的文件:

<?php
use ...;
// CONFIG: Enable debug mode. This means we'll log requests into 'ipn.log' in the same directory.
// Especially useful if you encounter network errors or other intermittent problems with IPN (validation).
// Set this to 0 once you go live or don't require logging.
define("DEBUG", 1);
// Set to 0 once you're ready to go live
define("USE_SANDBOX", 1);
define("LOG_FILE", "./ipn.log");
require_once(__DIR__ . "/../../bootstrap.php");

//define("LOG_FILE", __DIR__ . "/../../../../../japi/logs/ipn.log");
error_log(date('[Y-m-d H:i e] '). "Lukas: Initial call to log". PHP_EOL, 3, LOG_FILE);
// Read POST data
// reading posted data directly from $_POST causes serialization
// issues with array data in POST. Reading raw POST data from input stream instead.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
//$mmessage ="hi lukas <br/>";
//
//    include_once JCR_KINT_CLASS;
//$mmessage .= @Kint::dump($myPost);
//mail("lukas.meier@gmail.com", "IPN from paypal test", $mmessage);
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}
// Post IPN data back to PayPal to validate the IPN data is genuine
// Without this step anyone can fake IPN data
if(USE_SANDBOX == true) {
$paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
} else {
$paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}
$ch = curl_init($paypal_url);
if ($ch == FALSE) {
return FALSE;
}
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, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
if(DEBUG == true) {
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
}
// CONFIG: Optional proxy configuration
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
// Set TCP timeout to 30 seconds
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
// CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
// of the certificate as shown below. Ensure the file is readable by the webserver.
// This is mandatory for some environments.
//$cert = __DIR__ . "./cacert.pem";
//curl_setopt($ch, CURLOPT_CAINFO, $cert);
$res = curl_exec($ch);
if (curl_errno($ch) != 0) // cURL error
{
if(DEBUG == true) {
error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
}
curl_close($ch);
exit;
} else {
// Log the entire HTTP response if debug is switched on.
if(DEBUG == true) {
error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 3, LOG_FILE);
error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE);
}
curl_close($ch);
}
// Inspect IPN validation result and act accordingly
// Split response headers and payload, a better way for strcmp
$tokens = explode("rnrn", trim($res));
$res = trim(end($tokens));
if (strcmp ($res, "VERIFIED") == 0) {
// check whether the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your PayPal email
// check that payment_amount/payment_currency are correct
// process payment and mark item as paid.
// assign posted variables to local variables
//$item_name = $_POST['item_name'];
//$item_number = $_POST['item_number'];
//$payment_status = $_POST['payment_status'];
//$payment_amount = $_POST['mc_gross'];
//$payment_currency = $_POST['mc_currency'];
//$txn_id = $_POST['txn_id'];
//$receiver_email = $_POST['receiver_email'];
//$payer_email = $_POST['payer_email'];

$jppa = new JcrPayPalAnswer();
$jppa->createFromPayPalIpnResponseArray($myPost);
if($jppa->is_completed){
//content of file: paykey => array($project_id, serialize($fd), $statisticsId);
$r = parse_ini_file(JCR_PAYKEY_INIFILE);
if($r){
$pkArr = $r[$jppa->pay_key];
$project_id = $pkArr[0];
/** @var FundingDetails $fd */
$fd = unserialize(base64_decode($pkArr[1]));
$statisticsId = $pkArr[2];
$jcrp = new JewcerProject($project_id);
$jewcerFee = $jcrppa->amount_fee_account;
$fundingAmount = $jcrppa->amount_funding_account_brutto;
$x = null;
$js = new JcrStatistic($x, $statisticsId);
//fna [$amount, $paypalfee, $jewcerFeeAmount]
$fnA = JcrPayPalService::getFeesAndAmount($fd->amount, $fd->coverfee, $jcrp->getFundingFee());
$amount = $fnA[0];
$paypalfee = $fnA[3];
$jewcerFeeAmount = $fnA[2];
$fd->wepayFee = $paypalfee;
$fd->jcrFee = $jewcerFeeAmount;
$amount_with_fee = $amount;
if ($fd->coverfee) {
$fd->amount_without_fees = $amount - $paypalfee - $jewcerFeeAmount;
} else {
$fd->amount_without_fees = $fd->amount;
}
$fd->amount = $amount_with_fee;
$jcrf = new JcrFunder($project_id);
$jcrf->setBasicFunderValues($fd);
$jcrf->save();
$js->add_stats_from_fundingdetails($fd, "jfp3");
EmailService::sendDonationSuccessEmails($jcrp, $fd);
unset($r[$jppa->pay_key]);
UtilityService::write_ini_file($r, JCR_PAYKEY_INIFILE);
UtilityService::write_ini_file(array('ok',  $jcrf->id ), JCR_PAYPAL_STATUS_FOLDER . $jppa->pay_key);
}else{
error_log(date('[Y-m-d H:i e] '). "JEWCER ERROR 3200: couldn't find entry for paykey in inifile, inifile val: " . var_export($r, true). PHP_EOL, 3, LOG_FILE);
}
//    mail("lukas.meier@gmail.com", "IPN COMPLETED", serialize($jppa));
//    JcrPayPalKeyPool::$keys[$jppa->pay_key] = $jppa; //eventually verify emails
//    JcrPayPalKeyPool::$keys[$jppa->pay_key] = $jppa; //eventually verify emails
}
if(DEBUG == true) {
error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
}
} else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
// Add business logic here which deals with invalid IPN messages
if(DEBUG == true) {
error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
}
}

多年来,我一直在为各种各样的项目使用IPN。根据我的经验,如果一切配置正确,并且IPN脚本没有问题,那么它将非常接近实时地工作,不会出现很多问题。

不过,你可能会遇到的情况是,如果你的IPN脚本因任何原因失败,或者只是在PayPal被击中时向其发送200以外的响应代码,它会重试,但每次重试都会延迟发送时间。因此,它可能会立即发送一个,如果不能提供200的响应,它将在5秒、10秒、20秒、40秒等时间内发送另一个。(这不是它使用的确切增量,但这是它所做的一个例子。)

如果您的脚本在某个时候没有返回200响应,或者发送到脚本的IPN经常出现这种情况,PayPal的系统会将您的IPN移动到比其他运行良好的IPN慢的队列中。

最终,如果它仍然没有修复,他们只会在你的帐户上完全禁用它。

查看您PayPal帐户中的IPN历史记录,查看您在发送的IPN上收到的响应。当然,这将允许您验证它们是否也确实被发送了。

您还需要检查服务器上的PHP错误日志,看看当IPN脚本被击中时是否发生了任何事情,导致它因任何原因失败。例如,这种情况可能只发生在某些IPN类型中,或者当数据中包含特定字符时。

相关内容

最新更新