<!--#include file="com.asp"-->
<!--#include file="class.asp"-->
<%
Dim url,data,accdata,userinfo,openid
D_domain=split(split("http://"&LCase(Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("URL")),"http://")(1),"/qq")(0)
url="https://graph.qq.com/oauth2.0/token"
data="grant_type=authorization_code&client_id="+qqid+"&client_secret="+qqkey+"&code="+Request.QueryString("code")+"&state=200&redirect_uri=http://"+D_domain+"/qq/reg.asp"
accdata=GetBody(url,data)
'获取openid
openid=GetBody("https://graph.qq.com/oauth2.0/me",accdata)
accdata=MID(Trim(accdata),14,32)
openid=Getjson(openid,"openid")

url="https://graph.qq.com/user/get_user_info"
data="access_token="&accdata&"&openid="&openid&"&oauth_consumer_key="&qqid
info2=GetBody(url,data)
nickname=split(split(info2,"""nickname"": """)(1),"""")(0)

set rs=server.createobject("ADODB.Recordset")
	sql="select * from Member where M_qqid='"&openid&"'"
	rs.open sql,conn,1,1
	if not rs.eof then
	M_login=rs("M_login")
	M_id=rs("M_id")
session("M_login")=M_login
session("M_id")=M_id
session("M_pwd")=openid
Response.Write ("<script>{alert('欢迎回来！"&M_login&"');location.href = '../member/index.asp';}</script>")
response.End()
else
sql="Insert into member(M_login,M_pwd,M_email,M_qqid) values('Q_"&nickname&"','"&openid&"','@qq.com','"&openid&"')"
conn.execute(sql)
session("M_login")="Q_"&nickname
session("M_pwd")=openid

set rs=server.createobject("ADODB.Recordset")
	sql="select top 1 * from Member order by M_id desc"
	rs.open sql,conn,1,1
	if not rs.eof then
	session("M_id")=rs("M_id")
	end if
	rs.close
	set rs=nothing
Response.Write ("<script>{alert('登陆成功！Q_"&nickname&"，初始密码："&openid&"，请进入会员中心修改！');location.href = '../member/index.asp';}</script>")
response.End()
end if
	rs.close
	set rs=nothing
%>