<!--#include file="../p_inc/config.asp"-->
<!--#include file="../inc/config.asp"-->
<!--#include file="jo.asp"-->
<!--#include file="smart.1.asp"-->
<!--#include file="sha1.asp"-->
<%
response.Charset="utf-8"
url_get_noauth = "http://openapi.qzone.qq.com/user/get_user_info"
set table = jo.HashTable()
table.add "oauth_consumer_key",appid  
table.add "oauth_nonce",int(rnd * 1000000000)
table.add "oauth_timestamp",utc()/1000-8*3600
table.add "oauth_version","1.0"  
table.add "oauth_signature_method","HMAC-SHA1"
table.add "oauth_token",session("oauth_token")
table.add "openid",session("openid")
table.add "format","json"
table.sort "asc","key"

'获取待签名字符串和密钥
oauth_signature="GET" & "&" & utf8(url_get_noauth) & "&" & utf8(table.URIString("no"))
seckey = appkey & "&" & session("oauth_token_secret")

'计算签名
oauth_signature = b64_hmac_sha1(seckey,oauth_signature)
table.add "oauth_signature",oauth_signature

'发送请求
set http = SmartHttp(url_get_noauth & "?" & table.URIString("utf-8"))
http.autoClearBuffer = false
varresult = http.send().gettext("utf-8")

set userinfo = jo.HashTable()
userinfo.FromJson varresult
if not userinfo.Exists("nickname") then
	response.Write "登录失败，错误信息：" & userinfo.Items("msg")
	response.End()
end if
fpath = "userhead/" & session("openid") & ".jpg"
if not jo.fso(server.MapPath(fpath)).FileExists() then
	figureurl = userinfo.Items("figureurl")
	if userinfo.Exists("figureurl_1") then figureurl = userinfo.Items("figureurl_1")
	if userinfo.Exists("figureurl_2") then figureurl = userinfo.Items("figureurl_2")
	SmartHttp(figureurl).saveToFile(server.MapPath(fpath))
end if
session("nickname") = userinfo.Items("nickname")

If session("openid")<>"" Then
qqid =session("openid")
fphoto="qqlogin/" & fpath
nickname =userinfo.Items("nickname")
Dim Conn,dbpath
Set conn=Server.CreateObject("Adodb.Connection")
Set s_u_n_a_m_e=server.CreateObject("ADODB.Recordset")
		ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db) & ";Persist Security Info=False"
conn.open connstr
	zsoojs_u_name=UTF2GB(nickname)
	soojs_u_email=zsoojs_u_name&"@qq.com"
		Sql="select * from soojs_un where soojs_u_name='"&zsoojs_u_name&"' or soojs_u_email='"&zsoojs_u_email&"'"
	s_u_n_a_m_e.open Sql,Conn,1,3
		IF not (s_u_n_a_m_e.Bof and s_u_n_a_m_e.eof) Then
Set rs_u=server.CreateObject("adodb.recordset")
		Set rs_u=conn.execute("select soojs_u_name,soojs_lastip,soojs_lastdate,soojs_jifen,soojs_thisdate,soojs_level,id,soojs_u_email,soojs_u_f1 from soojs_un where (soojs_u_name='"&zsoojs_u_name&"' or soojs_u_email='"&zsoojs_u_email&"') and qqid='" & qqid & "'")
			response.Cookies(G_u_Cookies)("soojs_u")=escape(zsoojs_u_name)
			response.Cookies(G_u_Cookies)("soojs_jifen")=rs_u("soojs_jifen")
			response.Cookies(G_u_Cookies)("soojs_id")=rs_u("id")
			response.Cookies(G_u_Cookies)("soojs_lastdate")=rs_u("soojs_lastdate")
			response.Cookies(G_u_Cookies)("soojs_lastip")=rs_u("soojs_lastip")
			response.Cookies(G_u_Cookies)("soojs_u_email")=zsoojs_u_email	
			'response.Cookies(G_u_Cookies+"_a")=rs_u("id")
			'Response.Cookies(G_u_Cookies+"_a").expires=now()+100
			Response.Cookies(G_u_Cookies).expires=now()+100
			response.Cookies("soojsjj")="0"
			response.Cookies(G_u_Cookies)("soojs_u_pic")=escape(fphoto)
			response.redirect "../"	
		

		Else
		s_u_n_a_m_e.addnew
		s_u_n_a_m_e("soojs_u_name")=zsoojs_u_name
		s_u_n_a_m_e("soojs_u_pass")=qqid
		s_u_n_a_m_e("soojs_uu_name")=zsoojs_u_name
		s_u_n_a_m_e("soojs_u_ask")=""
		s_u_n_a_m_e("soojs_u_ok")=""
		s_u_n_a_m_e("soojs_u_tel")=""
		s_u_n_a_m_e("soojs_u_qq")=""
		s_u_n_a_m_e("soojs_u_email")=zsoojs_u_email
		s_u_n_a_m_e("soojs_u_addr")=""			
		s_u_n_a_m_e("soojs_u_content")=""									
		s_u_n_a_m_e("soojs_date")=FormatDate(now,55)'注册时间
		s_u_n_a_m_e("soojs_thisdate")=FormatDate(now,55)'注册时间	
		s_u_n_a_m_e("soojs_lastdate")=FormatDate(now,55)'注册时间					
		s_u_n_a_m_e("soojs_ip")=getIP()
		s_u_n_a_m_e("soojs_thisip")=getIP()	
		s_u_n_a_m_e("soojs_lastip")=getIP()	
		s_u_n_a_m_e("soojs_level")=0
		s_u_n_a_m_e("soojs_u_pic")=fphoto
		IF G_zhuce_j2="" Then
			s_u_n_a_m_e("soojs_jifen")=0	
		Else
			s_u_n_a_m_e("soojs_jifen")=G_zhuce_j2
		End IF		
		s_u_n_a_m_e("soojs_sex")=0
		s_u_n_a_m_e("soojs_u_card")=""
		s_u_n_a_m_e("soojs_u_msn")=""
		s_u_n_a_m_e("soojs_u_birth")="1980-01-01"
		s_u_n_a_m_e("soojs_u_Province")=""
		s_u_n_a_m_e("soojs_u_City")=""
		s_u_n_a_m_e("soojs_status")=0
		s_u_n_a_m_e("soojs_u_code")=""
		s_u_n_a_m_e("soojs_u_tuiguang")=""
		s_u_n_a_m_e("soojs_1616_manager")="3,8,9,10,11,12,13,14,16,18,7,25"
		s_u_n_a_m_e("soojs_1616_manager")=""
		s_u_n_a_m_e("soojs_jifen_G_jifen_s_f_1")=""
		s_u_n_a_m_e("soojs_jifen_G_jifen_s_f_today")=0
		s_u_n_a_m_e("qqid")=qqid
		s_u_n_a_m_e.update
	End IF	
	s_u_n_a_m_e.close
Set rs_u=server.CreateObject("adodb.recordset")
		Set rs_u=conn.execute("select soojs_u_name,soojs_lastip,soojs_lastdate,soojs_jifen,soojs_thisdate,soojs_level,id,soojs_u_email,soojs_u_f1 from soojs_un where (soojs_u_name='"&zsoojs_u_name&"' or soojs_u_email='"&zsoojs_u_email&"') and soojs_u_pass='" & qqid & "'")
			response.Cookies(G_u_Cookies)("soojs_u")=escape(zsoojs_u_name)
			response.Cookies(G_u_Cookies)("soojs_jifen")=rs_u("soojs_jifen")
			response.Cookies(G_u_Cookies)("soojs_id")=rs_u("id")
			response.Cookies(G_u_Cookies)("soojs_lastdate")=rs_u("soojs_lastdate")
			response.Cookies(G_u_Cookies)("soojs_lastip")=rs_u("soojs_lastip")
			response.Cookies(G_u_Cookies)("soojs_u_email")=zsoojs_u_email	
			'response.Cookies(G_u_Cookies+"_a")=rs_u("id")
			'Response.Cookies(G_u_Cookies+"_a").expires=now()+100
			Response.Cookies(G_u_Cookies).expires=now()+100
			response.Cookies("soojsjj")="0"
			response.Cookies(G_u_Cookies)("soojs_u_pic")=escape(fphoto)
			response.redirect "../"	
Else
	Response.Write("登录失败")
End If
Function getIP()
    Dim strIPAddr
    If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
        strIPAddr = Request.ServerVariables("REMOTE_ADDR")
    ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
        strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
    ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
        strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
    Else
        strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    End If
    getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
Function FormatDate(DT,tp)
	dim Y,M,D,hour_,minute_,second_
	Y=Year(DT)
	M=month(DT)
	D=Day(DT)
	hour_=hour(DT)
	minute_=minute(DT)
	second_=second(DT)
	if M<10 then M="0"&M
	if D<10 then D="0"&D
	if hour_<10 then hour_="0"&hour_
	if minute_<10 then minute_="0"&minute_
	if second_<10 then second_="0"&second_
	select case tp
	case 1 FormatDate=Y&"年"&M&"月"&D&"日"
	case 2 FormatDate=Y&"/"&M&"/"&D
	case 3 FormatDate=M&"/"&D
    case 4 FormatDate=Y&"\"&M&"\"&D
    case 5 FormatDate=Y&"-"&M&"-"&D
	case 6 FormatDate=M&"-"&D
	case 11 FormatDate=Y&"年"&M&"月"&D&"日"&" "&hour_&"时"&minute_&"分"&second_&"秒"
	case 22 FormatDate=Y&"/"&M&"/"&D&" "&hour_&"/"&minute_&"/"&second_
	case 44 FormatDate=Y&"\"&M&"\"&D&" "&hour_&"\"&minute_&"\"&second_
	case 55 FormatDate=Y&"-"&M&"-"&D&" "&hour_&":"&minute_&":"&second_
	case 66 FormatDate=right(Y,2)&"-"&M&"-"&D&" "&hour_&":"&minute_&":"&second_	
	case 77 FormatDate=M&"-"&D&" "&hour_&":"&minute_&":"&second_	
	case 88 FormatDate=hour_&":"&minute_&":"&second_
	case 666 FormatDate=M&"-"&D&" "&hour_&":"&minute_	
	case 555 FormatDate=Y&"-"&M&"-"&D&" "&hour_
	case 5555 FormatDate=Y&"-"&M&"-"&D&" "&hour_&":"&minute_
	Case Else FormatDate=Y&"-"&M&"-"&D
	end select
End Function
Function UTF2GB(UTFStr)
    For Dig=1 to len(UTFStr)
        if mid(UTFStr,Dig,1)="%" then
            if len(UTFStr) >= Dig+8 then
                GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
                Dig=Dig+8
            else
                GBStr=GBStr & mid(UTFStr,Dig,1)
            end if
        else
            GBStr=GBStr & mid(UTFStr,Dig,1)
        end if
    Next
    UTF2GB=GBStr
End Function
%>