Foxtable(狐表)用户栏目专家坐堂 → 服务器异步函数


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

主题:服务器异步函数

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


加好友 发短信
等级:小狐 帖子:373 积分:3107 威望:0 精华:0 注册:2015/1/30 9:47:00
服务器异步函数  发帖心情 Post By:2021/1/12 0:08:00 [只看该作者]

在服务器HttpServer中,主线程进行用户登录验证,是用同步函数还是异步函数呢?
目前用户集中访问的时候,服务器会出错,自动关闭,没有提示,不知道是不是以下代码出现的问题。

    Case "Remuneration"        
        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 
            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") 
        End If

        Dim Verified As Boolean
        Dim drc As DataRow = DataTables("员工花名册").SQLFind("企业微信号ID ='" & UserId & "'") '根据openid找出对应的行
        If UserId  > "" AndAlso drc IsNot Nothing  AndAlso drc("微信权限") = True '授权成功
            Verified  = True
            UserName = drc("姓名")
            e.AppendCookie("userid",UserId) '将userid存储在Cookie中
        ElseIf e.GetValues.ContainsKey("code") = False Then '如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
            Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&agentid={2}&state=STATE#wechat_redirect"
            Dim ul2 As String = UrlEncode(Vars("yyzy"))    ‘yyzy为系统固定参数
            ul = CExp(ul,Vars("qyid"),ul2,Vars("yyid"))   ‘yyid为系统固定参数
            sb.Append("<meta http-equiv='Refresh' c>") 
            e.WriteString(sb.ToString)
            Return
        ElseIf userid = "" Then
            e.WriteString("请从企业微信APP中进行访问")
            Return
        End If
        If Verified = False Then
            e.AppendCookie("userid",UserId)
            e.WriteString("<meta http-equiv='Refresh' c>")   ‘指向异步函数
        Else
            e.WriteString("<meta http-equiv='Refresh' c>")   ‘指向异步函数
        End If
        e.WriteString(sb.ToString)
[此贴子已经被作者于2021/1/12 0:16:01编辑过]

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


加好友 发短信
等级:超级版主 帖子:106536 积分:541839 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/1/12 8:48:00 [只看该作者]

最后一句代码去掉:e.WriteString (sb.ToString)

e.WriteString不能重复调用,一次返回只能调用一次。

另外如果登录验证是在函数里的,请使用同步函数,以为其它页面肯定是要等待验证通过的

 回到顶部