php - IPN 验证回发到 HTTPS

标签 php paypal

我的 PHP 代码目前使用以下代码回传到 PayPal。我如何更新它以满足即将生效的新支付安全标准?

$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) 
{
  $value = urlencode(stripslashes($value));
  $req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\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) 
{
  //an error occurred...
} 

else 
{
  fputs ($fp, $header . $req);

  while (!feof($fp)) 
  {
    $res = fgets ($fp, 1024);

    if(strcmp ($res, "VERIFIED") == 0) 
    {
      //all is well...
    }
  }
}

最佳答案

要启用 IPN 验证回发到 HTTPS,请按如下方式更改您的代码,

$fp = fsockopen( 'tls://ipnpb.paypal.com', 443, $errno, $errstr, 30);

PayPal 建议在生产环境中使用 ipnpb.paypal.com 端点。

此外,您需要将 HTTP/1.0 更改为 HTTP/1.1 以符合 PayPal 升级。

需要提交的Header,

$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen( $req ) . "\r\n";
$header .= "Connection: close\r\n\r\n";

对于沙箱的改变,

 $header .= "Host: www.paypal.com\r\n";

$header .= "Host: www.sandbox.paypal.com\r\n";

关于php - IPN 验证回发到 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37589359/

相关文章:

php - 带有 PHP 文件的 JQuery AJAX 缓存

php - MYSQL之类+组

Paypal 激活 'Accelerated boarding'

使用 scala 的 play 框架中的 PayPal 依赖项

ios - Paypal - IOS SDK - 企业账户/个体户

php - 如何解压来自 Qt 结构/字符串的 PHP 中的 boolean 值

php - 如何让我的服务器与 iPhone 应用程序一起工作?

php - 如何在 MySQL 和 PHP 中选择随机行?

Paypal 订阅/定期付款

java - 使用 Java Web 服务配置 PayPal IPN