<?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 $
*/
?>
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。