我的主机启用了 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);
}