Dim e As RequestEventArgs = args(0)
Dim UserId As String
Dim sb As New StringBuilder
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)
MessageBox.Show("a")
If jo("UserId") IsNot Nothing Then
UserId = jo("UserId")
End If
Else
UserId = e.Cookies("userid") '否则从cookie中提取userid和username
End If
If UserId > "" then'授权成功
e.AppendCookie("userid",UserId) '将userid和username存储在Cookie中
Return UserId
ElseIf e.GetValues.ContainsKey("code") = False Then '如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
'Dim ul1 As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=SCOPE&agentid=AGENTID&state=STATE#wechat_redirect"
'Dim ul2 As String = UrlEncode("http://www.whtcxx.com")
'ul1 = CExp(ul1,"wxc919804411b0d36c",ul2)
'sb.Append("<meta http-equiv='Refresh' c>") '跳转到授权链接
Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc919804411b0d36c&redirect_uri=http%3a%2f%2fwww.whtcxx.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
---------------------------------------------------------------
http://www.whtcxx.com/?code=011zW6e92AT00S0Z01d92PCbe92zW6e7&state=123
每次卡在这里网页就不动了
[此贴子已经被作者于2018/4/20 19:47:18编辑过]