Dim wb As New weui
'身份验证
Dim CorpID,DN As String '企业ID及管理组的Secret
Dim dr As DataRow = DataTables("应用参数表").Find("应用类别 = '企业微信' and 应用参数 = 'CorpID'")
If dr IsNot Nothing Then
CorpID = dr("参数值")
End If
dr = DataTables("应用参数表").Find("应用类别 = '企业微信' and 应用参数 = '可信域名'")
If dr IsNot Nothing Then
DN = dr("参数值")
End If
If e.host = DN Then '需要授权才能访问的可信域名
Dim UserId As String
Dim UserName As String
Dim Password,NewsName 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
Dim Verified As Boolean
Dim dr2 As DataRow = DataTables("Users").Find("userid ='" & UserId & "'") '根据openid找出对应的行
If UserId > "" AndAlso dr2 IsNot Nothing AndAlso dr2("permit") = True '授权成功
Verified = True
UserName = dr2("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={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state={2}#wechat_redirect"
Dim ul2 As String = UrlEncode("http://" & DN)
ul = CExp(ul,CorpID,ul2,"123")
sb.Append("<meta http-equiv='Refresh' c>") '跳转到授权链接
e.WriteString(sb.ToString)
Return
End If
'身份验证通过后才能访问需要的网页
If Verified = True Then
'开始生成网页
Select Case e.path
Case "default.htm","" '首页默认网页
Functions.Execute("default",e)
Case "dd_table.htm"
Functions.Execute("dd_table",e)
.......
End Select
End If
End If
在手机上如果是打开企业微信后找到应用登录点击可以正常访问手机主页上的各相关的网页,
但是如果是从微信上收到的链接比如"http://www.abc.com/dd_table.htm"点击这个链接就无法打开这个指定的网页,什么也没显示
微信名也已加入了企业微信,在Users表中也勾选了permit的,是什么原因?
谢谢!