【发布时间】:2014-02-13 01:32:03
【问题描述】:
直到昨天(今天早些时候),此 IPN 脚本是否正常工作且没有任何更改...这是核心 PayPal 代码的关键部分,我希望有人可以查看这些代码并让我知道是否有任何问题?我的 Wordpress 代码本身似乎可以正常工作(所以我排除了它)... Paypal 是否再次更改了他们的版本(1.0 到 1.1 到 ??)或 URL 或其他什么?
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
echo $errstr . ' (' . $errno . ')';
$mail_From = 'From: IPN@tester.com';
$mail_To = 'charlwoode@gmail.com';
$mail_Subject = 'HTTP ERROR';
$mail_Body = $errstr;//error string from fsockopen
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
$fh = fopen("logipn.txt", 'a');//open file and create if does not exist
fwrite($fh, "\r\n/////////////////////////////////////////\r\n HTTP ERROR \r\n");//Just for spacing in log file
fwrite($fh, $errstr);//write data
fclose($fh);//close file
}
elseif
{
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
$res=trim($res);
if (strcmp ($res, "VERIFIED") == 0) {
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$aid= $_POST['custom'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross']; //full amount of payment. payment_gross in US
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id']; //unique transaction id
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
//do stuff
}
else {
//do stuff
}
【问题讨论】:
标签: wordpress paypal paypal-ipn