飞嗨,欢迎您的光临,本博所发布之文章皆为作者亲测通过,如有错误,欢迎通过各种方式指正。(本博已于2015.12.6升级到php7,运行环境php7 php-fpm + nginx1.8.0)

腾讯域名邮箱一键登陆

PHP lf 193228℃ 0评论

用过新浪、阿里云、网易和腾讯的域名邮箱,我觉着腾讯的域名邮箱是最好用的,腾讯域名邮箱提供的diy是最多的,新浪域名邮箱的垃圾邮件是最多的,多的让我受不了,网易域名邮箱倒是没有垃圾邮件,但是diy的地方太少了,阿里云也一样,而且那个通过web发邮件的界面太丑…可能阿里巴巴的射击师自认为是创新,颠覆传统的邮箱UI设计。腾讯域名邮箱和qq邮箱使用的其实是一套系统,telnet smtp.exmail.qq.com 25和telnet smtp.qq.com 25完全是连接的同一个系统,所以腾讯的反垃圾邮件机制其实还是棒棒哒…只是虽然腾讯域名邮箱是国内这几家中最好的,但是在开放的api中,还是很坑人,官方的api文档竟然是有错误的!!!我试了好几次,各种猜测,终于能一键登陆了。于是,把他写成一个class

目前,腾讯域名邮箱的资料还是好少的,遇到问题,在搜索引擎上很难找到别人的经验,得自己思考,可能,这个邮箱服务,要么自己架设邮件服务器,要么购买邮箱服务,要么使用域名邮箱,就进去exmail.qq.com登陆,反正也不碍事儿,所以高手都没有做这个的。我这个小白白,在大学的时候试过一次,因为官方文档不全(和connect.qq.com相比,我觉得域名邮箱是外包给人写的api文档)失败了,最近这几天有空,想到来为大学遇到的问题画上一个句号! 百度网盘下载

exmail.class.php

exmail.class.php


  qqexmail.class.php /**
*@link http://blog.feehi.com
*@author wfee <admin@feehi.com>
*@created at 2015-2-28 sun
*@version 1.0
*/
class qqexmail{
/**
*@var string client_id 管理员账号,注册腾讯域名邮箱时的账号,如wfee,不是admin@feehi.com
*@var string client_secret 接口key,在管理邮箱->工具箱->开放接口->接口key 处获得
*@var string username 需要登录的邮箱用户名,@domain前面部分,如:admin
*/
const HOST = ‘https://exmail.qq.com';
private $client_id;
private $client_secret;
private $username;
public function __CONSTRUCT($client_id,$client_secret,$username)
{
$this -> client_id = $client_id;
$this -> client_secret = $client_secret;
$this -> username = $username;
}
/**
*@description 获得access_token
*@return string access_token
*/
public function getToken()
{
$data =array(
‘grant_type’ => ‘client_credentials’,
‘client_id’ => $this -> client_id,
‘client_secret’ => $this -> client_secret,
);
$res = $this -> postMethod(”,$data,SELF::HOST.’/cgi-bin/token’);
$resarr = json_decode($res);
return $resarr->access_token;
}
/**
*@description 获得auth_key
*@var string access_token 传入getToken()中获得的access_token
*@return string auth_key
*/
public function getAuthkey($access_token)
{
$data = array(
‘alias’ => $this -> username.’@feehi.com’,
‘access_token’ => $access_token,
);
$url = ‘http://openapi.exmail.qq.com:12211/openapi/mail/authkey';
$res = $this -> postMethod(”,$data,$url);
$resarr = json_decode($res);
return $resarr -> auth_key;
}
/**
*@description 获得一键登录的url
*@var string auth_key 传入getAuthkey()中获得的auth_key
*@return string url
*/
public function login($auth_key)
{
$data = array(
‘fun’ => ‘bizopenssologin’,
‘method’ => ‘bizauth’,
‘ticket’ => $auth_key,
‘agent’ => ‘wfee’,
‘user’ => $this -> username.’@feehi.com’,
);
$url = SELF::HOST.’/cgi-bin/login?';
$url .= http_build_query($data);
return $url;
}
/**
*@description 模拟post提交数据
*/
function postMethod($header,$data,$url)
{
$ch = curl_init();
$res= curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
$result = curl_exec ($ch);
curl_close($ch);
if ($result == NULL) {
return 0;
}
return $result;
}
}
?>  使用qqexmail.class.php
exmail.php

exmail.php

工具箱->开放接口->接口key 处获得
$username = ‘admin';//需要登录的邮箱用户名,@domain前面部分,如:admin
$mail = new qqexmail($client_id,$client_secret,$username);//实例化
$url = $mail -> login();//获得一键登录的url
echo “<script>location.href='”.$url.”‘\<script>”;//自动跳转登录
?>

转载请注明:飞嗨 » 腾讯域名邮箱一键登陆

喜欢 (0)or分享 (0)
发表我的评论
取消评论
表情
(2)个小伙伴在吐槽
  1. What sort of work do you do? motilium 10 The plan is activated only after being adopted by states that collectively represent a majority of the Electoral College, 270 electoral votes or more.
    匿名2016-01-21 23:53 回复
  2. No, I'm not particularly sporty zoloft sale no prescription It also called for the permanent extension of tax credits used by the wind and solar power industries.
    匿名2016-01-21 17:35 回复
粤ICP备15018643号-1