facebook登陆
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/zh_CN/sdk.js#xfbml=1&appId={your appId}&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<script>
//facebook
var sendFbid1 = function() {
FB.getLoginStatus(function(response){
if(response.status == 'connected') {
var id = "";
var name = "";
FB.api('/me', function (response) {
id = response.id;
name = response.name;
email = response.email;
gender = response.gender;
var api_url = 'user.php?act=api_login';
$.post(api_url, { id: id, name: name, email: email, gender: gender, type: 'facebook' },
function(data){
if(data == 1)
{
window.location.href="index.php";
}
});
});
}
else{
FB.login(function(){}, {scope: 'publish_actions'});
FB.login();
}
});
};
window.fbAsyncInit = function() {
FB.Event.subscribe('auth.login', sendFbid1);
FB.Event.subscribe('auth.authResponseChange', sendFbid1);
}
</script>
google登陆
<script type="text/javascript">
// 加载google js文件(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js?οnlοad=render'; // 后边加onload触发初始化函数
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
// 初始化函数
function render() {
gapi.signin.render('google_login', {
'callback': 'signinCallback',
'approvalprompt': 'auto',
// 这里写入你的App ID
'clientid': ' {your clientid}',
'cookiepolicy': 'single_host_origin',
'requestvisibleactions': 'http://schemas.google.com/AddActivity',
'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email'
});
}
// 回调函数
function signinCallback(authResult) {
if (authResult) {
// 是否有错
if(authResult["error"]==undefined){
// 隐藏登录按钮
$("#google_login").hide();
// 加载api
gapi.client.load("oauth2","v2",function(){
var request=gapi.client.oauth2.userinfo.get();
request.execute(function(obj){
// 取得登录邮箱并显示
if(obj["email"]){
id = obj["id"];
name = obj["name"];
email = obj["email"];
gender = obj["gender"];
var api_url = 'user.php?act=api_login';
$.post(api_url, { id: id, name: name, email: email, gender: gender, type: 'google' },
function(data){
if(data == 1)
{
window.location.href="index.php";
}
});
}
});
});
}
}
}
// 取消与应用关联的代码
function disconnectUser() {
var revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token=' + gapi.auth.getToken().access_token;
$.ajax({
type: 'GET',
url: revokeUrl,
async: false,
contentType: "application/json",
dataType: 'jsonp',
success: function(nullResponse) {
// 成功以后隐藏登录信息
// 显示登录按钮
$("#google_login").show();
alert("退出成功!");
},
error: function(e) {
alert("!請到 https://plus.google.com/apps 手动解除!");
window.open("https://plus.google.com/apps");
}
});
}
</script>
qq企业邮箱登陆
public function login_exmail(){
$admin_qq_email = $_SESSION['fruser_accout'] . "@{企业邮箱}.com";
$this->load->library('curl');
if( empty($_SESSION['access_token']))
{
$token_url = "https://exmail.qq.com/cgi-bin/token";
$post_data = array (
'grant_type' => 'client_credentials',
'client_id' => '{your_client_id}',
'client_secret' => '{your client_secret}',
);
$token_json = $this->curl->post($token_url,$post_data);
$token_result = json_decode($token_json);
$access_token = $token_result->access_token;
$_SESSION['access_token'] = $access_token;
}
else
{
$access_token = $_SESSION['access_token'];
}
if(!empty($access_token) && empty($_SESSION['auth_key']))
{
$authkey_url = "http://openapi.exmail.qq.com:12211/openapi/mail/authkey";
$header_data = array (
'Host: exmail.qq.com',
'Authorization: Bearer ' . $access_token
);
$post_data = array (
"alias" => $admin_qq_email,
);
$authkey_json = $this->curl->post($authkey_url,$post_data, $header_data);
$authkey_result = json_decode($authkey_json);
$auth_key = $authkey_result->auth_key;
$_SESSION['auth_key'] = $auth_key;
}
else
{
$auth_key = $_SESSION['auth_key'];
}
if(!empty($auth_key))
{
header ( "Location: https://exmail.qq.com/cgi-bin/login?fun=bizopenssologin&method=bizauth&agent={your_client_id}&user="
. $admin_qq_email . "&ticket=" . $auth_key );
}
}