-1

我无法将 Paypal 的 IPN 集成到我的 php 中,我有以下脚本,当在 paypal 沙箱中进行付款时,它一直处于默认情况。

任何帮助,将不胜感激!

$request = "cmd=_notify-validate"; 
    foreach ($_POST as $varname => $varvalue){
        $email .= "$varname: $varvalue\n";  
        if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){  
            $varvalue = urlencode(stripslashes($varvalue)); 
        }
        else { 
            $value = urlencode($value); 
        } 
        $request .= "&$varname=$varvalue"; 
    } 
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,"https://www.sandbox.paypal.com/cgi-bin/webscr");
    //curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com");
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $result = curl_exec($ch);
    curl_close($ch);

    switch($result){
        case "VERIFIED":
                    mail('test@test.com','worked','worked');
            break;
        case "INVALID":
            mail('test@test.com','invaild','invaild');
            break;
        default:
            mail('test@test.com','failed','failed');
    }

如果我给自己发电子邮件 $result 它只是空白。

编辑:我发现这是我的 LAMP 的服务器端问题,但不确定如何解决。

注意:我确实在服务器上安装了 curl,但我不确定它是否配置正确。

4

1 回答 1

2

我建议使用位于此处的 var_dump 和 Paypal 的测试工具进行一些调试:https ://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session

我可以理解使用第三方服务会变得困难且耗时。

可能值得简单地获取 POST 数据,将其序列化并将其应用于变量,这样您就可以在 PayPal 不触发回调的情况下进行测试。

我最初会做这样的事情来获取 PayPal POST。

<?php
   file_put_contents(serialize($_POST), 'post.log');
   //Now you have the post request serialized we can grab the contents and apply it to a variable for fast testing.
?>

您的代码的开始:

<?php
    $_POST = unserialize(file_get_content('post.log'));
    //Now you can execute the script via command line or within your browser without requiring PayPal's testing tool. Use var_dump to investigate what's the issue.
    $request = "cmd=_notify-validate"; 
    foreach ($_POST as $varname => $varvalue){
        $email .= "$varname: $varvalue\n";  
        if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){  
            $varvalue = urlencode(stripslashes($varvalue)); 
        }
        else { 
            $value = urlencode($value); 
        } 
        $request .= "&$varname=$varvalue"; 
    }
?>

现在:这在测试方面更加有效和高效。在您的示例中,您正在给自己发送电子邮件,但在邮件功能正文中的任何位置都没有包含 $result。 http://php.net/manual/en/function.mail.php

PayPal 的 IPN 示例使用 fsock,尽管 CURL 更有效且更易于使用。PayPal 的沙盒更改最近也出现了一些问题。https://www.paypal-community.com/t5/Selling-on-your-website/IPN-response-problem/mp/519862/message-uid/519862#U519862

另外:要确定主要原因是什么,正如您所说,这似乎是您的 LAMP 堆栈。通常从它们检查您的日志目录(通常是/var/log/),您将能够查明失败的原因。

于 2012-08-09T01:25:26.330 回答