Dim fl As String = "e:\baidu\web\" & e.path '设置网页根目录
If filesys.FileExists(fl)
Dim idx As Integer = fl.LastIndexOf(".")
Dim ext As String = fl.SubString(idx)
Select Case ext
Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar"
e.WriteFile(fl)
Return '这里必须返回
End Select
End If
Select Case e.path
Case "abc","abc1" '接口配置
If e.Request.HttpMethod.ToUpper = "GET"
If Functions.Execute("VerifySignature",e) Then
e.WriteString(e.GetValues("echostr"))
End If
End If
Case "s50000_message.htm" '用户留言
Functions.Execute("s50000_message",e)
End Select
If e.host = "abc.ngrok.cc" Then '需要授权才能访问的域名
Dim OpenID As String
Dim sb As New StringBuilder
sb.AppendLine("<meta name='viewport' c>")
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,"wx4718459301f2db8f","827cafff19659d5b93e8c7663db3999a",e.GetValues("code"))
Dim hc As new HttpClient(ul)
Dim jo As JObject = JObject.Parse(hc.GetData)
If jo("openid") IsNot Nothing Then
OpenID = jo("openid")
e.AppendCookie("openid",OpenID) '将openid存储在Cookie中
End If
Else
OpenId = e.Cookies("openid") '否则从cookie中提取openid
End If
Dim Verified As Boolean
Dim dr As DataRow = DataTables("Users").Find("openid ='" & OpenID & "'") '根据openid找出对应的行
If OpenId > "" AndAlso dr IsNot Nothing Then '授权成功
Verified = True
ElseIf e.GetValues.ContainsKey("code") = False Then '如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8acdb7df5beb68fd&redirect_uri=http%3a%2f%2fwexin.foxtable.com&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
sb.Append("<meta http-equiv='Refresh' c>") '跳转到授权链接
e.WriteString(sb.ToString)
Return
End If
If Verified = False Then
sb.AppendLine("你无权访问本系统")
Else
sb.AppendLine("Foxtable欢迎您, <a href='http://wexin.foxtable.com'>刷新页面</a>")
End If
e.WriteString(sb.ToString)
End If