以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 简单授权 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=145766) |
||||
-- 作者:shyilin -- 发布时间:2020/2/6 20:27:00 -- 简单授权 If e.host = "xxxxxxxxxx" Then \'需要授权才能访问的域名 Dim UserId As String Dim UserName As String Dim sb As New StringBuilder sb.AppendLine("<meta name=\'viewport\' c>") 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}" ul = CExp(ul,Functions.Execute("GetQYAccessToken"),e.GetValues("code")) Dim hc As new HttpClient(ul) Dim jo As JObject = JObject.Parse(hc.GetData) If jo("UserId") IsNot Nothing Then UserId = jo("UserId") End If Else UserId = e.Cookies("userid") \'否则从cookie中提取userid和username End If \'MessageBox.Show(UserId) Dim Verified As Boolean Dim dr As DataRow = DataTables("姓名").Find("编号 =\'" & UserId & "\'") \'根据openid找出对应的行 If UserId > "" AndAlso dr IsNot Nothing AndAlso dr("permit") = True \'授权成功 Verified = True UserName = dr("name") e.AppendCookie("userid",UserId) \'将userid和username存储在Cookie中 ElseIf e.GetValues.ContainsKey("code") = False Then \'如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接 Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxxxxx&redirect_uri=http%3a%2f%2fxxxxxxxx%2fdefault.htm&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("你无权访问本系统") e.WriteString(sb.ToString) Else wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") e.WriteString(wb.Build) Return \'这个要怎么写,网页出不来呢,一直在刷新 End If End If 后面授权成功后进不到首页 default.htm代码: Dim e As RequestEventArgs = args(0)
Dim wb As WeUI=args(1) With wb.AddGrid("","g1") .Add("c1","领用单", "./images/lingyong.png","lingyongqingding.htm") .Add("c4","领用审核", "./images/lingyongsh.png","lingyongshenheqingdang.htm") .Add("c2","表单查询", "./images/chaxunbd.png", "filter.htm") .Add("c3","系数查询", "./images/chaxunxs.png", "XSCX1.htm") End With e.WriteString(wb.Build) [此贴子已经被作者于2020/2/6 20:55:24编辑过]
|
||||
-- 作者:shyilin -- 发布时间:2020/2/6 20:45:00 -- 有没有哪个老师在呢,帮忙看看呢 |
||||
-- 作者:shyilin -- 发布时间:2020/2/6 20:56:00 -- wb.InsertHTML("<meta http-equiv=\'Refresh\' c>"),写这个就一直在刷新的状态 |
||||
-- 作者:shyilin3 -- 发布时间:2020/2/7 8:44:00 -- 有老师在吗? |
||||
-- 作者:有点蓝 -- 发布时间:2020/2/7 9:29:00 -- httprequest事件全部代码放到txt文件发上来看看 |
||||
-- 作者:shyilin3 -- 发布时间:2020/2/7 9:46:00 -- 稍等,我等一下弄一下 [此贴子已经被作者于2020/2/7 9:55:04编辑过]
|
||||
-- 作者:shyilin -- 发布时间:2020/2/7 10:14:00 --
|
||||
-- 作者:有点蓝 -- 发布时间:2020/2/7 10:48:00 -- If Verified = False Then sb.AppendLine("你无权访问本系统") e.WriteString(sb.ToString) Elseif e.Path = "" wb.InsertHTML("<meta http-equiv=\'Refresh\' c>")\'直接跳转到首页 e.WriteString(wb.Build) \'生成网页 Return \'必须的 End If
|
||||
-- 作者:shyilin -- 发布时间:2020/2/7 11:20:00 -- 好的,谢谢老师 |
||||
-- 作者:shyilin -- 发布时间:2020/2/7 17:25:00 -- 老师我用msgbox查了一下,每次登陆的时候会弹出好几次UserId,验证不是一次的吗?怎么会好多次呢,这个很影响登陆速度,能再帮我调试一下吗? |