PayPal IPN停止向数据库写入数据问题排查求助(沙箱环境流程正常但无数据入库)
PayPal IPN停止向数据库写入数据问题排查求助(沙箱环境流程正常但无数据入库)
我有一个基于PayPal的小额捐赠网页,之前一直运行正常,但几天前突然失效了,我完全找不到原因。我上网查了PayPal IPN是否有更新之类的信息,但一无所获。
在沙箱账号上测试时,流程看起来都没问题:能正常进入交易页面,交易完成后也能跳转到返回URL,沙箱账号的通知里也能看到捐赠交易记录,但本该把交易数据写入数据库的部分完全没工作。
相关代码
表单页面 test.php
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <!-- Identify your business so that you can collect the payments. --> <input type="hidden" name="business" value="sb-spoit2175143@business.example.com"> <!-- Specify a Donate button. --> <input type="hidden" name="cmd" value="_donations"> <!-- Ostatní proměnné --> <input type="hidden" name="cancel_return" value="donate_zruseno.php"> <input type="hidden" name="return" value="donate_dokonceno.php"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="notify_url" value="donate_test.php"> <input type="hidden" name="currency_code" value="CZK"> </form>
IPN回调处理页面 donate_test.php
<?php $DATABASE_HOST = 'HOST'; $DATABASE_USER = 'USER'; $DATABASE_PASS = 'PASS'; $DATABASE_NAME = 'DATABASE'; $pripojeni = new mysqli($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME); // read the post from PayPal system and add 'cmd' $req = 'cmd=_donations'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // Vyčteme nastavení z databáze. $sql_nastaveni = mysqli_query($pripojeni, "SELECT sandbox, webhook FROM podpora_nastaveni"); while($db_nastaveni = mysqli_fetch_array($sql_nastaveni)) { $nastaveni_webhook = $db_nastaveni['webhook']; $sandbox = $db_nastaveni['sandbox']; } //post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Host: www.sandbox.paypal.com\r\n"; $header .= "Content-Type: text/html; charset=utf-8"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; //$header .= "Connection: close\r\n"; $fp = fsockopen ('ssl://sandbox.paypal.com', 443, $errno, $errstr, 30); if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp (trim($res), "VERIFIED") == 0) { $sql = "INSERT INTO podpora (datum, discord, email, castka, cenzura, zprava, platnost) VALUES (NOW(), 'discord,', 'test@test.cz', '0', 'ne', 'test', '2022-12-10')"; mysqli_query($pripojeni, $sql); } else if (strcmp (trim($res), "INVALID") == 0) { } } fclose ($fp); } ?>
我做过的尝试
我试过把mysqli_query的代码移到if (!$fp)的分支里(用来测试数据库连接是否正常),这时候手动访问donate_test.php确实能在数据库中插入测试数据,但通过PayPal完整流程走的时候,还是没有任何数据入库。
我感觉问题可能是交易根本没有触发donate_test.php这个IPN回调页面,但完全找不到原因,有没有大佬能帮我排查一下?
备注:内容来源于stack exchange,提问作者Bazim
相关产品推荐
相关产品推荐

