我是这么处理的:
微信授权处理函数 Http_Get_MpOpenid2:
Dim e As RequestEventArgs = Args(0)
Dim Openid As String '微信用户Openid
Dim code As String '微信授权码
Dim state As String '开发者id
Dim wb As weui =args(1)
If e.Cookies.ContainsKey("openid") Then '从cookie中获取微信用户id
Openid = e.Cookies("openid")
Else
If e.host<> "127.0.0.1" Then
If String.IsNullOrEmpty(code) OrElse (e.GetValues.ContainsKey("code") AndAlso code <> e.GetValues("code")) Then
'If e.GetValues.ContainsKey("state") Then state = e.GetValues("state") 'url的值,这里存储微信用户公众号开发者id,如果只维护一个公众号,可以忽略这个
If e.GetValues.ContainsKey("code") Then 'url的值
code = e.GetValues("code")
openid =Functions.Execute("WeChat_GetOpenid_mp",code) ‘自己根据狐表帮助做
End If
End If
Else
Openid ="测试id_XMw4V4s"
End If
End If
If Openid >"" Then
wb.Appendcookie("openid",openid )
Else
Dim ul2 As String
ul2 ="https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri="+ UrlEncode("http://" & e.host & "/" & e.path )+ "&response_type=code&scope=snsapi_base&state="+ mpCorpID +"#wechat_redirect"
ul2=CExp(ul2,“你的id”)
wb.InsertHTML("<meta http-equiv='Refresh' c>") '跳转到授权链接
End If
Return openid
Case "", "default.htm" '首页
调用页面函数
Case "", "default.htm"
e.AsyncExecute = True
Functions.AsyncExecute("Http_wx_default",e)
页面函数:Http_wx_default
Dim e As RequestEventArgs = Args(0)
Dim Openid As String '微信用户Openid
Dim wb As New weui
Openid = Functions.Execute("Http_Get_MpOpenid2",e,wb) '调用函数统一处理授权
If openid="" Then
e.WriteString(wb.Build)
e.Handled = True
Return ""
End If
wb.AddPageTitle("","pageheader","ERP")
wb.AddPageFooter("","pf1","Copyright @ 技术有限公司")
With wb.AddGrid("","g1")
.Add("c1","报告查询", "./images/notepad.png", "filter.htm")
.Add("c12","FAQ管理", "./images/notepad.png", "faqfilter.htm")
.Add("c21","条码扫描", "./images/notepad.png", "test.htm")
.Add("c22","退出", "./images/exit.png", "exit.htm") '退出登录
End With
e.WriteString(wb.Build) '生成网页
e.Handled = True