dqv84329 2014-05-24 23:18
浏览 47
已采纳

IPN - 教程有错误

I was trying to follow the tutorial on paypal's developer site on setting up a basic IPN listener, and it looks nearly syntax for syntax like on their example. In fact when I started receiving the errors I've been receiving, I thought I would create a new ipn listener and use just the code they have in their example to see if it was my code or not and received the same errors.

Warning: fgets(): supplied argument is not a valid stream resource in \supergate\ipn.php on line 42

Warning: feof(): supplied argument is not a valid stream resource in \supergate\ipn.php on line 39

the errors on those line numbers are for these pieces of code at those lines:

 while (!feof($fp)) //line 39
{

 $res = fgets($fp, 1024); //line 42

here is the rest of the entire code

<?php
//Empty Header HTTP 200 OK reponse to ack 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_ammount   =$_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 ack message of notification just received
$req = 'cmd=_notify-validate'; //add 'cmd=_notify-validate' to beginning of acknowledgement

foreach ($_POST as $key => $value) {  //loop through the notification nv pairs
  $value = urlencode(stripcslashes($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
"; //HTTP POST REQUEST
$header .="Content-Type: application/x-www-form-urlencoded
";
$header .="Content-Length: " .strlen($req) . "

";

// Open a socket for the acknowledgement request
$fp = fsockopen('ssl://sandbox.paypal.com', 443, $errno, $errstr, 30);

//send the http post request back to paypal for validation
fputs($fp, $header . $req);

while (!feof($fp)) 
{

    $res = fgets($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) 
    {
     //WRITE TO EMAIL


    */
 }
//--------------------------------------------------------------------------------------------------------------------
 else if (strcmp($res,"INVALID") == 0) 
 {

   //write to email
}


fclose($fp); //close the file
?>

Okay now the new warning I get is this:

Warning: fgets() [function.fgets]: SSL: An existing connection was forcibly closed by the remote host. 
  • 写回答

1条回答 默认 最新

  • douju6651 2014-05-24 23:27
    关注

    You're not checking the result of fsockopen() which returns FALSE upon failure.

    $fp = fsockopen(...);
    if ($fp === FALSE) {
        exit("Could not open socket");
    }
    

    One clue from the documentation is the first parameter:

    hostname If OpenSSL support is installed, you may prefix the hostname with either ssl:// or tls:// to use an SSL or TLS client connection over TCP/IP to connect to the remote host.

    Note that your example is using ssl:// - it is possible your server is not correctly configured with OpenSSL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题