Dim e As RequestEventArgs = args(0)
Dim sb As New StringBuilder
sb.AppendLine("<meta name='viewport' c>")
If e.host = Functions.Execute("Get", "公众号", "授权域名") Then '授权测试
MsgBox(1)
Dim UserName As String
Dim OpenID As String
If e.GetValues.ContainsKey("code") Then '如果是通过授权链接跳转而来,就从链接重提取code来获取openid
MsgBox(21)
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, Functions.Execute("Get", "公众号", "AppID"), Functions.Execute("Get", "公众号", "AppSecret"), e.GetValues("code"))
Dim hc As New HttpClient(ul)
Dim jo As JObject = JObject.Parse(hc.GetData)
MsgBox(jo.tostring)
……
Else
MsgBox(22)
UserName = e.Cookies("username") '从cookie获取用户名和openid
OpenID = e.Cookies("openid")
If userName = "" OrElse OpenID = "" Then
MsgBox(221)
Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
ul = CExp(ul, Functions.Execute("Get", "公众号", "AppID"), UrlEncode(Functions.Execute("Get", "公众号", "授权域名")))
MsgBox(ul)
sb.Append("<meta http-equiv='Refresh' c>") '跳转到授权链接
e.WriteString(sb.ToString)
Return Nothing
End If
End If
End If