2015-06-14 109 views
0

我已经得到了这个贝宝IPN脚本,在沙箱模式下测试它,它工作完美,但是当我在实时模式下使用它不起作用。没有错误或其他。我该怎么办才能解决这个问题?php - PayPal IPN在沙盒上工作,但没有生活

<?php 
define("DEBUG", 0); 
define("USE_SANDBOX", 0); 
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, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
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')); 
$cert = __DIR__ . "./cacert.pem"; 
curl_setopt($ch, CURLOPT_CAINFO, $cert); 
$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 { 
     // Log the entire HTTP response if debug is switched on. 
     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); 
     } 
     curl_close($ch); 
} 
$tokens = explode("\r\n\r\n", trim($res)); 
$res = trim(end($tokens)); 
if (strcmp ($res, "VERIFIED") == 0) { 

    $receiver_email = $_POST['receiver_email']; 
    $payer_email = $_POST['payer_email']; 
    $payment_status = $_POST['payment_status']; 
     $item_number = $_POST['item_number']; 

     if($payment_status == 'Completed') { 
     require_once("../assets/includes/core.php"); 
     require_once("../assets/includes/settings.php"); 

if(USE_SANDBOX == true) { 
     $rec_email = "[email protected]"; 

} else { 
     $rec_email = "[email protected]"; 
} 

     if($receiver_email == $rec_email) { 
     $con = mysql_connect($dbhost,$dbuser,$dbpass); 
     mysql_select_db('website'); 

     function generateString($length) 
{ 
    $charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"; 

    for($i=0; $i<$length; $i++) 
     $key .= $charset[(mt_rand(0,(strlen($charset)-1)))]; 

    return $key; 
} 
$code = generateString("30"); 

      $insert_code = mysql_query("INSERT INTO `$dbtable_wsc` (`code`,`payer_email`,`item_number`,`used`,`gen_date`) VALUES('$code','$payer_email','$item_number','no', NOW())") or die("MYSQL INSERT CODE QUERY ERROR: " . mysql_error()); 

     mysql_close($con); 
    require("phpmailer/class.phpmailer.php"); 

    $mail = new PHPMailer(); 
    $mail->IsSMTP(); 
    $mail->SMTPAuth = true; 
    $mail->Host  = "ssl://smtp.gmail.com"; 
    $mail->Port  = 465; 
    $mail->Username = "[email protected]"; 
    $mail->Password = "******"; 
    $mail->FromName = "mydomain"; 
    $mail->Subject = "mydomain | Redeem Code"; 
    $mail->Body  = " 
    Your redeem code is ".$code." 

    To use your code click here: $root_link/webshop/red.php?code=".$code."&step=step2 

    Thank you for have given your support with a donation to mydomain, we really appreciate it! 

    mydomain"; 
    $mail->AddAddress($payer_email); 
    if(!$mail->Send()){ 
     echo "Mailer Error. Contact our Support Team giving them this error: " . $mail->ErrorInfo; 
    } 

echo "Email sent to $payer_email with the redeem code. If you didn't received your email go <a href='./red.php'>there</a> to redeem you code."; 
    } else { 
     die("You are trying to pay to the wrong email!"); 
     } 

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

测试了多次在沙盒模式,但每次我设置的生活和我的客户尝试买东西exept的IPN确认所有作品,使他们没有得到任何东西。我还想就如何做出更好的检查以确保付款尚未处理或不是假的一些建议。谢谢!

P.S.我知道PHP的mysql扩展被弃用,但目前这不是我的主要问题。

回答

0

没有阅读代码,但我知道我看,并且有两个不同的ITN:一个用于生活,一个用于沙箱。

必须设置他们两个

希望帮助

+0

你是什么意思了蚊帐做? – J19