以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  登录授权,获取UserId与UserName无效  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=127628)

--  作者:zoyong
--  发布时间:2018/11/18 15:25:00
--  登录授权,获取UserId与UserName无效

\'----------------------以下代码是企业微信认证-------------------------------------------
If e.host = "xjxhsd.vicp.net:21166" Then \'需要授权才能访问的域名
    Dim UserId As String
    Dim UserName As String
    Dim sb As New StringBuilder
    sb.AppendLine("<meta name=\'viewport\' c>")
    If e.GetValues.ContainsKey("code") Then \'如果通过授权链接跳转而来,就根据传递过来的code参数调用接口,获取用户的UserId
        Dim ul As String  = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={0}&code={1}"
        ul = CExp(ul,Functions.Execute("GetQYAccessToken"),e.GetValues("code"))
        Dim hc As new HttpClient(ul)
        Dim jo As JObject = JObject.Parse(hc.GetData)
        If jo("UserId") IsNot Nothing Then
            UserId = jo("UserId")
        End If
    Else
        UserId = e.Cookies("userid") \'否则从cookie中提取userid和username
    End If
    Dim Verified As Boolean
    Dim dr As DataRow
    dr = DataTables("Users").Find("userid =\'" & UserId & "\'") \'根据openid找出对应的行
    If dr IsNot Nothing AndAlso UserId  > "" AndAlso dr("permit") = True \'授权成功
        Verified  = True
        UserName = dr("name")
        e.AppendCookie("userid",UserId) \'将userid和username存储在Cookie中
        e.AppendCookie("UserName",UserName)
    ElseIf e.GetValues.ContainsKey("code") = False Then \'如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
        Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxcbfda17a529a96a6&redirect_uri=http%3a%2f%2fxjxhsd.vicp.net:21166&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
        sb.Append("<meta http-equiv=\'Refresh\' c>") \'跳转到授权链接
        e.WriteString(sb.ToString)
        Return
    End If
    If Verified = False AndAlso e.Path <> "logon.htm" Then \'如果用户身份验证失败,且访问的不是登录页面
        e.WriteString("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面
    Else
        sb.AppendLine("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页
    End If
    e.WriteString(sb.ToString)
End If

Select Case e.path
    Case "logon.htm"
        Dim wb As New WeUI
        wb.InsertHTML("<h3 align=\'center\' style=\'margin-top:5px\'>用户登录</h3>")
        wb.AddForm("","form1","logon.htm")
        \'提示用名和密码
        If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password")  Then \'判断是否是验证失败后的重新登录
            wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 \'如果用户通过登录按钮访问,则给用户一个2秒的提示.
        End If
        With wb.AddInputGroup("form1","ipg1")
            .Attribute = "style=\'margin-top:5px\'"
            .AddInput("xm","用户名","text")
            .AddInput("pw","密码","password")
        End With
        With wb.AddButtonGroup("form1","btg1",True)
            .Add("btn1", "确定", "submit")
        End With
        e.WriteString(wb.Build)
End Select


--  作者:有点甜
--  发布时间:2018/11/18 23:46:00
--  

1、具体一点你的问题

 

2、加入msgbox调试弹出到哪里,弹出什么信息

 

3、单纯贴代码别人无法定位错误


--  作者:zoyong
--  发布时间:2018/11/29 19:00:00
--  
Dim wb As New weui
\'
身份验证
Dim
Verified As Boolean \'用于标记用户是否通过了身份验证
Dim
UserName As String = e.Cookies("username") \'cookie中获取用户名
Dim
Password As String = e.Cookies("password") \'cookie中获取用户密码
If
e.Path = "logon.htm" \'如果是通过登录页面访问,PostValues即可中提取用户名和密码
    If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password"Then
        UserName = e.PostValues("username")
        Password = e.PostValues("password")
    End
If

End
If
If
UserName = "张三" AndAlso Password = "888" Then  \'实际使用的时候,请改为从数据库读取用户名和密码进行比较
    Verified  =
True

ElseIf
Username = "李四" AndAlso Password="999" Then
    Verified  =
True

End
If


            Dim dr As DataRow
            dr = DataTables("Users").SQLFind("name = " & e.PostValues("姓名") & " and  Password = " & e.PostValues("密码") & " and 订餐 = true")
            If dr Is Nothing Then    \'如果找不到数据
                With wb.AddMsgPage("","msgpage","验证失败!","没有权限,请联系管理员开通!")
                    .icon = "Warn" \'改变图标
                    .AddButton("btn1","返回").Attribute = ""
                End With
                e.WriteString(wb.Build)
                Return ""   \'必须返回
            End If

红色代码改成绿色,其他不变,弹出“没有权限,请联系管理员开通!”   求解

--  作者:有点甜
--  发布时间:2018/11/29 19:19:00
--  

1、改成

 

dr = DataTables("Users").SQLFind("name = \'" & e.PostValues("姓名") & "\' and  Password = \'" & e.PostValues("密码") & "\' and 订餐 = true")

 

2、如果还有问题,把sqlfind改成find测试,看合成的条件是不是错了。