Thinkphp5一键自动注册帐号和邮件激活

浏览:1512 发布日期:2017/12/01 分类:功能实现 关键字: TP5 激活 邮箱 邮件 发送
一键自动注册pop3邮件激活:http://www.sucaihuo.com/php/110.html
Tp整合邮件发送:http://t.cn/RYRJyPL

如果自动注册失败可以手动点注册
接下来是代码实现<?php
/**
 * Created by PhpStorm.
 * User: netcec
 * Date: 17-2-17
 * Time: 下午4:13
 */

namespace app\home\controller;

use app\common\controller\Curl;
use app\common\controller\SEK;
use think\Url;
use app\common\controller\JsDati;

class Index extends Curl
{
    protected $memberInfo = [];
    public function index()
    {
        return view("index",[],["__PUBLIC__"=>'public/',]);
    }
    /**需要注册的平台以此做为cookie文件名字
     * @return string
     */
    protected function getPlatformName()
    {
        return 'www.thinkphp.cn';
    }

    /**
     * @param string $img_path
     * @return string
     */
    public function saveImage($img_path=''){
        $img_path or $img_path = '/dynamic/capture/'.md5(time()).'thinkphp.png';
        $url = 'http://www.thinkphp.cn/member/verify.html';
        $content = self::get($url,$this->register_page_cookie);
        $path = PATH_DATA.'/'.ltrim($img_path,'/');
        SEK::touch($path);
        file_put_contents($path,$content);
        return $img_path;
    }

    /**获取注册页面
     * @return string
     */
    protected function getRegisterPage()
    {
        return self::get('http://www.thinkphp.cn/member/register.html',$this->register_page_cookie,true);
    }

    /**
     * 获取验证码
     * @return string
     */
    public function getRegisterCapture(){
        $this->getRegisterPage();
        return $this->saveImage();
    }


    /**注册帐号
     * @return array
     */
    public function register()
    {
        $captures = $this->getRegisterCapture();
        $result = (new JsDati())->jsdati_upload(PATH_DATA.$captures,25);
        $result = json_decode($result,true);
        if (!$result || $result['result'] === false) return '解码失败!';
        $data = [
            'username' => 'thinkPHP123sd',
            'password' => 'thinkPHP',
            'repassword' => 'thinkPHP',
            'email' => 'demozxc1@163.com',
            'seccodeverify' => $result['data']['val'],
        ];
        $post = self::post('http://www.thinkphp.cn/member/registerpost.html',http_build_query($data),$this->register_page_cookie,true);

        if (strpos($post,'注册成功,激活邮件已经发动到')){
            $user = 'demozxc1@163.com';//你的注册邮箱
            $pwd = '123456';//你的授权码
            $mail_server = 'pop.163.com';
            $mail_port = 110;
            $mail = new \Pop3mail();
            $cookie_file = "";

            /*邮件过滤条件   也可以不传*/
            $params = [
                'from' => 'ThinkPHP <noreply@thinkphp.org>',
                'title_containing' => '=?UTF-8?B?VGhpbmtQSFDnlKjmiLfmv4DmtLvpgq7ku7Y=?=',
            ];
            set_time_limit(0);

            /* 返回空数组则说明激活失败*/
            $preg='/<a .*?href=["|\'](.*?)["|\'].*?>/is';
            $res = $mail->getlist($preg,$mail_server,$mail_port,$user,$pwd,10,$cookie_file,$params);
            if ($res === false) return ['message'=>'授权码错误'];
            if (!empty($res)){
                return '注册成功';
            }else{
                return '注册失败';
            }
        }

        return ['message'=>'未知错误'];
    }

}
邮件激活类<?php
class Pop3mail{
    var $count;
    var $result;
    var $error;
    function getlist($preg,$mail_server, $mail_port, $mail_user, $mail_pass, $max = 10,$cookie_file="",$params=array(),$follow=false,$rq_header=[]){
        $return = array();//
        $pop3 = new POP3();
        for($j=0;$j<3;$j++){
            if ( ! $pop3->connect($mail_server, $mail_port ) || ! $pop3->user($mail_user) || ( $count = $pop3->pass($mail_pass) ) === false ) {
                $pop3->quit();
                $this->error = ( 0 === $this->count ) ? 'There doesn’t seem to be any new mail.' : $pop3->ERROR;
                return false;
            }
            $this->count = $count ;
            if(!empty($max)){
                if($count < $max )$max = $count;
            }
            //最多尝试3次,每次sleep20秒
            $min = $this->count<=$max ? 1 : $count-$max;
            for ( $i = $count; $i >=$min; $i-- ) {//每次最多只检查5封邮件
                $encryption="";//加密的邮件内容
                $message = $pop3->get($i);
                if($message == false){
                    continue;
                }
                foreach ((array)$message as $line) {
                    $encryption.=$line;
                }
                $header = "";
                $body = "";
                $mParser = mParser::fromString($encryption,$header,$body);
                $from = $mParser->getFrom();
                $subject = $mParser->getSubject();
                $html = $mParser->getBodyHtml();
                if(!empty($params["title_containing"])){
                    if(strpos($subject,$params['title_containing']) === false){
                        continue;
                    }
                }
                if(!empty($params["from"])){
                    if(strtolower($params["from"]) != strtolower($from)){
                        continue;
                    }
                }
                $links = array();

                $arr = array();
                preg_match_all($preg,$html,$links);
                array_filter($arr);
                if(isset($links[1]) && !empty($links[1])){
                    $links = $links[1];
                }
                if(!empty($links)){
                    foreach($links as $a){
                        if(!empty($a)){
                                \app\common\controller\Curl::get($a,$cookie_file,false,[],$rq_header,$follow);
                                $return[] = $a;
                        }
                    }
                }

            }
            if(!empty($return)) {
                return $return;
            }
            sleep(20);
            $pop3->quit();

        }
        return $return;//

    }

}




/*
* mail_fetch/setup.php
*
* @package SquirrelMail
*
* @copyright (c) 1999-2006 The SquirrelMail Project Team
*
* @copyright (c) 1999 CDI (cdi@thewebmasters.net) All Rights Reserved
* Modified by Philippe Mingo 2001 mingo@rotedic.com
* An RFC 1939 compliant wrapper class for the POP3 protocol.
*
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* pop3 class
*
* $Id: class-pop3.php 9503 2008-11-03 23:25:11Z ryan $
*/


?>
评论( 相关
后面还有条评论,点击查看>>