<!--#include file="../config.inc.asp"-->
<%
'///////////////////////////////////////////////////////////////////////////////
'//              UC-Client For ASP
'// 作    者:    舞者/LOVE
'// 技术支持:    QQ:48673641
'// 官方网站:    www.a8kk.com
'// 程序名称:    UC-Client For ASP
'// 单元名称:    uc.asp
'// 开始时间:    2010.01.05
'// 最后修改:    
'// 备    注:    接口主要处理页
'///////////////////////////////////////////////////////////////////////////////

Const API_DELETEUSER = 1		   '用户删除 API 接口开关
Const API_EDIT = 1		           '修改资料 API 接口开关
Const API_RENAMEUSER = 1		   '用户改名 API 接口开关
Const API_GETTAG = 0		       '获取标签 API 接口开关
Const API_SYNLOGIN = 1		       '同步登录 API 接口开关
Const API_REGISTER = 1		       '同步注册 API 接口开关
Const API_SYNLOGOUT = 1		       '同步登出 API 接口开关
Const API_UPDATEPW = 1		       '更改用户密码 开关
Const API_UPDATEBADWORDS = 1	   '更新关键字列表 开关
Const API_UPDATEHOSTS = 1		   '更新域名解析缓存 开关
Const API_UPDATEAPPS = 1		   '更新应用列表 开关
Const API_UPDATECLIENT = 1		   '更新客户端缓存 开关
Const API_UPDATECREDIT = 1		   '更新用户积分 开关
Const API_GETCREDITSETTINGS = 1	   '向 UCenter 提供积分设置 开关
Const API_GETCREDIT = 1		       '获取用户的某项积分 开关
Const API_UPDATECREDITSETTINGS = 1 '更新应用积分设置 开关

Const API_RETURN_SUCCEED = "1"
Const API_RETURN_FAILED = "-1"
Const API_RETURN_FORBIDDEN = "-2"

'验证部分，不用修改 开始
Dim tget, ttime, code, action
code = Request.QueryString("code")
code = uc_authcode(code,"DECODE",UC_KEY)
Set tget = parse_str(code)
If Len(code) < 5 Then
    echo "Invalid Request"
End If
ttime = tget("time")
If Not IsNumeric(ttime) Or ttime = "" Then
    echo "Invalid Request"
End If
ttime = DateAdd("s",ttime,"1970-01-01 08:00:00")
ttime = DateDiff("s",ttime,Now())
If CInt(ttime) > 60 Then
    echo "Authracation has expiried"
End If
'验证部分，不用修改 结束
action = tget("action")
Dim ids, uid, oldusername, newusername, username, password, orgpassword, salt, pass, questionid, answer, email
Select Case action
    Case "test"
        echo API_RETURN_SUCCEED
    Case "deleteuser"  '删除用户
        If API_DELETEUSER = 0 Then echo API_RETURN_FORBIDDEN
	    ids = tget("ids")  '此处获取多个ID。。
	    '处理方式
        echo API_RETURN_SUCCEED  '最后返回 成功
    Case "renameuser"  '重命名用户
        If API_RENAMEUSER = 0 Then echo API_RETURN_FORBIDDEN
	    uid = tget("uid")  '用户ID
	    oldusername = tget("oldusername")  '原用户名
	    newusername = tget("newusername")  '新用户名
	    '处理方式
        echo API_RETURN_SUCCEED  '最后返回 成功
    Case "updatepw"  '修改用户密码
        If API_UPDATEPW = 0 Then echo API_RETURN_FORBIDDEN
	    username = tget("username")  '用户名
		orgpassword = tget("orgpassword")  '未加密密码
	    password = tget("password")  '新密码
		salt = tget("salt")
	    '处理方式
        echo API_RETURN_SUCCEED  '最后返回 成功
    Case "synlogin"  '登录
        If API_SYNLOGIN = 0 Then echo API_RETURN_FORBIDDEN
		Response.Addheader "P3P","CP=""CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"""
        uid = tget("uid")  ' UID
        username = tget("username") '用户名
        password = tget("password") '密码   '已MD5
		pass = tget("pass") '密码
	    '处理方式
        echo API_RETURN_SUCCEED  '最后返回 成功
	Case "synlogout" '退出
        If API_SYNLOGOUT = 0 Then echo API_RETURN_FORBIDDEN
		Response.Addheader "P3P","CP=""CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"""
	    '处理方式
        echo API_RETURN_SUCCEED  '最后返回 成功
	Case "register" '注册
        If API_REGISTER = 0 Then echo API_RETURN_FORBIDDEN
		username = tget("username") '用户名
		password = tget("password") '密码
		email = tget("email") '邮箱
		questionid = tget("questionid") '安全问题
		answer = tget("answer") '安全答案
	    '处理方式
        echo API_RETURN_SUCCEED  '最后返回 成功
	Case "edit" '修改
        If API_EDIT = 0 Then echo API_RETURN_FORBIDDEN
		username = tget("username") '用户名
		oldpw = tget("oldpw") '旧密码
		newpw = tget("newpw") '新密码
		email = tget("email") '邮箱
	    '处理方式
        echo API_RETURN_SUCCEED  '最后返回 成功
    Case Else
        echo API_RETURN_SUCCEED
End Select
WriteToFile action&".txt", code


Function parse_str(str)
    Dim objData, aryData, i, aryT
    Set objData = Server.CreateObject("Scripting.Dictionary")
    aryData = Split(str,"&")
    For i = 0 To UBound(aryData)
        aryT = Split(aryData(i), "=")
        If UBound(aryT) > 0 Then
            objData.add aryT(0), aryT(1)
        Else
            objData.add aryT(0), ""
        End If
    Next
    Set parse_str = objData
    Set objData = Nothing
End Function

Sub echo(str)
    Response.write str
	response.End
End Sub

Function WriteToFile(fileName,Text)
    Dim Stream 
    Set Stream = Server.CreateObject("Adodb.stream")
    Stream.charset="utf-8"
    Stream.Type = 2
    Stream.Mode = 3
    Stream.open()
    Stream.WriteText(Text)
    Stream.SaveToFile Server.MapPath(fileName),2
    Stream.close()
    Set Stream = Nothing
End Function
%>