If e.host = "ctterp.vipgz1.idcfengye.com" 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
Dim Verified As Boolean
Dim dr As DataRow = DataTables("WXUsers").Find("userid ='" & 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=&&&&&&&&redirect_uri=http%3a%2f%2fctterp.vipgz1.idcfengye.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("欢迎" & UserName & " , <a href='http://&&&&&.idcfengye.com'>刷新页面</a>")
End If
e.WriteString(sb.ToString)
End If
Select Case e.Path
Case "", "default.htm" '首页
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", "fdphoto.htm")
.Add("c22","退出", "./images/exit.png", "exit.htm") '退出登录
End With
e.WriteString(wb.Build) '生成网页
Case "test.htm",""
wb.AppendHTML("<script src='http://res.wx.qq.com/open/js/jweixin-1.0.0.js'></script>",True) '引入JS-SDK库
wb.AppendHTML("<script src='./lib/jssdk.js'></script>") '引入脚本文件
'在页面注入权限验证配置
Dim st As New Date(1970,1,1,8,0,0)
Dim appid As String = "wx9f8a&&&&&8" 'CorpID
Dim timestamp As Integer = CInt((Date.Now - st).TotalSeconds()) '时间戳
Dim noncestr As String = Rand.NextString(16) '随机字符
Dim url As String = e.Request.URL.ToString '当前页面地址
Dim signature As String = Functions.Execute("GetJsSignature", noncestr, timestamp, url) '生成权限验证签名
Dim cfg As String = "wx.config({appId:'{0}',timestamp:{1},nonceStr:'{2}',signature:'{3}',jsApiList:['scanQRCode']});"
wb.AppendHTML("<script>" & CExp(cfg,appid,timestamp,noncestr,signature) & "</script>",True)
'开始正常生成网页内容
wb.AddForm("","form1","test.htm")
With wb.AddInputGroup("form1","ipg1","产品输入")
.AddInput("product","产品","text")
With .AddInputCell("ic1")
.AddLabel("lbh","编号",0)
.AddInput("number","text",1)
.AddVcodeButton("scan","扫码输入",2) '增加二维码扫描按钮,2表示显示在右边
End With
End With
With wb.AddButtonGroup("form1","btg1",True)
.Add("btn1", "确定", "submit")
End With
e.WriteString(wb.Build) '生成网页
End Select