【问题标题】:Trying to test Paypal IPN with Sandbox, but handshake does not go through尝试使用 Sandbox 测试 Paypal IPN,但握手未通过
【发布时间】:2017-07-23 02:48:29
【问题描述】:

我正在尝试设置 Paypal IPN,但无法弄清楚我在下面编写的代码有什么问题。当我尝试使用 Paypal 的沙盒 IPN 模拟器对其进行测试时,它返回“IPN 未发送,握手未验证。请查看您的信息。”我认为问题在于标题需要更改为 sanbox freindly 格式,但无法确定我需要更改的确切内容。

这是代码所在的 URL: http://pmoore17.altervista.org/TWADrama/ticketsales1.php

感谢任何帮助!谢谢!

<?php
// Read the notification from PayPal which comes in the form of a POST array and create the acknowledgement response
$req = 'cmd=_notify-validate';               // add 'cmd' to beginning of the acknowledgement you send back to PayPal

foreach ($_POST as $key => $value) 
{ // Loop through the notification NV pairs
$value = urlencode(stripslashes($value));  // Encode the values
$req .= "&$key=$value";                    // Add the NV pairs to the acknowledgement
}


// Assign the paypal payment notification values to local variables
if($_POST){
$last_name = $_POST['last_name'];
$first_name = $_POST['first_name'];
$quantity = $_POST['quantity'];
$payer_email = $_POST['payer_email'];}

//Set up the acknowledgement request headers (this is the updated version for http 1.1)
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
//Open a socket for the acknowledgement request
$fq = fsockopen ('www.paypal.com/cgi-bin/webscr', 80, $errno, $errstr, 30);

if(!$fq){
    echo "HTTP ERROR";
}
else
{//start 1

// Post request back to PayPal for validation
fputs ($fq, $header . $req);

//once paypal receives the acknowledgement response, another message will be send containing the single word VERIFIED or INVALID

while (!feof($fq)) 
    { //start 2, while not EndOfFile
$res = fgets ($fq, 1024); // Get the acknowledgement response
$res = trim($res);
    if (strcmp ($res, "VERIFIED") == 0) 
        {// start 3, Response is OK
        $fn = "content.txt";
$fp = fopen($fn,"a+") or die ("Error opening file in write mode!");
fputs($fp,"last_name: ".$last_name.", ");
fputs($fp,"first_name: ".$first_name.", ");
fputs($fp,"quantity: ".$quantity.", ");
fputs($fp,"payer_email: ".$payer_email."\n");
fclose($fp) or die ("Error closing file!");
        }//end 3
        else if(strcmp ($res, "INVALID") == 0)
            {//start 4
            $fn = "content.txt";
$fp = fopen($fn,"a+") or die ("Error opening file in write mode!");
fputs($fp,"last_name: ".$last_name.", ");
fputs($fp,"first_name: ".$first_name.", ");
fputs($fp,"quantity: ".$quantity.", ");
fputs($fp,"payer_email: ".$payer_email."\n");
fclose($fp) or die ("Error closing file!");
            }//end 4


} //end 2
fclose ($fq);  //close file pointer
} //end 1
?>

【问题讨论】:

    标签: php paypal paypal-ipn paypal-sandbox


    【解决方案1】:

    尝试改变这个:

    //Open a socket for the acknowledgement request
    $fq = fsockopen ('www.paypal.com/cgi-bin/webscr', 80, $errno, $errstr, 30);
    

    到这里:

    //Open a socket for the acknowledgement request
    $fq = fsockopen ('ssl://www.sandbox.paypal.com/cgi-bin/webscr', 443, $errno, $errstr, 30);
    

    【讨论】:

      【解决方案2】:

      您可以使用旧的 Paypal SDK 来验证收到的通知,而不是制作自己的(通常是错误的)解决方案。与作曲家:

      $ composer require paypal/adaptivepayments-sdk-php

      或手动下载 SDK。然后使用PPIPNMessage 类进行验证:

      // you can omit both arguments, mode defaults to "live"
      $ipn = new PPIPNMessage('', ['mode' => 'sandbox']);
      $valid = $ipn->validate(); // returns bool
      $data = $ipn->getRawData(); // returns the IPN notification as array
      
      // continue with things
      

      也许只为一个课程获取整个 SDK 太过分了,但无论如何这是你的选择 :)

      【讨论】:

      • 在过去的几天里,您的按钮/链接中的 notify_url 覆盖也不起作用(似乎)。自从上次 Amazon/GoDaddy/其他花哨的大“云”家伙中断以来,我没有收到 IPN 通知。不是说它是相关的,只是标记那个时刻。
      • 你不需要整个SDK,你可以在这里得到IPN代码github.com/paypal/ipn-code-samples/tree/master/php最近几天,IPN模拟器一直没有为我工作,但我在做的时候收到了IPN通知向 paypal.com 或 sandbox.paypal.com 付款
      猜你喜欢
      • 2016-07-05
      • 2016-05-27
      • 2017-02-17
      • 2016-04-29
      • 2013-02-20
      • 1970-01-01
      • 2017-01-02
      • 2013-10-06
      • 2013-09-20
      相关资源
      最近更新 更多