cURL Paypal IPN脚本无效

时间:2012-12-31 19:53:30

标签: php curl paypal paypal-ipn

我一直试图弄清楚我的ipn脚本有什么问题。我尝试了很多不同的方法,我也尝试过fsockopen,但我没有让它工作。现在我使用cURL,它仍然无法正常工作。我安装了cURL,它应该正常工作。

我的脚本(只是一个简单的例子,我删除了一些仅用于测试的检查):

<?php
$ACTIVE_CONNECTION = mysql_connect('127.0.0.1', 'mysqluser', 'mysqlpassword') or die("Could not connect to server.");
mysql_select_db('mysqldb', $ACTIVE_CONNECTION) or die("Could not connect to database.");

$tid = $_GET['tx'];
$auth_token = "aqiopfsawdaisytrgkl";

$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";

$post_vars = "cmd=_notify-synch&tx=" . $tid . "&at=" . $auth_token;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'cURL/PHP');

$fetched = curl_exec($ch);



$lines = explode("\n", $fetched);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$payment_amount = $keyarray['mc_gross'];
$payment_status = $keyarray['payment_status'];
$payment_currency = $keyarray['mc_currency'];
$txn_id = $keyarray['txn_id'];
$receiver_email = $keyarray['receiver_email'];
$payer_email = $keyarray['payer_email'];
$username = mysql_real_escape_string($keyarray['custom']);

    if ($payment_status == 'Completed'){
            mysql_query("UPDATE `users` SET vip = '1' WHERE `username` = '".$username."'");
        }
}
else if (strcmp ($lines[0], "FAIL") == 0) {
// manual investigation here
}
?>

1 个答案:

答案 0 :(得分:0)

尝试此操作来测试Sandbox IPN

{{3P>

替换

if (strcmp ($lines[0], "SUCCESS") == 0) {

if (strcmp ($lines[0], "SUCCESS") == 0 || 1 == 1) {