测试PayPal ipn到文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了测试PayPal ipn到文件相关的知识,希望对你有一定的参考价值。

Writes to a text file, test.txt, instead of email for the purposes of testing.
  1. <?php
  2. $req = 'cmd=_notify-validate';
  3.  
  4. foreach ($_POST as $key => $value) {
  5. $value = urlencode(stripslashes($value));
  6. $req .= "&$key=$value";
  7. }
  8.  
  9. // post back to PayPal system to validate
  10. $header .= "POST /cgi-bin/webscr HTTP/1.0
  11. ";
  12. $header .= "Content-Type: application/x-www-form-urlencoded
  13. ";
  14. $header .= "Content-Length: " . strlen($req) . "
  15.  
  16. ";
  17. $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
  18.  
  19. // assign posted variables to local variables
  20. $item_name = $_POST['item_name'];
  21. $item_number = $_POST['item_number'];
  22. $payment_status = $_POST['payment_status'];
  23. $payment_amount = $_POST['mc_gross'];
  24. $payment_currency = $_POST['mc_currency'];
  25. $txn_id = $_POST['txn_id'];
  26. $receiver_email = $_POST['receiver_email'];
  27. $payer_email = $_POST['payer_email'];
  28.  
  29. if (!$fp) {
  30.  
  31. // HTTP ERROR
  32.  
  33. } else {
  34. fputs ($fp, $header . $req);
  35. while (!feof($fp)) {
  36. $res = fgets ($fp, 1024);
  37. if (strcmp ($res, "VERIFIED") == 0) {
  38. $fh = fopen("test.txt","w");
  39. fwrite($fh, $payer_email);
  40. }else if (strcmp ($res, "INVALID") == 0) {
  41. //Send Email To You
  42. }
  43. }
  44.  
  45. fclose ($fp);
  46. }
  47. ?>

以上是关于测试PayPal ipn到文件的主要内容,如果未能解决你的问题,请参考以下文章

当 PayPal 发送付款通知 (IPN)

Paypal IPN 沙盒 - IPN 侦听器 - 未验证或无效

PHP Paypal IPN 方法 - 沙盒测试登录详情

使用 IPN 模拟器测试 PayPal IPN SHA-256 合规性

PayPal IPN HTTP 错误 400 - PHP - 使用 PayPal GIT 代码

IPN PAYPAL - 无效测试