以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 符合条件后自动跳转怎么写? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=161171) |
|
-- 作者:南望 -- 发布时间:2021/3/8 23:47:00 -- 符合条件后自动跳转怎么写? 网页详细授权,符合条件后自动跳转到DEFAULT.HTM(自定义函数)怎么写?下面的两种方法都是不断的循环跳转怎么回事? If OpenID > "" And UserName > "" Then \'这里可以做进一步的权限判断 \'sb.AppendLine("欢迎" & UserName & "光临, <a href=\'http://wexin.foxtable.com\'>刷新页面</a>") wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页 e.WriteString(wb.Build) Return "" end if
|
|
-- 作者:南望 -- 发布时间:2021/3/9 0:22:00 -- 上面的代码也放到自定义函数里了 |
|
-- 作者:有点蓝 -- 发布时间:2021/3/9 8:45:00 -- 贴出httprequest和函数的完整代码 |
|
-- 作者:南望 -- 发布时间:2021/3/9 10:20:00 -- HTTPREQUEST代码如下: Functions.Execute("wx",e) ‘WX函数就是网页详情授权代码,调试没问题! Select Case e.path Case "logon.htm" \'登录页面 Functions.Execute("login",e) Case "exit.htm" \'退出登录 Functions.Execute("exit",e) \'Case "", "default.htm" \'首页 Case "default.htm" \'首页 Functions.Execute("default",e) Case "list.htm" Functions.Execute("List",e) Case "addnew.htm" Functions.Execute("AddNew",e) Case "edit.htm" Functions.Execute("Edit",e) Case "delete.htm" Functions.Execute("Delete",e) Case "handle.htm" Functions.Execute("handle",e) Case "tongji.htm" Functions.Execute("Statistics",e) Case "filter.htm" Functions.Execute("Filter",e) Case "wefox" If e.Request.HttpMethod.ToUpper = "GET" If Functions.Execute("VerifySignature",e) Then e.WriteString(e.GetValues("echostr")) End If End If End Select |
|
-- 作者:有点蓝 -- 发布时间:2021/3/9 10:23:00 -- 1楼代码在哪个函数?贴出函数完整代码 |
|
-- 作者:南望 -- 发布时间:2021/3/9 10:32:00 -- 1楼的代码在WX自定义函数中,代码与帮助中“网页详情授权“一模一样,只是下面满足条件自动跳转实现不了。 我改成1楼的代码后通过授权就不断的刷新页面,不能显示出default.htm页面 If OpenID > "" And UserName > "" Then \'这里满足条件时需要自动跳转到DEFAULT.HTM页,如何实现?
sb.AppendLine("欢迎" & UserName & "光临, <a href=\'自己的域名\'>刷新页面</a>") Else sb.AppendLine("你无权访问本系统") End If End If [此贴子已经被作者于2021/3/9 10:35:56编辑过]
|
|
-- 作者:南望 -- 发布时间:2021/3/9 11:17:00 -- 蓝版帮忙看看吧 |
|
-- 作者:有点蓝 -- 发布时间:2021/3/9 11:20:00 -- 贴出完整代码 |
|
-- 作者:南望 -- 发布时间:2021/3/9 11:31:00 -- Dim sb As New StringBuilder sb.AppendLine("<meta name=\'viewport\' c>") If e.host = "wexin.foxtable.com" Then \'授权测试 Dim UserName As String Dim OpenID As String 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,"wx8acdb7df5beb68fd","dec0df8a469518df30e9bdef0758c678",e.GetValues("code")) Dim hc As new HttpClient(ul) Dim jo As JObject = JObject.Parse(hc.GetData) If jo("openid") IsNot Nothing Then \'如果获取openid成功(成功的话,还会同时返回一个accesstiken,用于获取用户详情) OpenID = jo("openid") Dim dr As DataRow = DataTables("WXUsers").Find("openid =\'" & Openid & "\'") If dr IsNot Nothing Then UserName = dr("nickname") Else ul = "https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN " \'根据openid和accesstoken获取用户详情,注意这里这个accesstoken不是普通accesston,只能用于网页授权 hc = New HttpClient(CExp(ul, jo("access_token"), OpenId)) jo = jo.Parse(hc.GetData) If jo("openid") IsNot Nothing Then UserName = jo("nickname") dr = DataTables("WXUsers").AddNew() Dim nms() As String = {"openid","nickname","sex","city","country","province","headimgurl"} \'"" For Each nm As String In nms dr(nm) = jo(nm) Next dr.Save Else e.WriteString(jo.ToString) \'在用户浏览器显示错误信息 Return End If End If e.AppendCookie("username",UserName) \'用户名和openid存储在Cookie中 e.AppendCookie("openid",OpenID) Else e.WriteString(jo.ToString) \'在用户浏览器显示错误信息 Return End If Else UserName = e.Cookies("username") \'从cookie获取用户名和openid OpenID = e.Cookies("openid") If userName = "" OrElse OpenID = "" 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_userinfo&state=123#wechat_redirect" sb.Append("<meta http-equiv=\'Refresh\' c>") \'跳转到授权链接 e.WriteString(sb.ToString) Return End If End If If OpenID > "" And UserName > "" Then \'满足条件如何自动跳转(非手动单击链接)到default.htm sb.AppendLine("欢迎" & UserName & "光临, <a href=\'http://wexin.foxtable.com\'>刷新页面</a>") Else sb.AppendLine("你无权访问本系统") End If End If e.WriteString(sb.ToString) |
|
-- 作者:有点蓝 -- 发布时间:2021/3/9 11:46:00 -- sb.AppendLine("<meta http-equiv=\'Refresh\' content=\'0; url=/default.htm\'>")
|