gpt4 book ai didi

php - 努力接收 Paypal 沙盒 IPN 发布数据

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

我的主机启用了 php 5.0 和 SSL,但在严格搜索在线论坛和博客后,我终究无法弄清楚为什么我空手而归,而我正在尝试使用 Paypal IPN 脚本。我正在使用沙盒模拟器来测试脚本,因此在检索 Post 数据时没有任何风险。请引用我的以下代码 -

$header = '';

$req = 'cmd=_notify-validate';

foreach($_POST as $key => $value) {
//All PayPal reqs must be URL encoded
$value = urlencode(stripslashes($value));
//Append key => value pair to CMD string
$req .= "&$key=$value";
}


//Post info back to paypal for verification
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
// $header .= "Host: ssl://www.sandbox.paypal.com\r\n";
$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://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

$con=mysql_connect("localhost","quadsour_xswitch","xswitch");
mysql_select_db("quadsour_xswitch",$con);//$data="NULL"

if(!$fp) {
//Process HTTP Error
$filename = 'debug.txt';
$filehandle=fopen($filename, 'w');
fwrite($filehandle, $errstr.'('.$errno.')');
fclose($filehandle);
die();

$message .= "\n HTTP ERROR. \n";

} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = stream_get_contents($fp, 1024);
/* $data="INSERT INTO ipn SET
complete='".$errstr."',invoice='".$errno."'";
$query=mysql_query($data);
*/

//VERIFIED TRANSACTION
//PAYMENT
if($_POST['payment_status'] == 'completed') {
$data="INSERT INTO ipn SET
complete='cond'";
$query=mysql_query($data);

$data="INSERT INTO ipn SET
complete='true',
invoice='".$_POST['invoice']."',
email='".$_POST['payer_email']."'
";
$query=mysql_query($data);

//$subscription = //Do SQL to retrieve the subscription based on $_POST['invoice']


}

}

fclose ($fp);
}

最佳答案

作为已经编写了几个 PHP 库来使用 PayPal IPN(下面的 CodeIgniter 和 Symfony2 的)的人,我不得不说你的脚本远不足以在安全和安全的情况下处理 PayPal IPN 的所有可能性稳健的方式。

与其重新发明轮子,只需插入这些库之一,具体取决于您的 PHP 设置:

关于php - 努力接收 Paypal 沙盒 IPN 发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10480961/

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