猪八戒 发表于 2018-6-29 19:02:10

安装使用 ASP程序整合UCenter 同步登录退出并解决中文登录的问题

首先ASP+UC客户端API文档查看:
用户注册示例 (ASP)Dim register
'register = uc_user_register("用户名","密码","邮箱","安全提问","问题答案")
register = uc_user_register("admin1","admin888","admin@qq.com","","")
If register > "0" Then
    response.write "注册成功"
ElseIf register = "-1" Then
    response.write "用户名不合法"
ElseIf register = "-2" Then
    response.write "包含要允许注册的词语"
ElseIf register = "-3" Then
    response.write "用户名已经存在"
ElseIf register = "-4" Then
    response.write "Email 格式有误"
ElseIf register = "-5" Then
    response.write "Email 不允许注册"
ElseIf register = "-6" Then
    response.write "该 Email 已经被注册"
ElseIf register = "-7" Then
    response.write "注册信息填写不全"
Else
    response.write "未定义"
End If


用户登录示例 (ASP)Dim login
'login = uc_user_login("用户","密码","是否ID登录","是否验证安全问题","安全问题","问题答案")
login = uc_user_login("admin","5201314","0","0","","")
If login(0) > "0" Then
    response.write "登录成功<br>"
    response.write "用户ID:"&login(0)&"<br>"
    response.write "用户名:"&login(1)&"<br>"
    response.write "用户密码:"&login(2)&"<br>"
    response.write "用户邮箱:"&login(3)&"<br>"
    response.write "是否重命名:"&login(4)&"<br>"
ElseIf login(0) = "-1" Then
    response.write "用户不存在,或者被删除"
ElseIf login(0) = "-2" Then
    response.write "密码错"
ElseIf login(0) = "-3" Then
    response.write "安全提问错"
ElseIf login(0) = "-4" Then
    response.write "用户或密码为空"
Else
    response.write "未定义"
End If

删除用户

'response.write uc_user_delete("用户ID")
response.write uc_user_delete(2)

检查用户名示例 (ASP)Dim cname
'cname = uc_user_checkname("用户名")
cname = uc_user_checkname("admin")
If cname = "1" Then
    response.write "正确"
ElseIf cname = "-1" Then
    response.write "用户名不合法"
ElseIf cname = "-2" Then
    response.write "包含不允许注册的词语"
ElseIf cname = "-3" Then
    response.write "用户名已经存在"
Else
    response.write "未定义"
End If


用户登录 后的:
response.write uc_user_synlogin(UID)

完整的实例:

Dim login
'login = uc_user_login("用户","密码","是否ID登录","是否验证安全问题","安全问题","问题答案")
login = uc_user_login("admin","5201314","0","0","","")
If login(0) > 0 Then '有此用户才登陆
    response.write uc_user_synlogin(login(0))'获取同步登录代码
ElseIf login(0) = "-1" Then
    response.write "用户不存在"
ElseIf login(0) = "-2" Then
    response.write "密码错误"
Else
    response.write "未定义"
End If如何安装使用这里就不详细描述了,只说几点遇到的问题,因为添加用户、修改密码我是直接用ASP+MYSQL向数据库添加修改数据,所以不知道这个API对添加用户、修改密码有没有问题,这里详细讲同步登录。

1、通信问题

在UC添加应用时通信密钥要和config.inc.asp里写的一样,编写程序时调用config.inc.asp,同步登录需要在是否同步应用里选择是。

2、中文用户无法登录问题

这里给一个简单的同步登录代码,就命名为login.asp吧!

<!--#include file="config.inc.asp"-->
<%
a=uc_user_login("清竹科技", "******", 0, 0, "", "") '登录返回ARRAY数组,详细函数说明见client.asp
'----------------------
'登录判断这里不详细编写,当作登录成功
response.write uc_user_synlogin(a(0),"******") '得到登录ID,打印结果执行JS同步登录
response.write a(1)
response.end
%>接下来是重点,打开client.asp,CTRL+F搜索Function uc_fopen(url,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在本函数下方添加一个二进制转换函数
Function bytes2bstr(vin)
On Error Resume Next
Err.Clear
strreturn = ""
For i = 1 To LenB(vin)
thischarcode = AscB(MidB(vin, i, 1))
If thischarcode < &H80 Then
strreturn = strreturn & Chr(thischarcode)
Else
nextcharcode = AscB(MidB(vin, i + 1, 1))
strreturn = strreturn & Chr(CLng(thischarcode) * &H100 + CInt(nextcharcode))
i = i + 1
End If
Next
bytes2bstr = strreturn
End Function添加后,把原函数里的uc_fopen = .ResponseText换成uc_fopen=bytes2bstr(.responsebody)
修改后的完整代码如下:
'================================================
'函数名: 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=bytes2bstr(.responsebody)
'uc_fopen = .ResponseText
End With
End Function
Function bytes2bstr(vin)
On Error Resume Next
Err.Clear
strreturn = ""
For i = 1 To LenB(vin)
thischarcode = AscB(MidB(vin, i, 1))
If thischarcode < &H80 Then
strreturn = strreturn & Chr(thischarcode)
Else
nextcharcode = AscB(MidB(vin, i + 1, 1))
strreturn = strreturn & Chr(CLng(thischarcode) * &H100 + CInt(nextcharcode))
i = i + 1
End If
Next
bytes2bstr = strreturn
End Function返回结果:
<script type="text/javascript" src=http://bbs.qzsys.com/api/uc.php?time=1291717078&code=************************** reload="1"></script>即login.asp里response.write uc_user_synlogin(a(0),"******")打印出来的结果,登录成功!
页: [1]
查看完整版本: 安装使用 ASP程序整合UCenter 同步登录退出并解决中文登录的问题