【发布时间】:2014-02-26 18:26:45
【问题描述】:
我正在使用贝宝网站上的“教科书”IPN 脚本示例。但是,通过 IPN 模拟器运行此代码时,加载时间很长,然后 PayPal 会抛出此错误:
Proxy Error代理服务器收到来自上游服务器的无效响应。 代理服务器无法处理请求 POST /webapps/developer/applications/ipn_simulator.
原因:从远程服务器读取错误
这是我的 IPN 侦听器代码。
非常感谢您的帮助!
// Send an empty HTTP 200 OK response to acknowledge receipt of the notification
header('HTTP/1.1 200 OK');
// Assign payment notification values to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$job_id = $_POST['custom'];
// Build the required acknowledgement message out of the notification just received
$req = 'cmd=_notify-validate'; // Add 'cmd=_notify-validate' to beginning of the acknowledgement
foreach ($_POST as $key => $value) { // Loop through the notification NV pairs
$value = urlencode(stripslashes($value)); // Encode these values
$req .= "&$key=$value"; // Add the NV pairs to the acknowledgement
}
// Set up the acknowledgement request headers
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; // HTTP POST request
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
// Open a socket for the acknowledgement request
$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// Send the HTTP POST request back to PayPal for validation
fputs($fp, $header . $req);
while (!feof($fp)) { // While not EOF
$res = fgets($fp, 1024); // Get the acknowledgement response
$message = 'fail';
if (strcmp ($res, "VERIFIED") == 0) { // Response contains VERIFIED - process notification
// Possible processing steps for a payment include the following:
$job = $this->jobmodel->get_by_id($job_id);
// Process payment
$this->jobmodel->add_payment($job_id, $_POST);
$message = $job_id;
}
else if (strcmp ($res, "INVALID") == 0) {
// Authentication protocol is complete - begin error handling
$message = 'fail';
}
$filename = 'Paypal IPN' . date('d-m-Y g-i', mktime());
$myFile = $_SERVER['DOCUMENT_ROOT']."/assets/html/paypal/$filename.html";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $message);
fclose($fh);
}
fclose($fp); // Close the file
【问题讨论】:
标签: php codeigniter paypal paypal-ipn