Foxtable(狐表)用户栏目专家坐堂 → 网页授权接口 异步函数


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

主题:网页授权接口 异步函数

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


加好友 发短信
等级:小狐 帖子:373 积分:3107 威望:0 精华:0 注册:2015/1/30 9:47:00
网页授权接口 异步函数  发帖心情 Post By:2018/9/1 15:55:00 [只看该作者]

3、Foxtable端的HttpRequst事件代码为:

If
e.host = "wexin.foxtable.com" 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中提取useridusername
    End If
    Dim Verified As Boolean
    Dim dr As DataRow = DataTables("Users").Find("userid ='" & UserId & "'")
'
根据openid找出对应的行
    If UserId  > "" AndAlso dr IsNot Nothing AndAlso dr("permit") = True
'
授权成功
        Verified  = True
        UserName = dr("name")
        e.AppendCookie("userid",UserId)
'
useridusername存储在Cookie
    ElseIf e.GetValues.ContainsKey("code") = False Then
'
如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
        Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa31aba4cd83af57e&redirect_uri=http%3a%2f%2fwexin.foxtable.com&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 Then
        sb.AppendLine(
"
你无权访问本系统")
    Else
        sb.AppendLine(
"
欢迎" & UserName & " , <a href='http://wexin.foxtable.com'>刷新页面</a>")
    End If
    e.WriteString(sb.ToString)

End
If


像这种网页授权的服务器,可以用异步函数么?
按帮助这种直接放HttpRequst事件里面,同时访问的用户数多的情况服务器会不会卡死?

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107182 积分:545159 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2018/9/1 16:04:00 [只看该作者]

可以,DataTables("Users").Find改为使用sqlcommand查询


 回到顶部