These days have been engaged in Tencent and Sina open platform ~ ~ The whole of the fast Halo ~ ~ Two basic almost, the whole out a small piece out to everyone to see.
Interested to explore the mail jackqn@126.com or in the following message ~ ~
sina.html
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>
</title>
<script type= "Text/javascript" >
var ChildWindow;
function Toqzonelogin ()
{
ChildWindow = window.open ("sina_rge.php", "Tencentlogin", "Width=450,height=320,menubar=0,scrollbars=1, resizable=1 , status=1,titlebar=0,toolbar=0,location=1 ");
}
function Closechildwindow ()
{
Childwindow.close ();
}
</script>
<body>
<br><br>
<a href= "#" onclick= ' Toqzonelogin () ' > Login Sina </a>
<br><br>
</body>
sina_rge.php
<?php
Require_once ("sinalib/utils.php");
Mysql_close ($conn);
function Redirect_to_login ($appid, $callback)
{
Echo $appid;
$redirect = "Https://api.weibo.com/oauth2/authorize". response_type=code&client_id= $appid &redirect_uri= ". $callback;
Header ("Location: $redirect");
}
Redirect_to_login ($sinaappid, "return address");
?>
sinaacc.php
<?php
Require_once ("sinalib/utils.php");
function Redirect_to_acc ($appid, $secret, $code, $callback) {
$url = "Https://api.weibo.com/oauth2/access_token";
$data = "client_id= $appid &client_secret= $secret &code= $code &grant_type=authorization_code& Redirect_uri= ". Rawurlencode ($callback);
$access =do_call ($url, $data);
$arr =json_decode ($access, true);
Print_r ($arr);
$access _token= $arr [' Access_token '];
echo $access _token. " Sina authorized success, each authorization can be 24 hours, beyond the time limit, please authorize ";"
}
REDIRECT_TO_ACC ($sinaappid, $sinaappkey, $_get[' code '], "return address");
?>
sinalib/utils.php
<?php
Error_reporting (E_all | | ~e_notice);
$sinaappid = "AppID to apply";
$sinaappkey = "key to apply"; function Do_post ($url, $postdata)
{
http
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_returntransfer, TRUE);
curl_setopt ($ch, Curlopt_post, TRUE);
curl_setopt ($ch, Curlopt_postfields, $postdata);
curl_setopt ($ch, Curlopt_url, $url);
$ret =curl_exec ($ch);
Curl_close ($ch);
return $ret;
}
function Do_call ($url, $postdata)
{
Https
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_returntransfer, TRUE);
curl_setopt ($ch, Curlopt_post, TRUE);
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
curl_setopt ($ch, Curlopt_ssl_verifyhost, false);
curl_setopt ($ch, Curlopt_postfields, $postdata);
curl_setopt ($ch, Curlopt_url, $url);
$ret =curl_exec ($ch);
Curl_close ($ch);
return $ret;
}
function Get_arr ($data) {
$arr = Array ();
$tem =substr ($data, Strpos ($data, ' {'), $data. len-3);
$arr =json_decode ($tem, true);
return $arr;
}
function Getmyuri () {
Get current directory
$BASEURL = str_replace (' \ \ ', '/', dirname ($_server[' script_name '));
$baseUrl = Empty ($BASEURL)? '/': '/'. Trim ($BASEURL, '/'). ' /';
return $BASEURL;
}
?>