<!--#include file="UC_Config.asp"-->
<%

Function uc_api_post(module,action,arg)
	dim s,postdata
	s = arg
	postdata = uc_api_requestdata(module,action,s,"")
	uc_api_post =  uc_fopen2(UC_API & "/index.php", 500000, postdata, "", true, UC_IP, 20,true)
End Function
Function uc_api_post2(module,action,arg)
	Dim mystr, j
	mystr = ""
	If IsArray(arg) Then
		For j = 0 To UBound(arg) Step 1
			mystr = mystr & arg(j) & "&"
		Next
	End If
	postdata = uc_api_requestdata(module,action,mystr,"")
	uc_api_post2 =  uc_fopen2(UC_API & "/index.php", 500000, postdata, "", true, UC_IP, 20,true)
End Function
'同步登陆
Function uc_user_synlogin(uid)
    uc_user_synlogin = uc_api_post("user", "synlogin", "uid="&uid)
End Function
'登陆
Function uc_user_login(user,pwd)
	If user = "" Or pwd = "" Then uc_user_login = Array(-4, 0, 0, 0, 0) : Exit Function
	If isuid = "1" Then isuid = "1" Else isuid = "0"
    Dim mystr, str, uid, email, name
    mystr = Array("username=" & SURLEncode(user), "password=" & pwd, "isuid=" & isuid, "checkques=0", "questionid=", "answer=")
	uc_user_login = uc_api_post2("user", "login", mystr)
	'uc_user_login = uc_api_post("user","login","username="&user&"&password="&pwd&"&isuid=0&checkques=0&questionid=&answer=")
End Function 
'同步退出
Function uc_user_synlogout()
	uc_user_synlogout = uc_api_post("user","synlogout","uid=0")
End Function 
'修改用户资料
Function uc_user_edit(username , oldpw , newpw , email ,ignoreoldpw, questionid,answer)
	'uc_user_edit = uc_api_post("user","edit","username="&username&"&newpw="&newpw&"&oldpw="&oldpw&"&email="&email&"&questionid="&questionid&"&answer="&answer&"&ignoreoldpw="&ignoreoldpw)
	Dim str, mystr
	mystr = Array("username=" & SURLEncode(username), "oldpw=" & oldpw, "newpw=" & newpw, "email=" & email, "ignoreoldpw=" & ignoreoldpw, "questionid=" & SURLEncode(questionid), "answer=" & SURLEncode(answer))
	uc_user_edit = uc_api_post2("user", "edit", mystr)
End Function 
'用户注册
Function uc_user_register(user,pwd,email)
	uc_user_register = uc_api_post("user","register","username="&user&"&password="&pwd&"&email="&email&"&questionid=&answer=&regip=")
End Function 
'删除用户
function uc_user_delete(username)
	uc_user_delete = uc_api_post("user","delete","username="&username)
end function
'修改头像
Function uc_avatar(uid,stype)
	uid = CInt(uid)	
	input = uc_api_input("uid="&uid)
	uc_avatarflash = UC_API&"/images/camera.swf?inajax=1&appid="&UC_APPID&"&input="&input&"&agent="&Php_MD5(Request.ServerVariables ("HTTP_USER_AGENT"))&"&ucapi="&Server.URLEncode(replace(UC_API,"http://", ""))&"&avatartype="&stype&"&uploadSize=2048"
	uc_avatar="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='450' height='253' id='mycamera' align='middle'><param name='allowScriptAccess' value='always' /><param name='scale' value='exactfit' /><param name='wmode' value='transparent' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><param name='movie' value='"&uc_avatarflash&"' /><param name='menu' value='false' /><embed src='"&uc_avatarflash&"' quality='high' bgcolor='#ffffff' width='450' height='253' name='mycamera' align='middle' allowScriptAccess='always' allowFullScreen='false' scale='exactfit'  wmode='transparent' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>"
End Function 

Function uc_api_requestdata(module,action,arg,extra)
	dim input
	input = uc_api_input(arg)
	uc_api_requestdata = "m="&module&"&a="&action&"&inajax=2&input="&input&"&appid="&UC_APPID&extra
End Function

Function uc_api_input(data)
	uc_api_input = Server.URLEncode(uc_authcode(data&"&agent="&Php_MD5(Request.ServerVariables ("HTTP_USER_AGENT"))&"&time="&php_time(), "ENCODE", UC_KEY))
End Function

Function uc_fopen(url, limit, post, cookie, bysocket, ip, stimeout, block)
	dim objXmlHttp
	set objXmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
	objXmlHttp.open "post",url,False
	objXmlHttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
    objXmlHttp.setRequestHeader "Accept", "*/*"   
    objXmlHttp.setRequestHeader "Accept-Language","zh-cn"   
    objXmlHttp.setRequestHeader "User-Agent", Request.ServerVariables("HTTP_USER_AGENT")    
    objXmlHttp.setRequestHeader "Connection","Close"   
    objXmlHttp.setRequestHeader "Cache-Control","no-cache"   	
	objXmlHttp.send(post)
	Dim binFileData
	binFileData = objXmlHttp.responseBody
	Dim ObjStream
	Set ObjStream = CreateObject("Adodb.Stream")
	With ObjStream
		.Type = 1
		.Mode = 3
		.Open
		.write binFileData
		.Position = 0
		.Type = 2
		.Charset = "utf-8"
		s = .ReadText
		.Close
	End With
	Set ObjStream = Nothing
	uc_fopen = s
End function


function uc_fopen2(url, limit, post, cookie,bysocket, ip , stimeout, block)
	Dim times
	if request("__times__")<>"" Then
		times = Cint(request("__times__")) + 1
	Else
		times =  1
	End If
	if times > 2 Then
		uc_fopen2 = ""
	End If
	If instr(url,"?")>0 Then
		url = url & "&__times__=" & times
	Else
		url = url & "?__times__=" & times
	End If
	uc_fopen2 = uc_fopen(url, limit, post, cookie, bysocket, ip, stimeout, block)
End Function

Function xml2array(xmldoc)
	Dim objdoc
	set objdoc=Server.CreateObject("msxml2.FreeThreadedDOMDocument.3.0")
	objdoc.async = false
	objdoc.LoadXml(xmldoc)
	Dim objNodeList
	Dim Counters(14)
	set objNodeList = objdoc.selectSingleNode("//root").childNodes
	For i = 0 To (objNodeList.length - 1)
		Counters(i)= objNodeList.Item(i).text
	Next
	xml2array = Counters
End Function 

Function loadxml(code)
    Dim xml, objNodem, i, objNode, nCntChd
    Set xml = Server.CreateObject("Microsoft.XMLDOM")
    xml.async = False
    xml.loadxml code
	If xml.parseError.errorCode <> 0 Then
        loadxml = Split("-99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",",")
		Exit Function
	End If
    Set objNode = xml.documentElement 
    nCntChd = objNode.ChildNodes.length - 1 
    For i = 0 To nCntChd 
        loadxml = loadxml & urldecode(xml.documentElement.childNodes(i).text) & ","
    Next
    loadxml = Left(loadxml,Len(loadxml)-1)
    Set xml = Nothing
	loadxml = Split(loadxml,",")
End Function

'================================================
'函数名: SURLEncode
'作  用: URLEncode编码
'参  数: word  : 字符串
'返回值: 编码
'================================================
Function SURLEncode(word)
    If Left(UC_DBCHARSET,3) = "utf" Or UC_DBCHARSET = "65001" Then
	    Session.CodePage = 65001
	Else
	    Session.CodePage = 936
	End If
    SURLEncode = Server.URLEncode(Trim(word))
    If Left(API_DBCHARSET,3) = "utf" Or API_DBCHARSET = "65001" Then
	    Session.CodePage = 65001
	Else
	    Session.CodePage = 936
	End If
End Function

'================================================
'函数名: urldecode
'作  用: URLEncode解码
'参  数: encodestr  : 字符串
'返回值: 解码
'================================================
Function urldecode(encodestr) 
   Dim newstr, havechar, lastchar, i, char_c, next_1_c, next_1_Num
   newstr = "" 
   havechar = False
   lastchar = "" 
   For i = 1 To Len(encodestr) 
      char_c = Mid(encodestr,i,1) 
      If char_c = "+" Then
         newstr = newstr & " "
      ElseIf char_c = "%" Then
         next_1_c = Mid(encodestr,i+1,2) 
         next_1_num = CInt("&H" & next_1_c) 
         If havechar Then
            havechar = False
            newstr = newstr & Chr(CInt("&H" & lastchar & next_1_c)) 
         Else
            If abs(next_1_num) <= 127 Then
               newstr = newstr & Chr(next_1_num) 
            Else
               havechar = True
               lastchar = next_1_c 
            End If
         End If
         i = i + 2 
      Else
         newstr = newstr & char_c 
      End If
   Next
   urldecode = newstr 
End Function
%>