<!--#include file="com.asp"-->
<!--#include file="class.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<title>会员登陆</title>
<meta charset="utf-8" />
<meta content="width=device-width, initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=yes" name="format-detection" />
<meta content="email=no" name="format-detection" />
<meta name="keywords" content=""  />
<meta name="description" content="" />

</head>
<body >
<%
if session("from")="" then
from="../member/index.asp"
else
from=session("from")
end if
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=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)
figureurl_qq_2=split(split(info2,"""figureurl_qq_2"": """)(1),"""")(0)
if nickname="" then
call box("授权失败，请重新登录！","../member/member_login.asp","error")
else
set rs=server.createobject("ADODB.Recordset")
	sql="select * from SL_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
call box("欢迎回来！"&M_login,URLdecode(from),"success")
else
sql="insert into SL_member(M_login,M_pwd,M_email,M_fen,M_pic,M_regtime,M_qqid) values('Q_"&nickname&"','"&openid&"','@qq.com',0,'"&replace(figureurl_qq_2,"\","")&"','"&now()&"','"&openid&"')"
conn.execute(sql)
session("M_login")="Q_"&nickname
session("M_pwd")=openid
set rs=server.createobject("ADODB.Recordset")
	sql="select top 1 * from SL_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
call box("登陆成功！Q_"&nickname,URLdecode(from),"success")
end if
	rs.close
	set rs=nothing
end if

%>
</body>
</html>