微博第三方登陆js实现
html页面代码:
<meta charset="utf-8">
<meta property="wb:webmaster" content="2e1bcfc697808c9f" />
<html xmlns:wb="http://open.weibo.com/wb">
<script src="http://tjs.sjs.sinajs.cn/open/api/js/wb.js?appkey=4116105834&debug=true" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
WB2.anyWhere(function (W) {
W.widget.connectButton({
id: "wb_connect_btn",
type: ‘3,2‘,
callback: {
login: function (o) { //登录后的回调函数
//alert("login: " + o.screen_name) location screen_name id
var ajax = new XMLHttpRequest();
ajax.onreadystatechange=function(){
if (ajax.readyState==4){
//接收数据
alert(ajax.responseText);
//history.go(0);
//document.getElementById("sppwd").innerHTML = ajax.responseText;
}
}
//与服务器建立连接
ajax.open("get","sinaadd.php?oid="+o.id+"&screen_name="+o.screen_name+"&location="+o.location);
//处理请求
ajax.send(null);
},
logout: function () { //退出后的回调函数
alert(‘logout‘);
}
}
});
});
</script>
<div id="wb_connect_btn"></div>
</html>
php页面代码:
<?php
$uid=$_GET[‘oid‘];
$screen_name=$_GET[‘screen_name‘];
$location=$_GET[‘location‘];
$db = new PDO("mysql:host=blog.bwphp.cn;dbname=wangbao","wangbao", "1234",array(PDO::MYSQL_ATTR_INIT_COMMAND => ‘SET NAMES \‘utf8\‘‘));
$db->query("set names utf8");
$addsql = "insert into sina_oauth(uid,screen_name,location) values(‘$uid‘,‘$screen_name‘,‘$location‘)";
$add = $db->exec($addsql);
if($add){
echo "用户信息以成功入库";
}else{
$db->errorInfo();
}
?>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。