我有一个小动作脚本,当有人用Paypal购买时,我会运行。
Using the notify_url=http://www.mysite.com/my-automatic-script.php
我正在使用我网站上的mail()功能自动抓取电子邮件地址并使用某些信息更新用户。
一切都运行得很完美,但剧本只是不断重复和重复。 (我每隔5分钟就收到一封电子邮件)..
脚本在这里:
require('wp-blog-header.php');
$user_email = trim(isset($_POST['payer_email']) ? $_POST['payer_email'] : "");
$us_firstname = trim(isset($_POST['first_name']) ? $_POST['first_name'] : "");
$us_lastname = trim(isset($_POST['last_name']) ? $_POST['last_name'] : "");
$randomkey = rand(0, 9999);
$user_name = $us_lastname . '_' . $randomkey;
$user_id = email_exists( $user_email );
if ( !$user_id ) {
$random_password = wp_generate_password ( 12, false, false );
$user_id = wp_create_user( $user_name, $random_password, $user_email );
wp_update_user( array ('ID' => $user_id, 'first_name' => $us_firstname, 'last_name' => $us_lastname) ) ;
update_user_meta( $user_id, 'subscription_status', 'subscribed' );
update_user_meta( $user_id, 'subscription_level', '3' );
update_user_meta( $user_id, 'subscription_pack', 'Manual' );
update_user_meta( $user_id, 'subscription_key', '' );
update_user_meta( $user_id, 'subscription_expires', date('Ymd', strtotime('+ 365 day')) );
// The message
$headers = "From: no-reply@mysite.com";
$message2 = "Here is my message";
// Send
mail($user_email, 'Welcome to my site', $message2, $headers);
//end mail
break;
} else {
$headers = "From: no-reply@mysite.com";
$message2 = "This user is already registered";
mail('me@me.com', 'Purchase from Registered User', $message2, $headers);
}
break;
提前致谢!是休息;足够吗?
另一个更新:
我去了PDT PayPal路线:
看起来这似乎有效!
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
$auth_token = "my-secret-code";
$req .= "&tx=$tx_token&at=$auth_token";
// 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 ('www.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
// read the body data
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}
// parse the data
$lines = explode("\n", $res);
$keyarray = array();