gpt4 book ai didi

php - paypal ipn 未通过验证

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:48 33 4
gpt4 key购买 nike

我正在为 Paypal ipn 使用以下代码:

    <?php

mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("PayPal") or die(mysql_error());

// 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";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\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);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

// PAYMENT VALIDATED & VERIFIED!

}

else if (strcmp ($res, "INVALID") == 0) {

// PAYMENT INVALID & INVESTIGATE MANUALY!

}
}
fclose ($fp);
}

?>

在以各种方式进行测试后,除了以下情况,我的一切都正常工作:

if (strcmp ($res, "VERIFIED") == 0)  

不工作

if (strcmp ($res, "VERIFIED") == 1)

作品

显然它没有得到验证,因为我从沙箱发送 IPN。

可能缺少什么?

最佳答案

因为你们都说 strcmp($res, "VERIFIED") == 1 是真的,$res 比字符串 VERIFIED “大”了 1 个字符。我的猜测是 $res 末尾有一个\n 字符或其他需要删除的字符。在使用 strcmp 调用这些行之前,尝试执行类似 str_replace('\n', '', $res) 的操作。只是大声思考。如果这不起作用,请告诉我。

仅供引用,PayPal 有在线示例代码,可使用 cURL 在 PHP 中验证 IPN。链接:http://www.x.com/developers/paypal/documentation-tools/paypal-code-samples#instantpaymentnotification

关于php - paypal ipn 未通过验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10522102/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com