我尝试在我的项目中实施PayPal并设置D:\home\site\wwwroot\env\Scripts\wheelhouse\
(通过PayPal沙箱)来接收付款通知。我创建了一个IPN
帐户,并有两个dev
地址。一个用于卖家(email
),一个用于买家。我将seller-facilitator@someDomain.com
文件在线存储在我的网站中,并在卖家帐户中配置php
,如下所示:
ipn url
当我尝试模拟http://example.org/someFolder/ipnsample.php
时,我收到一条消息IPN
,因此配置似乎没问题,但是我无法接收任何通知邮件。
PHP:
IPN was sent and the handshake was verified.
HTML(购买表格):
// 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'];
// 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.0\r\n";
$header .= "Host: 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";
$fp = fsockopen ('tls://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// Open a socket for the acknowledgement request
// 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
if (strcmp ($res, "VERIFIED") == 0) { // Response contains VERIFIED - process notification
// Send an email announcing the IPN message is VERIFIED
$mail_From = "IPN@example.com";
$mail_To = "My@Mail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
else if (strcmp ($res, "INVALID") == 0) {
// Authentication protocol is complete - begin error handling
// Send an email announcing the IPN message is INVALID
$mail_From = "IPN@example.com";
$mail_To = "My@Mail.com";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
}
fclose($fp); // Close the file
答案 0 :(得分:1)
首先检查邮件方法是否正常工作:
$mail_From = "IPN@example.com";
$mail_To = "My@Mail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
只需将代码放在侦听器php文件和刷新页面之上。如果邮件方法正常,只需在while()
之前使用serialize($ fp)方法调试变量$ fp $mail_From = "IPN@example.com";
$mail_To = "My@Mail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = serialize($fp);
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);