1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
set_time_limit(100);
//date_default_timezone_set('PRC');
function matchMailHead($str){
$headList = array();
$headArr = array('subject','date');
foreach ($headArr as $key){
if(preg_match('/^'.$key.':(.*?)[\n\r]$/ism', $str,$m)){
$match = trim($m[1]);
$headList[$key] = $key=='date'?strtotime($match): mb_decode_mimeheader($match);
}
}
return $headList;
}
function getValidCode($mailserver,$email,$password){
if(strpos($mailserver,":993")!==false){//ssl
$host= "{".$mailserver."/imap/ssl/novalidate-cert}INBOX";
}
else{
$host= "{".$mailserver."}INBOX";
//$host= "{".$mailserver."/notls}";
}
//echo $host;
$mbox = imap_open($host, "$email", "$password") or die("can't connect: " . imap_last_error());
$sorted = imap_sort($mbox, SORTDATE, 1);//日期降序排列
$total=count($sorted);
$num=5;//读取最新的前5封邮件找验证码,如果你这个邮箱收发量大,这里改下数字,如改为10,读取前10封
if($num>$total)$num=$total;
for ($i&#061;0;$i<$num;$i&#043;&#043;){
$no&#061;$sorted[$i];
$headers &#061; imap_fetchheader($mbox, $no); //获取信件标头
$headArr &#061; matchMailHead($headers); //匹配信件标头
//echo json_encode($headArr)."
";
if($headArr["subject"]&#061;&#061;&#039;Welcome to Rola-IP platform&#039;){//验证码邮件标题匹配读取验证码
$body&#061; base64_decode(imap_fetchbody($mbox, $no, 1));
preg_match("/Your Regisiter Code is:\s*(\d&#043;)/i",$body,$m);
return $m[1];
}
}
imap_close($mbox);
return &#039;&#039;;
}
function get_user_name($num){
$un&#061;"";
for($i&#061;0;$i<$num;$i&#043;&#043;)$un.&#061;chr(rand(1,26)&#043;96);
return $un;
}
function get_password($chrnum,$num){
$pwd&#061;"";
for($i&#061;0;$i<$chrnum;$i&#043;&#043;)$pwd.&#061;chr(rand(1,26)&#043;96);
for($i&#061;0;$i<$num;$i&#043;&#043;)$pwd.&#061;rand(0,9);
return $pwd;
}
function get_num($num,$isQQ){
$v&#061;$isQQ?rand(1,9):1;
$num-&#061;1;
for($i&#061;0;$i<$num;$i&#043;&#043;)$v.&#061;rand(0,9);
return $v;
}
function sendCode($email){
$content&#061;file_get_contents("http://adm.fxtcvip.com/send_email_register_verify_code?email&#061;$email");
$o&#061;json_decode($content);
if($o->code!&#061;&#061;0)die("发送验证码失败&#061;&#061;》".$o->msg);
}
/////////////////////////////////////////////////////////////////////////
$email&#061;$_GET["email"];
$password&#061;$_GET["password"];
$mailserver&#061;isset($_GET["mailserver"])?$_GET["mailserver"]:"imap.mail.com:143";///////////传递了服务器地址使用传递的
sendCode($email);//发送验证码
sleep(15);//暂停15秒等待对方服务器发邮件
$ver_code&#061;getValidCode($mailserver,$email,$password);
if($ver_code&#061;&#061;"")die("获取验证码失败&#xff0c;请适当调整sleep时间给对方服务器发送邮件~~");
$user_name&#061;get_user_name(7);
$pwd&#061;get_password(3,4);
$phone&#061;get_num(11,false);
$qq&#061;get_num(10,true);
$url&#061;"http://adm.fxtcvip.com/reg?user_name&#061;$user_name&password&#061;$pwd&phone&#061;$phone&qq&#061;$qq&email&#061;$email&remark&#061;http://www.paypal.com,http://www.amazon.com&ver_code&#061;$ver_code";
$content&#061;file_get_contents($url);//注册
$o&#061;json_decode($content);
if($o->code!&#061;&#061;0)die("注册失败&#061;&#061;&#061;>".$o->msg.$url);
//注册成功登陆系统获取token
$url&#061;"http://adm.fxtcvip.com/login?user_name&#061;$user_name&password&#061;$pwd";
$content&#061;file_get_contents($url);//登陆系统获取token
$o&#061;json_decode($content);
if($o->code!&#061;&#061;0)die("登陆系统失败&#061;&#061;&#061;>".$o->msg);
echo "Token&#xff1a;".$o->data->token." user_name&#xff1a;$user_name password&#xff1a;$pwd";
?> |