簡體   English   中英

貝寶IPN可在沙盒中工作,但不能實時運行

[英]Paypal IPN works in sandbox but not live

我已從此處http://www.sanwebe.com/2012/07/paypal-instant-payment-notification-ipn/comment-page-1#comment-6871獲取並改編了以下代碼

<?php
include 'dbdata.php';
//Change these with your information
$paypalmode = 'sandbox'; //Sandbox for testing or empty ''
$paypalmode = '';
if($_POST)
{
    if($paypalmode=='sandbox')
    {
        $paypalmode     =   '.sandbox';
    }
    $req = 'cmd=' . urlencode('_notify-validate');
    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }
    $ch = curl_init();
    //curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    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_HTTPHEADER, array('Host: www'.$paypalmode.'.sandbox.paypal.com'));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com'));
    $res = curl_exec($ch);
    curl_close($ch);

    if (strcmp ($res, "VERIFIED") == 0)
    {
        $transactionID = $_POST['txn_id'];
        $payerEmail = $_POST['payer_email'];
        $paymentStatus = $_POST['payment_status'];
        $firstName = $_POST['first_name'];
        $surname = $_POST['last_name'];
        $payerID = $_POST['payer_id'];
        $addressName = $_POST['address_name'];         
        $addressCountry = $_POST['address_country'];
        $addressCountryCode = $_POST['address_country_code'];
        $addressZip = $_POST['address_zip'];
        $addressState = $_POST['address_state'];
        $addressCity = $_POST['address_city'];
        $addressStreet = $_POST['address_street'];
        $mcGross = $_POST['mc_gross'];
        $mcShipping = $_POST['mc_shipping'];
        $mcCurrency = $_POST['mc_currency'];
        $paymentDate = $_POST['payment_date'];


        $mdate= date('Y-m-d H:i:s',strtotime($paymentDate));
        $otherStuff = json_encode($_POST);

          $query5 = "INSERT INTO paypal (transationID,payerEmail,paymentStatus,firstName,surname,paymentDate,payerID,addressName,addressCountry,addressCountryCode,addressZip, addressState,addressCity,addressStreet,mcGross,mcShipping,mcCurrency,allData) VALUES  ('".$transactionID."','".$payerEmail."','".$paymentStatus."','".$firstName."','".$surname."','".$mdate."','".$payerID."','".$addressName."','".$addressCountry."','".$addressCountryCode."','".$addressZip."','".$addressState."','".$addressCity."','".$addressStreet."','".$mcGross."','".$mcShipping."','".$mcCurrency."','".$otherStuff."')";


     mysql_query($query5); 
  $mail_From    = "xxx@googlemail.com";
  $mail_To      = "xxx@googlemail.com";
  $mail_Subject = "VERIFIED IPN";
  $mail_Body    = $otherStuff;
  //mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

    }

    if (strcmp ($res, "INVALID") == 0)
    {
        $transaction_id = $_POST['txn_id'];
        $payerid = $_POST['payer_id'];
        $firstname = $_POST['first_name'];
        $lastname = $_POST['last_name'];
        $payeremail = $_POST['payer_email'];
        $paymentdate = $_POST['payment_date'];
        $paymentstatus = $_POST['payment_status'];
        $mdate= date('Y-m-d h:i:s',strtotime($paymentdate));
        $otherStuff = json_encode($_POST);

         $query5 = "INSERT INTO paypal (transationID,payerEmail,paymentStatus) VALUES  ('".$transaction_id."','".$payeremail."','".$paymentstatus."')";
     mysql_query($query5); 

    }
}
?>

如果我使用沙盒模式和IPN模擬器,則會將數據正確插入表中。 現在,我已將客戶的貝寶帳戶的IPN設置設置為指向我的腳本並打開了IPN,但沒有任何反應。

該網站正在使用快速結帳。 該網站位於美國。 php腳本托管在我們的服務器(英國)上。

貝寶顯示已發送,如果我重新發送IPN,則它們會重新顯示為已發送。 誰能看到這里出什么問題了?

  • 更新。 我已經使用了基於英國的Paypal帳戶,並將IPN通知設置為相同的URL,並從我妻子的Paypal帳戶發送了付款,然后我進入了數據庫。

另外,我沒有從IPN獲取我妻子的客戶詳細信息,但從模擬器獲得了。

沃比先生

只需更換

foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

foreach ($_POST as $key => $value){
    $value = urlencode(stripslashes($value));
    $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
    $req .= "&$key=$value";         
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM