<%
'///////////////////////////////////////////////////////////////////////////////
'//              UC-Client For ASP
'// 作    者:    舞者/LOVE
'// 技术支持:    QQ:48673641
'// 官方网站:    www.a8kk.com
'// 程序名称:    UC-Client For ASP
'// 单元名称:    client.asp
'// 开始时间:    2010.01.05
'// 最后修改:    
'// 备    注:    ASP-Client主要函数
'///////////////////////////////////////////////////////////////////////////////

'================================================用户接口 开始================================================
'================================================
'函数名: uc_user_register
'作  用: 用户注册
'参  数: username   : 用户名
'        password   : 密码
'        email      : Email
'        questionid : 安全提问
'        answer     : 安全提问答案
'返回值: -1 : 用户名不合法
'        -2 : 包含不允许注册的词语
'        -3 : 用户名已经存在
'        -4 : email 格式有误
'        -5 : email 不允许注册
'        -6 : 该 email 已经被注册
'        -7 : 注册信息不全
'        >1 : 表示成功，数值为 UID
'================================================
Function uc_user_register(username, password, email, questionid, answer)
    Dim mystr
	If username = "" Or password = "" Or email = "" Then uc_user_register = "-7" : Exit Function
    mystr = Array("username=" & SURLEncode(username), "password=" & password, "email=" & email, "questionid=" & SURLEncode(questionid), "answer=" & SURLEncode(answer))
	uc_user_register = uc_api_post("user", "register", mystr)
End Function

'================================================
'函数名: uc_user_registerapi
'作  用: 用户注册2
'参  数: username   : 用户名
'        password   : 密码
'        email      : Email
'        questionid : 安全提问
'        answer     : 安全提问答案
'返回值: 同步注册HTML代码
'================================================
Function uc_user_registerapi(username, password, email, questionid, answer)
    Dim mystr
	If username = "" Or password = "" Or email = "" Then uc_user_register = "-7" : Exit Function
    mystr = Array("username=" & SURLEncode(username), "password=" & password, "email=" & email, "questionid=" & SURLEncode(questionid), "answer=" & SURLEncode(answer))
	uc_user_registerapi = uc_api_post("user", "registerapi", mystr)
End Function

'================================================
'函数名: uc_user_login
'作  用: 用户登陆检查
'参  数: username	: 用户名/uid
'        password	: 密码
'        isuid		: 是否为uid   默认 0
'        checkques	: 是否使用检查安全问答 默认 0
'        questionid	: 安全提问
'        answer 	: 安全提问答案
'返回值: Array(uid, 用户名, 密码, Email,用户名是否重名)
'        uid: 
'           大于 0 : 返回用户 ID，表示用户登录成功
'           -1 : 用户不存在，或者被删除
'           -2 : 密码错
'           -3 : 安全提问错
'           -4 : 用户或密码为空
'================================================
Function uc_user_login(username, password, isuid, checkques, questionid, answer)
    If username = "" Or password = "" Then uc_user_login = Array(-4, 0, 0, 0, 0) : Exit Function
	If isuid = "1" Then isuid = "1" Else isuid = "0"
	If checkques = "1" Then checkques = "1" Else checkques = "0"
    Dim mystr, str, uid, email, name
    mystr = Array("username=" & SURLEncode(username), "password=" & password, "isuid=" & isuid, "checkques=" & checkques, "questionid=" & SURLEncode(questionid), "answer=" & SURLEncode(answer))
	str = uc_api_post("user", "login", mystr)
	uc_user_login = loadxml(str)
End Function

'================================================
'函数名: uc_get_user
'作  用: 获取用户数据
'参  数: username	: 用户名/uid
'        isuid		: 是否为uid   默认 0
'返回值: Array(uid, 用户名, Email)
'================================================
Function uc_get_user(username, isuid)
    If username = "" Then uc_get_user = Array(0, 0, 0) : Exit Function
	If isuid = "1" Then isuid = "1" Else isuid = "0"
	Dim str, uid, email
	str = uc_api_post("user","get_user",Array("username=" & SURLEncode(username), "isuid=" & isuid))
    If Len(str) < 10 Then uc_get_user = Array(0, 0, 0) : Exit Function
	uc_get_user = loadxml(str)
End Function

'================================================
'函数名: uc_user_edit
'作  用: 编辑用户
'参  数: username  : 用户名
'        oldpw	   : 旧密码
'        newpw	   : 新密码
'        email	   : Email
'        ignoreoldpw  : 是否忽略旧密码, 忽略旧密码, 则不进行旧密码校验.  默认0
'        questionid	: 安全提问
'        answer    :安全提问答案
'返回值: 1  : 修改成功
'        0  : 没有任何修改
'       -1  : 旧密码不正确
'       -4  : email 格式有误
'       -5  : email 不允许注册
'       -6  : 该 email 已经被注册
'       -7  : 没有做任何修改
'       -8  : 受保护的用户，没有权限修改
'================================================
Function uc_user_edit(username, oldpw, newpw, email, ignoreoldpw, questionid, answer)
	If ignoreoldpw = 1 Then ignoreoldpw = 1 Else ignoreoldpw = 0
	If username = "" Or oldpw = "" Then uc_user_edit = -7 : Exit Function
    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_post("user", "edit", mystr)
End Function

'================================================
'函数名: uc_user_editapi
'作  用: 编辑用户2
'参  数: username  : 用户名
'        oldpw	   : 旧密码
'        newpw	   : 新密码
'        email	   : Email
'        ignoreoldpw  : 是否忽略旧密码, 忽略旧密码, 则不进行旧密码校验.  默认0
'        questionid	: 安全提问
'        answer    :安全提问答案
'返回值: 同步修改的HTML代码
'================================================
Function uc_user_editapi(username, oldpw, newpw, email, ignoreoldpw, questionid, answer)
	If ignoreoldpw = 1 Then ignoreoldpw = 1 Else ignoreoldpw = 0
	If username = "" Or oldpw = "" Then uc_user_edit = -7 : Exit Function
    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_post("user", "editapi", mystr)
End Function
'================================================
'函数名: uc_user_delete
'作  用: 删除用户
'参  数: uid : 用户ID
'返回值: 1 : 成功
'        0 : 失败
'================================================
Function uc_user_delete(uid)
    If Not IsNumeric(uid) Then uc_user_delete = 0 : Exit Function
	uc_user_delete = uc_api_post("user", "delete", Array("uid=" & uid))
End Function

'================================================
'函数名: uc_user_deleteavatar
'作  用: 删除用户头像
'参  数: uid : 用户ID
'返回值: 1 : 成功
'        0 : 失败
'================================================
Function uc_user_deleteavatar(uid)
    If Not IsNumeric(uid) Then uc_user_deleteavatar = 0 : Exit Function
	uc_user_deleteavatar = uc_api_post("user", "deleteavatar", Array("uid=" & uid))
End Function

'================================================
'函数名: uc_user_synlogin
'作  用: 获取同步登录代码
'参  数: uid : 用户ID
'返回值: 同步登录的 HTML 代码
'================================================
Function uc_user_synlogin(uid, password)
    If Not IsNumeric(uid) Then uc_user_synlogin = 0 : Exit Function
	uc_user_synlogin = uc_api_post("user", "synlogin", Array("uid=" & uid, "password=" & password))
End Function

'================================================
'函数名: uc_user_synlogout
'作  用: 获取同步退出代码
'参  数: 
'返回值: 同步退出的 HTML 代码
'================================================
Function uc_user_synlogout()
    uc_user_synlogout = uc_api_post("user", "synlogout", "")
End Function

'================================================
'函数名: uc_user_checkemail
'作  用: 检查Email地址是否正确
'参  数: email : Email
'返回值: 1 : 成功
'       -4 : email 格式有误
'       -5 : email 不允许注册
'       -6 : 该 email 已经被注册
'================================================
Function uc_user_checkemail(email)
    If email = "" Then uc_user_checkemail = "-4" : Exit Function
    uc_user_checkemail = uc_api_post("user", "check_email", Array("email=" & email))
End Function

'================================================
'函数名: uc_user_checkname
'作  用: 检查用户名是否为合法
'参  数: username   : 用户名
'返回值: 1 : 合法
'       -1 : 用户名不合法
'       -2 : 包含不允许注册的词语
'       -3 : 用户名已经存在
'================================================
Function uc_user_checkname(username)
    If username = "" Then uc_user_checkname = "-1" : Exit Function
    uc_user_checkname = uc_api_post("user", "check_username", Array("username=" & SURLEncode(username)))
End Function

'================================================
'函数名: uc_user_addprotected
'作  用: 添加保护用户
'参  数: username  : 保护用户名
'        admin     : 操作的管理员
'返回值: 1 : 成功
'       -1 : 失败
'================================================
Function uc_user_addprotected(username, admin)
    If username = "" Or admin = "" Then uc_user_addprotected = "-1" : Exit Function
    uc_user_addprotected = uc_api_post("user", "addprotected", Array("username=" & SURLEncode(username), "admin=" & admin))
End Function

'================================================
'函数名: uc_user_deleteprotected
'作  用: 删除保护用户
'参  数: username  : 保护用户名
'        admin     : 操作的管理员
'返回值: 1 : 成功
'       -1 : 失败
'================================================
Function uc_user_deleteprotected(username)
    If username = "" Then uc_user_deleteprotected = "-1" : Exit Function
    uc_user_deleteprotected = uc_api_post("user", "deleteprotected", Array("username=" & SURLEncode(username)))
End Function

'================================================
'函数名: uc_user_getprotected
'作  用: 得到受保护的用户名列表
'参  数: 
'返回值: Array
'================================================
Function uc_user_getprotected()
    uc_user_getprotected = uc_api_post("user", "getprotected", Array("1=1"))
End Function

'================================================
'函数名: uc_user_merge
'作  用: 把重名用户合并到 UCenter
'参  数: oldusername  : 老用户名
'        newusername  : 新用户名
'        uid		  : 老UID
'        password	  : 密码
'        email		  : Email
'返回值: -1 : 用户名不合法
'        -2 : 包含不允许注册的词语
'        -3 : 用户名已经存在
'        -4 : 所有项都是必填项
'        >1 : 表示成功，数值为 UID
'================================================
Function uc_user_merge(oldusername, newusername, uid, password, email)
    If oldusername = "" Or newusername = "" Or uid = "" Or password = "" Or email = "" Then uc_user_merge = -4 : Exit Function
    If Not IsNumeric(uid) Then uc_user_merge = "-1" : Exit Function
    Dim mystr
	mystr = Array("oldusername=" & SURLEncode(oldusername), "newusername=" & SURLEncode(newusername), "uid=" & uid, "password=" & password, "email=" & email)
    uc_user_merge = uc_api_post("user", "merge", mystr)
End Function

'================================================
'函数名: uc_user_merge_remove
'作  用: 移除重名用户记录
'参  数: username  : 用户名
'返回值:
'================================================
Function uc_user_merge_remove(username)
    If username = "" Then Exit Function
    uc_user_merge_remove = uc_api_post("user", "merge_remove", Array("uid=" & SURLEncode(username)))
End Function

'================================================
'函数名: uc_user_getcredit
'作  用: 获取指定应用的指定用户积分
'参  数: appid	: 应用Id
'        uid	: 用户Id
'        credit : 积分编号
'返回值: -1 : 用户名不合法
'        -2 : 包含不允许注册的词语
'        -3 : 用户名已经存在
'        -4 : 所有参数都是必填项
'        >1 : 表示成功，数值为 UID
'================================================
Function uc_user_getcredit(appid, uid, credit)
    If Not IsNumeric(appid) Or Not IsNumeric(uid) Or Not IsNumeric(credit) Then uc_user_getcredit = "-4" : Exit Function
    Dim mystr
	mystr = Array("appid=" & appid, "uid=" & uid, "credit=" & credit)
    uc_user_getcredit = uc_api_post("user", "getcredit", mystr)
End Function
'================================================用户接口 结束================================================


'================================================短信接口 开始================================================
'================================================
'函数名: uc_pm_location
'作  用: 进入短消息界面
'参  数: uid	: 用户 ID
'        newpm  : 是否直接进入newpm 默认0
'返回值: -1 : 只能使用用户 ID
'        URL : 跳转的地址 使用 Response.Redirect跳转
'================================================
Function uc_pm_location(uid, newpm)
    If Not IsNumeric(uid) Then uc_pm_location = -1 : Exit Function
    If newpm = 1 Then newpm = "&folder=newbox" Else newpm = ""
	uc_pm_location = uc_api_url("pm_client", "ls", "uid=" & uid, newpm)
End Function

'================================================
'函数名: uc_pm_checknew
'作  用: 检查新的短消息
'参  数: uid   : 用户 ID
'        more  : 详细信息
'返回值: 当 more = 0 时  : 未读消息数
'        当 more = 1 时  : Array(未读消息数,私人消息数)
'        当 more = 2 时  : Array(未读消息数,私人消息数,公共消息数,系统消息数)
'        当 more = 3 时  : Array(未读消息数,私人消息数,公共消息数,系统消息数,最后消息时间,最后消息发件人 ID,最后消息发件人用户名,最后消息内容)
'================================================
Function uc_pm_checknew(uid, more)
    If Not IsNumeric(uid) Then uc_pm_checknew = "-1" : Exit Function
    If Not IsNumeric(more) Then more = "0"
	If more > 3 Then more = "0"
	Dim mystr
    mystr = uc_api_post("pm","check_newpm",Array("uid=" & uid, "more=" & more))
	If more = "0" Then
	    If Len(mystr) < "1" Then mystr = 0
		uc_pm_checknew = mystr
    ElseIf more = "1" Then
	    If Len(mystr) > 10 Then mystr = loadxml(mystr) Else mystr = Array(0, 0)
        uc_pm_checknew = mystr
	ElseIf more = "2" Then
	    If Len(mystr) > 10 Then mystr = loadxml(mystr) Else mystr = Array(0, 0, 0, 0)
        uc_pm_checknew = mystr
	ElseIf more = "3" Then
	    If Len(mystr) > 10 Then mystr = loadxml(mystr) Else mystr = Array(0, 0, 0, 0, 0, 0, 0, 0)
        uc_pm_checknew = mystr
	End If
End Function

'================================================
'函数名: uc_pm_send
'作  用: 发送短消息
'参  数: fromuid   : 发件人uid 0 为系统消息
'        msgto     : 收件人 uid/username 多个逗号分割
'        subject   : 标题
'        message   : 内容
'        instantly : 是否立即发送  默认 1
'        replypmid : 回复的消息 ID  默认 0(发送新消息)
'        isusername: msgto 参数是否为用户名  默认 0(使用UID)
'返回值: >0 : 发送成功的最后一条消息 ID
'         0 : 发送失败
'        -1 : 超出了24小时最大允许发送短消息数目
'        -2 : 不满足两次发送短消息最短间隔
'        -3 : 不能给非好友批量发送短消息
'        -4 : 目前还不能使用发送短消息功能（注册多少日后才可以使用发短消息限制）
'        -5 : 发件人只能使用UID  0为系统消息
'================================================
Function uc_pm_send(fromuid, msgto, subject, message, instantly, replypmid, isusername)
    If Not IsNumeric(fromuid) Then uc_pm_send = "-5" : Exit Function
	If instantly = "0" Then instantly = "0" Else instantly = "1"
	If Not IsNumeric(replypmid) Then replypmid = "0"
	If isusername = "1" Then isusername = "1" Else isusername = "0"
	If instantly = "0" Then
	   If replypmid <> 0 Then replypmid = "&pmid=" & replypmid & "&do=reply" Else replypmid = ""
	   uc_pm_send = uc_api_url("pm_client", "send", "uid=" & fromuid, "&msgto=" & SURLEncode(msgto) & "&subject=" & SURLEncode(subject) & "&message=" & SURLEncode(message) & replypmid)
	Else
		Dim mystr
        mystr = Array("fromuid=" & fromuid, "msgto=" & SURLEncode(msgto), "subject=" & SURLEncode(subject), "message=" & SURLEncode(message), "replypmid=" & replypmid, "isusername=" & isusername)
    	uc_pm_send = uc_api_post("pm","sendpm",mystr)
	End If
End Function

'================================================
'函数名: uc_pm_delete
'作  用: 删除短消息
'参  数: uid     : 用户Id
'        folder  : 打开的目录 inbox=收件箱，outbox=发件箱
'        pmids   : 要删除的消息ID数组 用,分隔
'返回值: >0 : 被删除的短消息数
'        -4 : 要删除的消息ID 不能为空
'        -5 : 只能使用 UID
'       <=0 : 失败
'================================================
Function uc_pm_delete(uid, folder, pmids)
    If Not IsNumeric(uid) Then uc_pm_delete = "-5" : Exit Function
    If pmids = "" Then uc_pm_delete = "-4" : Exit Function
	If folder = "outbox" Then folder = "outbox" Else folder = "inbox"
    Dim mystr
    mystr = ReArray(pmids, "pmids")
	mystr = Array("uid=" & uid, "folder=" & folder, mystr)
	uc_pm_delete = uc_api_post("pm", "delete", mystr)
End Function

'================================================
'函数名: uc_pm_deleteuser
'作  用: 按照用户删除短消息
'参  数: uid     : 用户Id
'        touids  : 要删除的消息用户ID数组
'返回值: >0 : 成功
'        -4 : 要删除的用户ID 不能为空
'        -5 : 只能使用 UID
'       <=0 : 失败
'================================================
Function uc_pm_deleteuser(uid, touids)
    If Not IsNumeric(uid) Then uc_pm_deleteuser = "-5" : Exit Function
    If touids = "" Then uc_pm_deleteuser = "-4" : Exit Function
	Dim mystr
    mystr = ReArray(touids, "touids")
	mystr = Array("uid=" & uid, mystr)
	uc_pm_deleteuser = uc_api_post("pm", "deleteuser", mystr)
End Function

'================================================
'函数名: uc_pm_readstatus
'作  用: 标记已读/未读状态
'参  数: uid     : 用户Id
'        uids	 : 要标记已读状态的用户ID数组
'        pmids	 : 要标记已读状态的消息ID数组
'        status	 : 0 已读 1 未读
'返回值: 
'================================================
Function uc_pm_readstatus(uid, uids, pmids, status)
    If status = "1" Then status = "1" Else status = "0"
	Dim mystr, mystr2
    mystr = ReArray(uids, "uids")
	mystr2 = "pmids=" & pmids
	If pmids <> "" Then mystr2 = ReArray(pmids, "pmids")
	mystr = Array("uid=" & uid, mystr, mystr2, "status=" & status)
	uc_pm_readstatus = uc_api_post("pm", "readstatus", mystr)
End Function

'================================================
'函数名: uc_pm_list
'作  用: 获取短消息列表
'参  数: uid     : 用户Id
'        page	 : 当前页编号，默认值 1
'        pagesize: 每页最大条目数，默认值 10
'        folder	 : 打开的目录
'                newbox:新件箱
'                inbox:(默认值) 收件箱
'                outbox:发件箱
'        tfilter : 过滤方式
'                newpm:(默认值) 未读消息，folder 为 inbox 和 outbox 时使用
'                systempm:系统消息，folder 为 inbox 时使用
'                announcepm:公共消息，folder 为 inbox 时使用
'        msglen  : 截取短消息内容文字的长度，0 为不截取，默认值 0
'返回值: Array(消息总数,短消息列表数据)
'================================================
Function uc_pm_list(uid, page, pagesize, folder, tfilter, msglen)
    If Not IsNumeric(page) Then page = "1"
    If Not IsNumeric(pagesize) Then pagesize = "10"
    If Not IsNumeric(msglen) Then msglen = "0"
    If folder = "newbox" Then
	    folder = "newbox"
	ElseIf folder = "outbox" Then
	    folder = "outbox"
	Else
	    folder = "inbox"
	End If
    If tfilter = "systemp" Then
	    If folder = "inbox" Then tfilter = "systemp" Else tfilter = "newpm"
	ElseIf tfilter = "announcepm" Then
	    If folder = "inbox" Then tfilter = "announcepm" Else tfilter = "newpm"
	Else
		tfilter = "newpm"
	End If
	Dim mystr
	mystr = Array("uid=" & uid, "page=" & page, "pagesize=" & pagesize, "folder=" & folder, "filter=" & tfilter, "msglen=" & msglen)
	uc_pm_list = uc_api_post("pm", "ls", mystr)
End Function

'================================================
'函数名: uc_pm_ignore
'作  用: 忽略未读消息提示
'参  数: uid : 用户Id
'返回值: 
'================================================
Function uc_pm_ignore(uid)
	uc_pm_ignore = uc_api_post("pm", "ignore", Array("uid=" & uid))
End Function

'================================================
'函数名: uc_pm_view
'作  用: 获取短消息内容
'参  数: uid     : 用户Id
'        pmid	 : 消息Id
'        touid	 : 消息对方用户Id
'        aterange: 日期范围 1=今天,2=昨天,3=前天,4=上周,5=更早
'返回值: Array()
'================================================
Function uc_pm_view(uid, pmid, touid, daterange)
    If Not IsNumeric(pmid) Then pmid = "0"
    If Not IsNumeric(touid) Then touid = "0"
    If touid > 0 Then pmid = ""
    If Not IsNumeric(daterange) Then daterange = "1"
	If daterange > 5 Then daterange = "1"
	Dim mystr
	mystr = Array("uid=" & uid, "pmid=" & pmid, "touid=" & touid, "daterange=" & daterange)
	uc_pm_view = uc_api_post("pm", "view", mystr)
End Function

'================================================
'函数名: uc_pm_viewnode
'作  用: 获取单条短消息内容
'参  数: uid   : 用户Id
'        atype : 0 = 获取指定单条消息
' 				 1 = 获取指定用户发的最后单条消息
' 				 2 = 获取指定用户收的最后单条消息
'        pmid  : 消息 ID，默认值 0，type 为 0 时本参数有效
'返回值: Array()
'================================================
Function uc_pm_viewnode(uid, pmid, atype)
    If Not IsNumeric(pmid) Then pmid = "0"
    If Not IsNumeric(atype) Then atype = "0"
	Dim mystr
	mystr = Array("uid=" & uid, "pmid=" & pmid, "type=" & atype)
	uc_pm_viewnode = uc_api_post("pm", "viewnode", mystr)
	uc_pm_viewnode = loadxml(uc_pm_viewnode)
End Function

'================================================
'函数名: uc_pm_blackls_get
'作  用: 获取黑名单
'参  数: uid : 用户Id
'返回值: 黑名单
'================================================
Function uc_pm_blackls_get(uid)
	uc_pm_blackls_get = uc_api_post("pm", "blackls_get", Array("uid=" & uid))
End Function

'================================================
'函数名: uc_pm_blackls_set
'作  用: 设置黑名单
'参  数: uid : 用户Id
'        blackls  : 黑名单内容  {ALL} 表示全部
'返回值: 1: 更新成功
'        0: 更新失败
'================================================
Function uc_pm_blackls_set(uid, blackls)
	uc_pm_blackls_set = uc_api_post("pm", "blackls_set", Array("uid=" & uid, "blackls=" & blackls))
End Function

'================================================
'函数名: uc_pm_blackls_add
'作  用: 设置黑名单
'参  数: uid : 用户Id
'        username  : 用户名
'返回值: 1: 更新成功
'        0: 更新失败
'================================================
Function uc_pm_blackls_add(uid, username)
	uc_pm_blackls_add = uc_api_post("pm", "blackls_add", Array("uid=" & uid, ReArray(username, "username")))
End Function

'================================================
'函数名: uc_pm_blackls_delete
'作  用: 设置黑名单
'参  数: uid : 用户Id
'        username  : 用户名
'返回值: 1: 更新成功
'        0: 更新失败
'================================================
Function uc_pm_blackls_delete(uid, username)
	uc_pm_blackls_delete = uc_api_post("pm", "blackls_delete", Array("uid=" & uid, ReArray(username, "username")))
End Function
'================================================短信接口 结束================================================


'================================================好友接口 开始================================================
'================================================
'函数名: uc_friend_add
'作  用: 添加好友
'参  数: uid	: 用户ID
'        friendid  : 好友ID
'        comment   : 备注，可以为空
'返回值: >0   : 成功
'        -1  :  双方都是好友
'================================================
Function uc_friend_add(uid, friendid, comment)
    If Not IsNumeric(uid) Then uc_friend_add = "-11" : Exit Function
    If Not IsNumeric(friendid) Then uc_friend_add = "-10" : Exit Function
    Dim mystr
	mystr = Array("uid=" & uid, "friendid=" & friendid, "comment=" & SURLEncode(comment))
    uc_friend_add = uc_api_post("friend", "add", mystr)
End Function

'================================================
'函数名: uc_friend_delete
'作  用: 删除好友
'参  数: uid	: 用户ID
'        friendids  : 好友ID  用,分隔
'返回值: >0   : 成功 返回删除个数
'        -0   : 失败,或者好友已经删除
'================================================
Function uc_friend_delete(uid, friendids)
    If Not IsNumeric(uid) Then uc_friend_delete = "-10" : Exit Function
    Dim mystr
	mystr = ReArray(friendids, "friendids")
	mystr = Array("uid=" & uid, mystr)
    uc_friend_delete = uc_api_post("friend", "delete", mystr)
End Function

'================================================
'函数名: uc_friend_totalnum
'作  用: 获取好友人数
'参  数: uid	: 用户ID
'        direction 
'            0 : (默认值) 指定用户的全部好友
'            1 : 正向，指定用户添加的好友，但没被对方添加
'            2 : 反向，指定用户被哪些用户添加为好友，但没被对方添加
'            3 : 双向，互相添加为好友
'返回值: 好友人数
'================================================
Function uc_friend_totalnum(uid, direction)
    If Not IsNumeric(uid) Then uc_friend_totalnum = "-10" : Exit Function
    If Not IsNumeric(direction) Then direction = 0
	If direction > 3 Then direction = 0
    Dim mystr
	mystr = Array("uid=" & uid, "direction=" & direction)
    uc_friend_totalnum = uc_api_post("friend", "totalnum", mystr)
End Function

'================================================
'函数名: uc_friend_ls
'作  用: 好友列表
'参  数: uid	: 用户ID
'        page	: 当前页
'        pagesize	: 每页条目数
'        totalnum	: 总数
'        direction 
'            0 : (默认值) 指定用户的全部好友
'            1 : 正向，指定用户添加的好友，但没被对方添加
'            2 : 反向，指定用户被哪些用户添加为好友，但没被对方添加
'            3 : 双向，互相添加为好友
'返回值: 
'================================================
Function uc_friend_ls(uid, page, pagesize, totalnum, direction)
    If Not IsNumeric(uid) Then uc_friend_ls = "-1" : Exit Function
    If Not IsNumeric(page) Then page = "1"
    If Not IsNumeric(pagesize) Then pagesize = "10"
    If Not IsNumeric(totalnum) Then totalnum = "10"
    If Not IsNumeric(direction) Then direction = "0"
	If direction > 3 Then direction = "0"
    Dim mystr
	mystr = Array("uid=" & uid, "page=" & page, "pagesize=" & pagesize, "totalnum=" & totalnum, "direction=" & direction)
    uc_friend_ls = uc_api_post("friend", "ls", mystr)
End Function

'================================================好友接口 结束================================================

'================================================头像接口 开始================================================
'================================================
'函数名: uc_avatar
'作  用: 修改头像
'参  数: uid	: 用户 ID
'        atype  : 头像类型，取值范围(virtual,real)，默认为 virtual
'        returnhtml  : 是否返回 HTML 代码  默认 1
'返回值: returnhtml = 1   : 返回设置头像的 HTML 代码
'        returnhtml = 0   : 返回设置头像的 Flash 调用数组
'        -1   : 只用使用用户 ID
'================================================
Function uc_avatar(uid, atype, returnhtml)
    If Not IsNumeric(uid) Then uc_avatar = -1 : Exit Function
    If atype = "real" Then atype = "real" Else atype = "virtual"
	If returnhtml = "0" Then returnhtml = "0" Else returnhtml = "1"
	Dim thtml, uc_input, uc_avatarflash
	uc_input = uc_api_input("uid=" & uid)
	uc_avatarflash = UC_API & "/images/camera.swf?inajax=1&appid=" & UC_APPID & "&input=" & uc_input & "&agent=" & Php_MD5(Request.ServerVariables("HTTP_USER_AGENT")) & "&ucapi=" & SURLEncode(UC_API) & "&avatartype=" & atype
    If returnhtml = 0 Then
        uc_avatar = Array("width=447", "height=477", "scale=exactfit", "src=" & uc_avatarflash, "id=mycamera", "name=mycamera", "quality=high", "bgcolor=#ffffff", "wmode=transparent", "menu=false", "swLiveConnect=true", "allowScriptAccess=always")
    Else
		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=""447"" height=""477"" id=""mycamera"" align=""middle"">" & vbcrlf & _
		"		<param name=""allowScriptAccess"" value=""always"" />" & vbcrlf & _
		"		<param name=""scale"" value=""exactfit"" />" & vbcrlf & _
		"		<param name=""wmode"" value=""transparent"" />" & vbcrlf & _
		"		<param name=""quality"" value=""high"" />" & vbcrlf & _
		"		<param name=""bgcolor"" value=""#ffffff"" />" & vbcrlf & _
		"		<param name=""movie"" value="""&uc_avatarflash&""" />" & vbcrlf & _
		"		<param name=""menu"" value=""false"" />" & vbcrlf & _
		"		<embed src=""" & uc_avatarflash & """ quality=""high"" bgcolor=""#ffffff"" width=""447"" height=""477"" name=""mycamera"" align=""middle"" allowScriptAccess=""always"" allowFullScreen=""false"" scale=""exactfit""  wmode=""transparent"" type=""application/x-shockwave-flash"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" />" & vbcrlf & _
		"	</object>" & vbcrlf
	End If
End Function

'================================================
'函数名: uc_check_avatar
'作  用: 检测头像是否存在
'参  数: uid	: 用户 ID
'        size   : 头像尺寸  头像尺寸，取值范围(big,middle,small)，默认为 middle
'        atype  : 头像类型，取值范围(virtual,real)，默认为 virtual
'返回值: 1   : 头像存在
'        0   : 头像不存在
'       -1   : 只用使用用户 ID查看
'================================================
Function uc_check_avatar(uid, size, atype)
    If Not IsNumeric(uid) Then uc_check_avatar = "-1" : Exit Function
    If size = "big" Then
        size = "big"
	ElseIf size = "small" Then
	    size = "small"
	Else
	    size = "middle"
	End If
    If atype = "real" Then atype = "real" Else atype = "virtual"
    uc_check_avatar = uc_fopen(UC_API & "/avatar.php?uid=" & uid & "&type=" & atype & "&size=" & size & "&check_file_exists=1","")
End Function

'================================================头像接口 结束================================================

'================================================
'函数名: uc_credit_exchange_request
'作  用: 积分兑换请求
'参  数: uid	: 用户 ID
'        from   : 原积分
'        tox    : 目标积分
'        toappid: 目标应用ID
'        amount : 积分数额
'返回值: 1   : 请求成功
'        0   : 请求失败
'================================================
Function uc_credit_exchange_request(uid, from, tox, toappid, amount)
    Dim mystr
	mystr = Array("uid=" & uid, "from=" & from, "to=" & tox, "toappid=" & toappid, "amount=" & amount)
    uc_credit_exchange_request = uc_api_post("credit", "request", mystr)
End Function

'================================================
'函数名: uc_tag_get
'作  用: 返回指定的相关TAG数据
'参  数: tagname   : TAG名称
'        nums    : 返回数据的条目数
'返回值: Array()
'================================================
Function uc_tag_get(tagname, nums)
    uc_tag_get = uc_api_post("credit", "request", Array("tagname=" & tagname, ReArray(nums,"nums")))
End Function

'================================================
'函数名: uc_mail_queue
'作  用: 邮件队列
'参  数: uids	: 用户名id，多个用逗号(,)隔开
'        emails : 邮件地址，多个用逗号隔开
'        subject: 邮件标题
'        message: 邮件内容
'        charset: 邮件字符集，可选参数，默认为gbk
'        htmlon : 是否按html格式发送邮件，可选参数，默认为否
'        level  : 邮件级别，可选参数，取值0-127，默认为1，越大发送的优先级越高，为0时不入库，直接发送，会影响当前进程速度，慎用
'返回值: 0   : 请求失败
'       >0   : 成功，返回插入记录的id，如果是多条则返回最后一条记录的id，若level等于0，则返回1
'================================================
Function uc_mail_queue(uids, emails, subject, message, frommail, charset, htmlon, level)
    If charset = "" Then charset = "gbk"
	If htmlon = "1" Then htmlon = True Else htmlon = False
	Dim mystr
	mystr = Array("uids=" & uids,"emails=" & emails,"subject=" & SURLEncode(subject),"message=" & SURLEncode(message),"frommail=" & frommail,"charset=" & charset,"htmlon=" & htmlon,"level=" & level)
    uc_mail_queue = uc_api_post("mail", "add", mystr)
End Function

'================================================
'函数名: uc_app_ls
'作  用: 获取应用列表
'参  数:
'返回值: XML数据
'================================================
Function uc_app_ls()
    uc_app_ls = uc_api_post("app", "ls", "")
End Function

'================================================
'函数名: ReArray
'作  用: 转换成数组
'参  数: arg  : 要转换的数据
'        name : 前缀
'返回值: 
'================================================
Function ReArray(arg, name)
    Dim mystr, i, j
    arg = Split(arg,",")
    For i = 0 To UBound(arg)
        ReArray = ReArray & name & "[" & i & "]=" & SURLEncode(Trim(arg(i))) & "&"
    Next
	ReArray = Left(ReArray,Len(ReArray)-1)
End Function

'================================================
'函数名: loadxml
'作  用: xml数据转成数组
'参  数: code   : xml数据源
'返回值: 数组
'================================================
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

'================================================
'函数名: uc_api_post
'作  用: 方式取指定的模块和动作的数据
'参  数: module   : 请求的模块
'        action   : 请求的动作
'        arg      : 参数（会加密的方式传送）
'返回值: 数据
'================================================
Function uc_api_post(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
    uc_api_post = uc_api_requestdata(module, action, mystr, "")
	uc_api_post = uc_fopen(UC_API & "/index.php",uc_api_post)
End Function

'================================================
'函数名: uc_api_requestdata
'作  用: 构造发送给用户中心的请求数据
'参  数: module   : 请求的模块
'        action   : 请求的动作
'        arg      : 参数（会加密的方式传送）
'        extra    : 附加参数（传送时不加密）
'返回值: 要传送的数据
'================================================
Function uc_api_requestdata(module, action, arg, extra)
    Dim input, post
	input = uc_api_input(arg)
	post = "m=" & module & "&a=" & action & "&inajax=2&release=" & UC_CLIENT_RELEASE & "&input=" & input & "&appid=" & UC_APPID & extra
	uc_api_requestdata = post
End Function

Function uc_api_url(module, action, arg, extra)
	uc_api_url = UC_API & "/index.php?" & uc_api_requestdata(module, action, arg, extra)
End Function

Function uc_api_input(data)
    data = data & "&agent=" & Php_MD5(Request.ServerVariables("HTTP_USER_AGENT")) & "&time=" & DateDiff("s","1970-01-01 08:00:00",Now())
	uc_api_input = SURLEncode(uc_authcode(data,"",UC_KEY))
End Function

'================================================
'函数名: uc_fopen
'作  用: 远程打开URL
'参  数: url    : 打开的ur
'        post   : 要发送的 POST 数据
'返回值: 取到的字符串
'================================================
Function uc_fopen(url,post) 
	Dim Http 
	Set Http = Server.CreateObject("Msxml2.ServerXMLHTTP")
	With Http
        .Open "POST",url,False
        .SetRequestHeader "Accept","*/*"
        .SetRequestHeader "Accept-Language","zh-cn"
        .SetRequestHeader "Content-Type","application/x-www-form-urlencoded" 
        .SetRequestHeader "User-Agent", Request.ServerVariables("HTTP_USER_AGENT")
	.setRequestHeader "Host","119.132.83.166" 
        .SetRequestHeader "Content-Length",Len(post)
        .setRequestHeader "Connection","Close" 
        .setRequestHeader "Cache-Control","no-cache"
        .Send post
        uc_fopen = .ResponseText
	End With
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
%>