Foxtable(狐表)用户栏目专家坐堂 → 如何控制域名子目录的详情授权?


  共有77人关注过本帖树形打印复制链接

主题:如何控制域名子目录的详情授权?

帅哥哟,离线,有人找我吗?
wh420
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:942 积分:8948 威望:0 精华:0 注册:2014/2/19 16:32:00
如何控制域名子目录的详情授权?  发帖心情 Post By:2021/10/13 11:22:00 [只看该作者]

现有域名abc.com,想对www.abc.com/list/a.htm和www.abc.com/list/b.htm实现微信授权访问,而http://WWW.ABC.COM/OTHER/list.htm则不需要网页授权,可随意访问。请问老师这个如何写代码?
Dim sb As New StringBuilder
sb
.AppendLine("<meta name='viewport' c>")
If
e.host = "wexin.foxtable.com" Then '授权测试
    Dim UserName As String
    Dim OpenID As String
    If e.GetValues.ContainsKey("code") Then '
如果是通过授权链接跳转而来,就从链接重提取code来获取openid
        Dim ul As String  = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code"
        ul = CExp(ul,"wx8acdb7df5beb68fd","dec0df8a469518df30e9bdef0758c678",e.GetValues("code"))
        Dim hc As new HttpClient(ul)
        Dim jo As JObject = JObject.Parse(hc.GetData)
        If jo("openid") IsNot Nothing Then '
如果获取openid成功(成功的话,还会同时返回一个accesstiken,用于获取用户详情)
            OpenID = jo("openid")
            Dim dr As DataRow = DataTables("WXUsers").Find("openid ='" & Openid & "'")
            If dr IsNot Nothing Then
                UserName = dr("nickname")
            Else
                ul = "https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN "
                '
根据openidaccesstoken获取用户详情,注意这里这个accesstoken不是普通accesston,只能用于网页授权
                hc = New HttpClient(CExp(ul, jo("access_token"), OpenId))
                jo = jo.Parse(hc.GetData)
                If jo("openid") IsNot Nothing Then
                    UserName = jo("nickname")
                    dr = DataTables("WXUsers").AddNew()
                    Dim nms() As String = {"openid","nickname","sex","city","country","province","headimgurl"} '""
                    For Each nm As String In nms
                        dr(nm) = jo(nm)
                    Next
                    dr.Save
                Else
                    e.WriteString(jo.ToString) '
在用户浏览器显示错误信息
                    Return
                End If
            End If
            e.AppendCookie("username",UserName) '
用户名和openid存储在Cookie
            e.AppendCookie("openid",OpenID)
        Else
            e.WriteString(jo.ToString) '
在用户浏览器显示错误信息
            Return
        End If
    Else
        UserName = e.Cookies("username") '
cookie获取用户名和openid
        OpenID = e.Cookies("openid")
        If userName = "" OrElse OpenID = "" Then
            Dim ul As String  = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8acdb7df5beb68fd&redirect_uri=http%3a%2f%2fwexin.foxtable.com&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
            sb.Append("<meta http-equiv='Refresh' c>") '
跳转到授权链接
            e.WriteString(sb.ToString)
            Return
        End If
    End If
    If  OpenID > "" And UserName > "" Then
       
'这里可以做进一步的权限判断
        sb.AppendLine("欢迎" & UserName & "光临, <a href='http://wexin.foxtable.com'>刷新页面</a>")
    Else
        sb.AppendLine("你无权访问本系统")
   
End If
End
If
e
.WriteString(sb.ToString)

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:76222 积分:386700 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/10/13 11:50:00 [只看该作者]

参考:http://www.foxtable.com/mobilehelp/topics/0006.htm
如:
……
If e.host = "www.abc.com" Then '授权测试
    Select Case e.Path
        Case "
list\a.htm","list\b.htm"
    Dim UserName As String
    Dim OpenID As String
……
    Else
        UserName = e.Cookies("username"'
cookie获取用户名和openid
        OpenID = e.Cookies("openid")
        If userName = "" OrElse OpenID = "" Then
            Dim ul As String  = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8acdb7df5beb68fd&redirect_uri=http%3a%2f%2fwexin.foxtable.com
%2f" & UrlEncode(e.Path.replace("\","/")) & "&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
            sb.Append("<meta http-equiv='Refresh' c>"'跳转到授权链接
            e.WriteString(sb.ToString)
            Return
        End If
    End If

 回到顶部
帅哥哟,离线,有人找我吗?
zcl
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:245 积分:1950 威望:0 精华:0 注册:2014/9/12 16:35:00
  发帖心情 Post By:2021/10/14 16:13:00 [只看该作者]

不错


 回到顶部