甜老师:这是我刚放msgbox(e.path)的位置。同时我也显示了一下:在code后面放了msgbox("1:" & UserId) ;在UserId = e.Cookies("userid")后面放了msgbox("2:" & UserId) 。我把cookies清空后,第一次进入微信后,msgbox("1:" & UserId)没有显示,msgbox("2:" & UserId) 显示为空。再次进入入微信,msgbox("1:" & UserId)还是没有显示,msgbox("2:" & UserId) 显示正常的openid。我的理解是第二次进入微信应该是从code中获取出openid,但确是是从cookies中获取出openid的。也就是说清空cookies后,第一次进入微信,正常跳转是没有问题,openid也正常取出来了,但为什么显示不出来呢?
msgbox(e.path) '刚才显示的位置
if e.post = "sxwytx.iego.cn" then
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("GetQYAccessToken1"),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")
msgbox("1:" & UserId)
End If
Else
UserId = e.Cookies("userid") '否则从cookie中提取userid和username
msgbox("2:" & UserId)
If userid = "" andalso e.GetValues.ContainsKey("code") = false then
Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww51c9a9c0c93a7d18&redirect_uri=http%3a%2f%2fsxwytx.iego.cn&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
sb.Append("<meta http-equiv='Refresh' c>") '跳转到授权链接
e.WriteString(sb.ToString)
Return
End If
End If
If userid > "" Then
e.AppendCookie("userid",UserId) '将userid和username存储在Cookie中
Dim dr1 As DataRow = DataTables("人员信息表").SQLFind("人员ID = '" & userid & "'")
If dr1 IsNot Nothing Then
Userrols = dr1("角色")
usergroup = dr1("地市")
End If
End If
Select Case e.Path
Case "ccss.htm"
sb.AppendLine("<meta name='viewport' c>")
sb.AppendLine("您的帐号是:" & userid & "<br/><br/>")
sb.AppendLine("您的角色是:" & Userrols & "<br/><br/>")
sb.AppendLine("您的地市是:" & usergroup & "<br/><br/>")
e.WriteString(sb.ToString)
End Select
end if