Foxtable(狐表)用户栏目专家坐堂 → [求助]强烈求助,cookices获得使用极其不稳定


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

主题:[求助]强烈求助,cookices获得使用极其不稳定

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


加好友 发短信
等级:小狐 帖子:394 积分:4047 威望:0 精华:0 注册:2017/3/24 15:10:00
[求助]强烈求助,cookices获得使用极其不稳定  发帖心情 Post By:2021/4/7 22:12:00 [只看该作者]

团报主页需要三个Cookie参数,分别是jsbh,tuanid,openid,现在的问题是,通过十好几个手机测试,这三个cookier的生成出现了很多组合,就是没有一个完整的?请求老师帮忙解决一下,否则项目根本无法进行


' 团报主页
Dim e As RequestEventArgs = args(0)
Dim wb As new weui
'wb.AppendHTML("<meta name='viewport' c>")

Dim jsbh As String
Dim tuanid As String 
If e.GetValues.ContainsKey("jsbh")  Then
jsbh = e.GetValues("jsbh")
End If
If e.GetValues.ContainsKey("tuanid")  Then
tuanid = e.GetValues("tuanid")
End If

Dim shouquanurl As String = "tuanbao.htm?jsbh=" & jsbh & "&tuanid=" & tuanid
Functions.Execute("gz_webshouquan",e,shouquanurl)   ‘授权函数

If e.GetValues.ContainsKey("jsbh")  Then
    wb.AppendCookie("jsbh",e.GetValues("jsbh"))  
End If

jsbh = e.Cookies("jsbh")
tuanid = e.Cookies("tuanid") '在使tuanid值的时候要判断是否为空值
Dim openid As String = e.Cookies("openid")
………………………………



''gz_webshouquan函数
Dim e As RequestEventArgs = args(0)
Dim url As String = args(1)

Dim wb As New WeUI
wb.InsertHTML("<meta name='viewport' c>")

If e.GetValues.ContainsKey("jsbh")  Then
    Dim cmd As new SQLCommand
    wb.AppendCookie("jsbh",e.GetValues("jsbh"),360)
    'msgbox(e.GetValues("jsbh")) '测试能正常显示出正确值
End If
If e.GetValues.ContainsKey("tuanid")  Then
    wb.AppendCookie("tuanid",e.GetValues("tuanid"),360)
    'msgbox(e.GetValues("tuanid"))  '测试能正常显示出正确的值来
End If

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,vars("appid"),vars("AppSecret"),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").sqlFind("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 "
            '根据openid和accesstoken获取用户详情,注意这里这个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
        wb.AppendCookie("openid",openid,360) 
    Else
        e.WriteString(jo.ToString) '在用户浏览器显示错误信息
        Return ""
    End If
Else    
    openid = e.Cookies("openid")
    If  OpenID = "" Then
        Dim ul1 As String  = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state={2}#wechat_redirect"
        Dim ul2 As String = UrlEncode("http://" & vars("域名") & "/" & url) '包装原基本URL
        ul1 = CExp(ul1,vars("AppId"),ul2,"123")
        wb.InsertHTML("<meta http-equiv='Refresh' c>") '跳转到授权链接
        e.WriteString(wb.Build)        
        Return ""
    End If
End If


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


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

重新到项目里把httprequest完整代码,上面函数完整代码,"gz_webshouquan"函数完整代码复制到记事本发上来

 回到顶部