<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="qq_oauth.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><%=cf_name%> - QQ帐号登录</title>
</head>

<body>
<%
function getrnd(byval t0)
		randomize
		dim n1,n2,n3
		do while len(getrnd)<t0 '随机字符位数 
			n1=cstr(chrw((57-48)*rnd+48)) '0~9 
			n2=cstr(chrw((90-65)*rnd+65)) 'a~z 
			n3=cstr(chrw((122-97)*rnd+97)) 'a~z 
			getrnd=getrnd&n1&n2&n3 
		loop
end function

Set qc = New QqConnet
    CheckLogin=qc.CheckLogin()
	If CheckLogin=False Then
	   Response.Write("登录失败！")
	   Response.End()
	End If
	Session("Access_Token")=qc.GetAccess_Token()
    Session("Openid")=qc.Getopenid()
    UserInfo=qc.GetUserInfo()

    nickname=qc.GetUserName(UserInfo)(0)'QQ呢称
    sex=qc.GetUserName(UserInfo)(1)'性别
	figureurl_2=Replace(qc.GetUserName(UserInfo)(2),"\","")'空间头像
	figureurl_qq_2=Replace(qc.GetUserName(UserInfo)(3),"\","")'QQ头像
	if figureurl_qq_2="" then
	fig=figureurl_2
	else
	fig=figureurl_qq_2
	end if
	set qc=nothing

if session("Openid")<>"" then
  set rs=server.CreateObject("adodb.recordset")
  sql="select * from cw_user where qid='"&session("Openid")&"'"
  rs.open sql,conn,1,3
  if not rs.eof then
  session("user")=rs("user")
  session("userid")=rs("id")
  session("names")=rs("names")
  session("tel")=rs("tel")
  session("address")=rs("address")
  session("utype")=rs("type")
  jf=rs("jf")
  rs("pic")=fig
  rs.update
  Call Cw_jf("+",1)
  Call Cw_gr(jf)
  else
  u_user="CW_"&getrnd(5)
  rs.addnew
  rs("user")=u_user
  rs("qid")=session("Openid")
  rs("pic")=fig
  rs.update
  u_id=rs("id")
  session("user")=u_user
  session("userid")=u_id
  session("utype")=0
  end if  
  rs.close
  set rs=nothing  
  response.Redirect"Index.asp"
else
  response.Redirect"login.asp"
end if

call closes()
%>
</body>
</html>
