gpt4 book ai didi

php - Paypal IPN 取消订阅,发送新的登录信息?

转载 作者:太空宇宙 更新时间:2023-11-03 15:57:06 31 4
gpt4 key购买 nike

我希望有人能给我指出正确的方向。

我已经在网站上创建了一个 IPN 监听器,目前它适用于订阅和创建他们的 PIN 号码的人,将他们的登录信息(电子邮件和随机生成的 PIN)添加到数据库中没有问题。然后,他们可以在收到包含详细信息的电子邮件后登录到下载区。

注册工作完美 - 然而,当他们取消订阅时,Paypal 清楚地发送通知并且 IPN 只是发布新的登录,我不知道如何编码发送“对不起你“离开”电子邮件并将其从数据库中删除。

如有任何帮助,我们将不胜感激!

下面的脚本;

<?php

mysql_connect("xxxx", "xxxx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());


// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

// PAYMENT VALIDATED & VERIFIED!

$email = $_POST['payer_email'];
$password = mt_rand(1000, 9999);

mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error());

$to = $email;
$subject = 'xxx Download Area | Login credentials';
$message = '

Thank you for your purchase

Your account information
-------------------------
Email: '.$email.'
Password: '.$password.'
-------------------------

You can now login at xxxxx';
$headers = 'From:xxx@xxx.co.uk' . "\r\n";

mail($to, $subject, $message, $headers);



}

else if (strcmp ($res, "INVALID") == 0) {

// PAYMENT INVALID & INVESTIGATE MANUALY!

$to = 'paypal@xxx.co.uk';
$subject = 'xxx Download Area | Invalid Payment';
$message = '

Dear xxx,

A payment has been made for the Download area on xxx.co.uk but is flagged as INVALID.
Please verify the payment manually and contact the buyer.

Please contact xxx at xxx on xxx if you need additional help, the buyers email is below;

Buyer Email: '.$email.'
';
$headers = 'From:noreply@xxx.co.uk' . "\r\n";

mail($to, $subject, $message, $headers);

}
}
fclose ($fp);
}
?>

最佳答案

只需添加一个开关来检查与 ipn 一起发送的 txn_type 的类型。这只是我的头脑,但试一试......

$email = $_POST['payer_email'];               

switch ($_POST['txn_type']) {
case 'web_accept':
//you received a payment such as a buy now button
//so now lets do things such as trigger a call to a
//function to create an email or add POST vars to a database
$this->createUser($email, $password);
$this->createEmail($email, $password);
break;
case 'subscr_signup':
//This shows that someone has subscribed using a subscribe button
//We can do anything here such as increase the users access level
break;
case 'subscr_payment':
//payment for a subscribed user has just been made
//do something such as send them a conformation email
break;
case 'subscr_eot':
//this is a End Of Terms meaning that the subscriber either canceled or
//paypal could not process the payment due to the user not having the funds
//lets remove them from our database and send them an email
$this->removeUser($email);
break;
case 'subscr_cancel':
//Here the user canceled their account so lets remove them and send an email
$this->removeUser($email);
break;
}

function createEmail($email, $password)
{

$to = $email;
$subject = 'xxx Download Area | Login credentials';
$message = '

Thank you for your purchase

Your account information
-------------------------
Email: '.$email.'
Password: '.$password.'
-------------------------

You can now login at xxxxx';
$headers = 'From:xxx@xxx.co.uk' . "\r\n";

mail($to, $subject, $message, $headers);

}

function createUser($email, $password)
{
mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error());
}

沿着这些路线的东西至少应该让你朝着正确的方向前进。

关于php - Paypal IPN 取消订阅,发送新的登录信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7685765/

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