gpt4 book ai didi

php - PayPal IPN 监听器使用沙箱但不实时

转载 作者:太空宇宙 更新时间:2023-11-03 16:09:58 24 4
gpt4 key购买 nike

我有一个 paypal ipn 监听器 ipn.php,它链接到数据库并使用通知信息更新通知表,然后通过电子邮件将 key 发送到付款人电子邮件。

这是 ipn.php

<?php    

include("class.phpmailer.php");
include("class.smtp.php");

include("config.php");

//Send an empty HTTP 200 OK response to acknowledge receipt of the notification

ini_set("log_errors", "On");
ini_set("error_log", "error.log");

$con = mysql_connect($dbhost,$dbuser,$dbpass);

if($con == false){ echo "Could not connect to mysql: " . mysql_error();}
else{echo "Connected to database successfully!";}

header('HTTP/1.0 200 OK');
header('Connection: close');


$item_name = $_POST['item_name'] != null ? $_POST['item_name'] : "none";
$item_number = $_POST['item_number'] != null ? $_POST['item_number'] : "none";
$payment_status = $_POST['payment_status'] != null ? $_POST['payment_status'] : "none";
$payment_amount = $_POST['mc_gross'] != null ? $_POST['mc_gross'] : "none";
$payment_currency = $_POST['mc_currency'] != null ? $_POST['mc_currency'] : "none";
$txn_id = $_POST['txn_id'] != null ? $_POST['txn_id'] : "none";
$receiver_email = $_POST['receiver_email'] != null ? $_POST['receiver_email'] : "none";
$payer_email = $_POST['payer_email'] != null ? $_POST['payer_email'] : "none";

// Build the required acknowledgement message out of the notification just received
$req = 'cmd=_notify-validate'; // Add 'cmd=_notify-validate' to beginning of the acknowledgement

foreach ($_POST as $key => $value) { // Loop through the notification NV pairs
$value = urlencode(stripslashes($value)); // Encode these values
$req .= "&$key=$value"; // Add the NV pairs to the acknowledgement
}

// Set up the acknowledgement request headers
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; // HTTP POST request
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// Open a socket for the acknowledgement request
$fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// Send the HTTP POST request back to PayPal for validation
fputs($fp, $header . $req);


error_log("reached");

$res = stream_get_contents($fp,1024); // Get the acknowledgement response

while(!feof($fp)){
$res = trim(fgets($fp,1024));

if(empty($res)){
break;
}
}

$res = trim(fgets($fp,1024));

if (strcmp ($res, "VERIFIED") == 0) { // Response contains VERIFIED - process notification


$sql = "INSERT INTO notifications VALUES( DEFAULT, '$item_name','$item_number','$payment_status','$payment_amount','$payment_currency','$txn_id','$receiver_email','$payer_email')";

mysql_select_db($dbname,$con);

if(!mysql_query($sql)){
error_log(mysql_error());
}

if(strcmp($payment_status,"Completed") == 0){
mysql_select_db($dbname, $con);
$key = get_new_key();
$sql = "";
$sql = "INSERT INTO activationkeys VALUES(DEFAULT, '$key', '0', $item_number)";
if(!mysql_query($sql)){
error_log("Could not execute query: " . mysql_error());
}

$mail = new PHPMailer(true);

//Send mail using gmail
if($config_gmail){
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = $config_gmail_username;
$mail->Password = $config_gmail_password;
}

//Typical mail data
$mail->AddAddress($payer_email,"Donator");
$mail->SetFrom($config_merchant_domain,$config_merchant_name);
$mail->Subject = "You're Donation Key";
$mail->Body = "Hey, your payment was successful.\nHere's your key: " . $key;

if(!$mail->send()){
error_log("Message could not be sent: " . $mail->ErrorInfo );
}


}
mysql_close($con);



// Authentication protocol is complete - OK to process notification contents

// Possible processing steps for a payment include the following:

// Check that 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

}
else if (strcmp ($res, "INVALID") == 0) { //Response contains INVALID - reject notification

// Authentication protocol is complete - begin error handling
// Send an email announcing the IPN message is INVALID
$mail_From = "IPN@example.com";
$mail_To = "Your-eMail-Address";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}

fclose($fp); // Close the file

function get_new_key(){
$keycharacters = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$key = "";
for($i = 0; $i < 10; $i++){
$key .= $keycharacters[rand(0,strlen($keycharacters)-1)];
}
return $key;
}

?>

问题是,当我通过沙箱发送时,它会很好地更新数据库并通过电子邮件发送 key ,但是当我尝试实时使用代码时,它什么也没做...

我不知道问题出在哪里。

最佳答案

有什么错误吗?检查 IPN 历史日志?如果进行 API 调用,请确保使用 LIVE Credentials,如果仍然有问题,请给我帐号或电子邮件地址,或向 paypal.com/mts 提交票证

关于php - PayPal IPN 监听器使用沙箱但不实时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20286327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com