【问题标题】:paypal ipn listener errors贝宝 ipn 侦听器错误
【发布时间】:2013-06-12 16:31:53
【问题描述】:

我正在为 Paypal Adaptive Payments 实现 IPN 侦听器,我从这里下载了示例代码:

https://cms.paypal.com/cms_content/IT/it_IT/files/developer/IPN_PHP_41.txt

然后我做了一个事务(使用沙盒),但我认为示例是错误的,因为代码在我的 error_log 文件中返回了一些错误:

[16-Jun-2013 16:11:34 UTC] PHP Warning:  stripslashes() expects parameter 1 to be string, array given in /var/www/actions/IPNListener.php on line 7
[16-Jun-2013 16:11:34 UTC] PHP Notice:  Undefined variable: header in /var/www/actions/IPNListener.php on line 12
[16-Jun-2013 16:11:34 UTC] PHP Notice:  Undefined index: item_name in /var/www/actions/IPNListener.php on line 18

未定义的索引不仅是“item_name”,而且是所有索引!!!!!

交易正常,交易完成后paypal会自动调用IPN...但是paypal示例代码根本不起作用!你知道怎么解决吗?

【问题讨论】:

    标签: php paypal paypal-ipn paypal-adaptive-payments


    【解决方案1】:

    试试这个

    <?php
    //Build the data to post back to Paypal
    $postback = 'cmd=_notify-validate'; 
    
    // go through each of the posted vars and add them to the postback variable
    foreach ($_POST as $key => $value) {
       $value = urlencode(stripslashes($value));
       $postback .= "&$key=$value";
    }
    
    // build the header string to 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($postback) . "\r\n\r\n";
    
    // Send to paypal or the sandbox depending on whether you're live or developing
    // comment out one of the following lines
    //$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);//open the connection
    $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
    // or use port 443 for an SSL connection
    //$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
    
        if (!$fp) 
        {
            // HTTP ERROR Failed to connect
            //error handling
        }
        else // if we've connected OK
        {
            fputs ($fp, $header . $postback);//post the data back
            while (!feof($fp)) 
            {
                $response = fgets ($fp, 1024);
    
                if (strcmp ($response, "VERIFIED") == 0) //It's verified
                {
                    //do something
                }
                else if (strcmp ($response, "INVALID") == 0) 
                { 
                    //the Paypal response is INVALID, not VERIFIED
                    // This implies something is wrong
                }
            } //end of while
            fclose ($fp);
        }
    ?>
    

    【讨论】:

    • 谢谢,但它返回相同的错误:[16-Jun-2013 16:37:27 UTC] PHP 警告:stripslashes() 期望参数 1 为字符串,数组在 /var/ 中给出第 7 行 www/actions/IPNListener.php [16-Jun-2013 16:37:27 UTC] PHP 注意:未定义变量:第 25 行 /var/www/actions/IPNListener.php 中的标头
    • 让我知道这是否有帮助?
    • 谢谢!标题现在没问题,但仍然存在错误:[16-Jun-2013 18:12:45 UTC] PHP 警告:stripslashes() 期望参数 1 为字符串,数组在 /var/www/actions/IPNListener 中给出.php 在第 7 行
    • 这是 PHP 警告它不是错误。您可以在 php.ini 文件中禁用 PHP 警告或将其写在页面顶部 error_reporting(E_ERROR | E_PARSE);
    • 好的,但 Paypal 响应无效,这是真正的问题!
    猜你喜欢
    • 2014-08-25
    • 2023-04-02
    • 2023-04-10
    • 2016-04-29
    • 2016-10-11
    • 2019-03-31
    • 1970-01-01
    • 2016-05-27
    • 2015-06-16
    相关资源
    最近更新 更多