paypal_ipn麻烦插入sql-server数据库

时间:2014-11-15 09:55:32

标签: php sql-server-2008 paypal-ipn

晚上好,我一直在玩Paypal IPN,所有接缝都可以,但它不会插入我的数据库。

我使用的是sql server / mssql2008。

我已经测试了数据库连接以查看它是否出错并且我没有得到任何日志。任何帮助都将非常感谢。

-Chris

define("DEBUG", 1);
define("USE_SANDBOX", 1);
define("LOG_FILE", "./ipn.log");

$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
    $keyval = explode ('=', $keyval);
    if (count($keyval) == 2)
        $myPost[$keyval[0]] = urldecode($keyval[1]);
}

$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
    $get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
    if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
        $value = urlencode(stripslashes($value));
    } else {
        $value = urlencode($value);
    }
    $req .= "&$key=$value";
}


if(USE_SANDBOX == true) {
    $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
} else {
    $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}

$ch = curl_init($paypal_url);
if ($ch == FALSE) {
    return FALSE;
}

curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);

if(DEBUG == true) {
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
}

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));


$res = curl_exec($ch);
if (curl_errno($ch) != 0) 
    {
    if(DEBUG == true) { 
        error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
    }
    curl_close($ch);
    exit;

} else {

        if(DEBUG == true) {
            error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 3, LOG_FILE);
            error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE);


            list($headers, $res) = explode("\r\n\r\n", $res, 2);
        }
        curl_close($ch);
}


if (strcmp ($res, "VERIFIED") == 0) {

    if(DEBUG == true) {
        error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
    }

    if ($payment_status == "Completed")
    { 

        if(DEBUG == true) 
        {
            error_log(date('[Y-m-d H:i e] '). "COMPLETED PAYMENT STATUS");
        }


$database_user = "dbuser";
$database_pass = "dbpass";
$database_dbo4 = "datebase";

$conn4=odbc_connect($database_dbo4,$database_user,$database_pass);
$account = "testaccountid";
$amounttotal = 5; 


$sql = "insert into donation (accountid, amount) VALUES ($account, $amounttotal)";


$result = odbc_exec($conn4, $sql);





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

    if(DEBUG == true) {
        error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
    }
}

1 个答案:

答案 0 :(得分:0)

我在听众的最顶端运行了以下代码

ini_set('display_errors', 1); error_reporting(E_ALL);

然后我在firefox中手动运行了监听器,并且在数据库设置中出现错误,我的用户名有问题...... Doh。

然后我发现它仍然不会插入但有些玩游戏我在我的代码中发现了这个

if (strcmp ($res, "VERIFIED") == 0) {

    if(DEBUG == true) {
        error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
    }

// IF USING EBAY AND A WEBSITE TO SELL GOODS THEN YOU NEED TO ENSURE THE PAYMENT STATUS IS COMPLETED AND DETERMINE WHICH CHANNEL SENT THE REQUEST
// USE CUSTOM FIELD TO DETERMINE WHAT SENT THE PAYMENT  
//$payment_status = $_POST['payment_status'];
//  $custid =  $_POST["custom"];
//  $txn_type = $_POST["txn_type"];
//  $item_name = $_POST['item_name1'];

我所做的就是从

中删除//
//$payment_status = $_POST['payment_status'];

现在一切正常,我可以自己检查!

希望这个答案有助于其他人。

由于