Dim e As RequestEventArgs = args(0)
Dim url As String = e.path 'e.Request.url.tostring
Dim g As String = ""
For Each key As String In e.GetValues.Keys
If g IsNot Nothing Then g = g & "&"
g = g & key & "=" & e.GetValues(key)
Next
If g IsNot Nothing Then g = "?" & g '解决苹果手机 通知信息会重置 用户帐号 导致无法获取用户的问题
Dim jo As JObject
Dim UserId As String = Nothing
Dim UserInfo As String = Nothing
Dim sb As New StringBuilder
msgbox(url)
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}"
"https://qyapi.weixin.qq.com/cgi-bin/user/list_id?access_token=ACCESS_TOKEN" 我看新的好像这样 该如何调整呢
ul = CExp(ul, GetAccessToken, e.GetValues("code"))
Dim hc As New HttpClient(ul)
jo = JObject.Parse(hc.GetData)
If jo("UserId") IsNot Nothing Then
UserId = jo("UserId")
UserInfo = GetUsers(jo("UserId"))
e.AppendCookie("UserId", UserId) '用户userid存储在Cookie中
e.AppendCookie("UserInfo", UserInfo) '用户信息存储在Cookie中
End If
Else
If e.Cookies("UserId") IsNot Nothing And e.Cookies("UserInfo") IsNot Nothing Then
UserId = e.Cookies("UserId")
UserInfo = e.Cookies("UserInfo")
Else
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 CorpID As String = Functions.Execute("Get", "企业微信", 0) '企业号的CorpID
Dim port As String = Nothing
If Functions.Execute("Get", "基本信息", 1) <> 80 Then port = ":" & Functions.Execute("Get", "基本信息", 1)
Dim kxym As String = Functions.Execute("Get", "基本信息", 2) & port '域名+端口
Dim ul2 As String = web.HttpUtility.UrlEncode("http://" & kxym & "/" & url & g)
ul1 = CExp(ul1, CorpID, ul2)
'msgbox(ul1)
sb.Append("<meta http-equiv='Refresh' c>") '跳转到授权链接
e.WriteString(sb.ToString)
Return Nothing
End If
End If
If UserId IsNot Nothing And UserInfo IsNot Nothing Then
Return UserInfo
End If
Return Nothing