为动易SiteWeaver加入QQ登录功能 打印本文 打印本文  关闭窗口 关闭窗口  
作者:gohwu  文章来源:本站原创  点击数  更新时间:2013/3/20 15:21:20  文章录入:gohwu  责任编辑:gohwu
 

PS: 很多朋友问 照着做还是有问题,不好意思,忘记告诉大家 数据库也要修改下的 对PE_User表增加三个字段 qq_openid 字符,qq_accessToken字符 IsLocked 逻辑,然后其他就是下面的操作了!

校园网综合平台采用了动易SiteWeaver Oblog DVBBS 三个系统,用户统一,为了方便大家的登录,加入了QQ捆绑帐号登录功能,具体方法如下:

第一步,打开http://connect.qq.com 申请自己的网站 记录下APPID
第二步,修改动易SiteWeaver程序js文件下checklogin.js中 ,你需要的登录样式 加入 <a href=\"http://openapi.qzone.qq.com/oauth/show?which=ConfirmPage&client_id=你的appid&response_type=token&scope=all&redirect_uri=你的返回网址\"><img src=\"../images/Connect_logo_6.png\" border=\"0\"></a>
第三部,新建两个文件 放在user文件夹
qqlogin.asp 代码如下:
<script type="text/javascript"
<script type="text/javascript">
if(QC.Login.check()){//如果已登录
QC.Login.getMe(function(openId, accessToken){
//alert(["当前登录用户的", "openId为:"+openId, "accessToken为:"+accessToken].join("\n"));
//alert(openId);
//document.cookie="qqlogin_openId=" +openId;
//document.cookie="qqlogin_accessToken=" +accessToken;
window.location.href="qqlogin1.asp?action=qqlogin&qq_AccessToken="+accessToken+"&qq_openId="+openId
});
//这里可以调用自己的保存接口
//document.getElementById("UserName").value=openId;
//document.getElementById("UserPassword").vAlign=accessToken
}
</script>
qqlogin1.asp
代码如下:
<!--#include file="../Start.asp"-->
<link href="../images/style.CSS" rel="stylesheet" type="text/css">
<script language=javascript>
function refreshimg(){
document.all.checkcode.src='../Inc/CheckCode.asp?'+Math.random();
}
function SetFocus()
{
if (document.Login.UserName.value=="")
document.Login.UserName.focus();
else
document.Login.UserName.select();
}
function CheckForm()
{
if(document.Login.UserName.value=="")
{
alert("请输入用户名!");
document.Login.UserName.focus();
return false;
}
if(document.Login.UserPassword.value == "")
{
alert("请输入密码!");
document.Login.UserPassword.focus();
return false;
}
}
</script>
<style type="text/css">
<!--
body {margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;}
-->
</style>
<%
action=request.QueryString("action")
if action="qqlogin" then
Dim qq_AccessToken,qq_openId,url,rs,sql,username1,password1,CheckCode1
qq_AccessToken=request.QueryString("qq_AccessToken")
qq_openId=request.QueryString("qq_openId")
'response.write "qq_AccessToken="&qq_AccessToken
'response.write "qq_openId="&qq_openId
'response.End()
If CheckUserLogined() = False Then
Set rs=server.CreateObject("Adodb.recordset")
sql="select * from PE_User where qq_openid='"&qq_openId&"'"
rs.open sql,conn,1,1
if rs.eof then
call bangding
else
username1=rs("UserName")
password1=rs("UserPassword")
CheckCode1=Session("CheckCode")
response.write "<script>location.href='User_ChkLogin.asp?UserName="&username1&"&UserPassword="&password1&"&CheckCode="&CheckCode1&"&tt=qqlogin1';</script>"
end if
rs.close
set rs=nothing
set sql=nothing
else
Conn.Execute ("update PE_User set qq_openid='" & qq_openId & "',qq_accessToken='" & qq_AccessToken & "' where UserID=" & Session("UserID")& "")
response.write "<script>parent.window.location.href='index.asp'</script>"
end if
end if
if action="bangding" then
Response.Write "<html><head><title>绑定QQ帐号</title><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbCrLf
Response.Write "<link href='../Images/style.css' rel='stylesheet' type='text/css'></head><body>" & vbCrLf
Response.Write "<table cellpadding=2 cellspacing=1 border=0 width=400 class='border' align=center>" & vbCrLf
Response.Write " <tr align='center'><td height='22' class='title'><strong>绑定QQ帐号</strong></td></tr>" & vbCrLf
Response.Write " <tr><td height='100' class='tdbg' ><p align=center><a href='http://openapi.qzone.qq.com/oauth/show?which=ConfirmPage&client_id=你的APIID&response_type=token&scope=all&redirect_uri=http%3A%2F%2F你的网址%2Fuser%2Fqqlogin.asp'><img src='../qqlogin/qq_login.gif' border='0'></a></p>"& vbCrLf
Response.Write "</td></tr>" & vbCrLf
Response.Write "</table></form>" & vbCrLf
Response.Write "</body></html>" & vbCrLf
end if
if action="quxiao" then
'userid=request.QueryString("userid")
Conn.Execute ("update PE_User set qq_openid=null,qq_accessToken=null where UserID=" & Session("UserID") & "")
response.write "<script>parent.window.location.href='index.asp'</script>"
end if
Sub bangding()
Response.Write "<html><head><title>绑定网站帐号</title><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbCrLf
Response.Write "<link href='../Images/style.css' rel='stylesheet' type='text/css'></head><body>" & vbCrLf
Response.write "<form name='Login' action='User_ChkLogin.asp?tt=qqlogin' method='post' onSubmit='return CheckForm();'>"
Response.Write "<table cellpadding=2 cellspacing=1 border=0 width=400 class='border' align=center>" & vbCrLf
Response.Write " <tr align='center'><td height='22' class='title'><strong>网站帐号登录</strong></td></tr>" & vbCrLf
Response.Write " <tr><td height='100' class='tdbg' ><p>用户名:<input name='UserName' type='text' id='UserName' maxlength='20'></p>"& vbCrLf
Response.Write "<p>密&nbsp;&nbsp;码:<input name='UserPassword' type='password' id='UserPassword' maxlength='20'></p>"& vbCrLf
If EnableCheckCodeOfLogin = True then
Response.write "<p>验证码:<input name='CheckCode' size='6' maxlength='6'><a href='javascript:refreshimg()' title='看不清楚,换个图片'><img id='checkcode' src='../Inc/CheckCode.asp' style='border: 1px solid #ffffff' /></a></p>"& vbCrLf
End IF
Response.write "<input name='qq_AccessToken' type='hidden' value='"&qq_AccessToken&"' /><input name='qq_openId' type='hidden' value='"&qq_openId&"' />"
Response.Write "</td></tr>" & vbCrLf
Response.Write " <tr align='center'><td class='tdbg'><input name='buttom1' type='submit' value='绑定帐号' /></td></tr>" & vbCrLf
Response.Write "</table></form>" & vbCrLf
Response.Write "</body></html>" & vbCrLf
End Sub
%>
修改动易SiteWeaver程序中USER文件夹中的User_ChkLogin.asp文件,具体如下:
在开始
Dim CookieDate
Dim UserPassword, RndPassword, CheckCode
下面增加如下代码:
Dim qq_login,qq_AccessToken,qq_openId'2012年9月22加入QQ登录
qq_login=request.QueryString("tt")
if qq_login="qqlogin" then
qq_AccessToken=request.Form("qq_AccessToken")
qq_openId=request.Form("qq_openId")
end if
第二处 找到Set rs = Conn.Execute("select UserID,UserName,UserPassword,LastPresentTime,LastPresentTime,IsLocked from PE_User where UserName='" & UserName & "'")
修改为
Set rs = Conn.Execute("select UserID,UserName,UserPassword,LastPresentTime,LastPresentTime,IsLocked,qq_openID from PE_User where UserName='" & UserName & "'")
第三处 找到
Response.Cookies(Site_Sn)("UserName") = UserName
Response.Cookies(Site_Sn)("UserPassword") = UserPassword
Response.Cookies(Site_Sn)("LastPassword") = RndPassword
Response.Cookies(Site_Sn)("CookieDate") = CookieDate
在下面增加
'QQ登录 绑定到用户
if IsNull(rs("qq_openid")) then
'response.write qq_openId
Conn.Execute ("update PE_User set qq_openid='" & qq_openId & "',qq_accessToken='" & qq_AccessToken & "' where UserID=" & rs("UserID") & "")
end if
End If
至此 在需要增加登录的地方增加js 登录调用,就可以使用QQ登录了。具体的请参考QQ登录开发API说明。