gpt4 book ai didi

php - Paypal IPN 返回无效

转载 作者:太空宇宙 更新时间:2023-11-03 16:11:16 24 4
gpt4 key购买 nike

这是我用来解释 PayPal 通知的代码。我一直收到来自 Paypal 的“无效”。很抱歉,这个问题本质上只是一个代码片段,但我已经研究了这么久,似乎无法取得任何进展。

如果有人有任何想法,但需要查看一些调试信息,那么我设法获得它的方法是通过 php mail() 函数 - 所以只要问我就可以得到它。

<?php
$debugmessage = "";

require($_SERVER['DOCUMENT_ROOT'] . '/xxxx.php');
mysql_connect("$server", "$user", "$password") or die(mysql_error());
mysql_select_db("$database") 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
echo "http error";
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
$debugmessage .= "|".$res;
$debugmessage .= "|".strlen($req);
if (strcmp ($res, "VERIFIED") == 0) {
// PAYMENT VALIDATED & VERIFIED!
$debugmessage .= "|"+"payment VALID";

$email = $_POST['payer_email'];
$password = mt_rand(100000, 999999);
mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error());
$to = $email;
$subject = 'Download Area | Login Credentials';
$message = '
Thank you for your purchase!
Your account information
-------------------------
Email: '.$email.'
Password: '.$password.'
-------------------------
You can now login at xxxxxxxxxxxx';
$headers = 'From:xxxxxxx@xxxxxxx.com' . "\r\n";
mail($to, $subject, $message, $headers);
}
else if (strcmp ($res, "INVALID") == 0) {
$debugmessage .= "|"."payment INvalid";
// PAYMENT INVALID & INVESTIGATE MANUALY!
$to = 'xxxxxx@xxxxxxx.com';
$subject = 'Download Area | Invalid Payment';
$message = '
Dear Administrator,
A payment has been made but is flagged as INVALID.
Please verify the payment manualy and contact the buyer.
Buyer Email: '.$email.'
';
$headers = 'From:xxxxxx@xxxxxxx.com' . "\r\n";
mail($to, $subject, $message, $headers);

}
}
fclose ($fp);
}
mail("xxxxxxx@gmail.com",$debugmessage,"");
?>

以防万一有人理解那可怕的困惑,$debugmessage 在脚本运行后包含这个:

|HTTP/1.0 200 OK |840|X-Frame-Options: SAMEORIGIN |840|Strict-Transport-Security: max-age=14400 |840|Strict-Transport-Security: max-age=14400 |840|Content-Type: text/html; charset=UTF-8 |840|Date: Tue, 05 Mar 2013 04:42:09 GMT |840|Content-Length: 7 |840|Connection: close |840| |840|INVALID|840|payment INvalid

我读过有关不使用 fsockopen 以及使用称为“CURL”的内容的内容,但我对这些内容不太有信心。

非常感谢任何帮助。

最佳答案

5 小时后...我的解决方案是丢弃代码并使用 this tutorial 重做它.

强烈推荐。

关于php - Paypal IPN 返回无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15216338/

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