0

ペイパルから標準のIPN.phpサンプルを取得し、エラー処理とmysqlconnection/mysqlqueryをphpスクリプトに追加しました。変数がipnスクリプトに入り、mysqldbに格納されるという問題である可能性があると思います。Mysqlデータベース接続は正常に機能します。私は本当にそのコードをmysqlクエリで考えていますが、それを変更する方法がわかりません。どんな助けでも素晴らしいでしょう!

ipn_errors.logによるエラー

[21-Jan-2013 13:45:57 UTC] PHP Notice:  Undefined variable: item_number in /var/www/ipn.php on line 78
[21-Jan-2013 13:45:57 UTC] PHP Notice:  Undefined variable: payment_status in /var/www/ipn.php on line 78
[21-Jan-2013 13:45:57 UTC] PHP Notice:  Undefined variable: payment_amount in /var/www/ipn.php on line 78
[21-Jan-2013 13:45:57 UTC] PHP Notice:  Undefined variable: payer_email in /var/www/ipn.php on line 78

ipn.php-これらのエラーを作成しています。

// STEP 1: Read POST data

// reading posted data from directly from $_POST causes serialization 
// issues with array data in POST
// reading raw POST data from input stream instead. 
mysql_connect("localhost", "#####", "#####") or die(mysql_error());  
mysql_select_db("#####") or die(mysql_error()); 
$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]);
}
// read the post from PayPal system and add 'cmd'
$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";
}


// STEP 2: Post IPN data back to paypal to validate

$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
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);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

// In wamp like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path 
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);


// STEP 3: Inspect IPN validation result and act accordingly

if (strcmp ($res, "VERIFIED") == 0) {
// check whether 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

// assign posted variables to local variables
$payer_email = $_POST['payer_email'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
} else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
 ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');
}
 mysql_query("INSERT INTO paypalpayments (itemnum, paystatus, payamount, email) VALUES ('', '$item_number', 

'$payment_status', '$payment_amount',  '$payer_email')");
?>
4

1 に答える 1

1

変数は次の行で設定されます。

$myPost[$keyval[0]] = urldecode($keyval[1]);

...そしてスクリプトの後半では、次の$_POSTように変数をコピーするために使用します:

$payer_email = $_POST['payer_email'];

提案:これらの変数を見つけるため$myPostに代わりに使用してください。$_POSTINSERT クエリの前に mysql_real_escape_string() を忘れないでください。

ob_start()先頭と$msg = ob_get_clean()最後で使用すると、この非同期スクリプトのデバッグをある程度進めることができます。次に、自分自身に電子メールで送信できる可変文字列があります。これによりvar_dump()、 などを使用して診断メッセージを発行できるようになります。

于 2013-01-21T19:10:21.543 に答える