这段代码是取得当前用户的userid
If e.host = "qwe.ngrok.cc" 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("统计").Find("userid ='" & UserId & "'") '根据openid找出对应的行
If UserId > "" AndAlso dr IsNot Nothing '授权成功
Verified = True
UserName = dr("姓名")
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%2fqwe.ngrok.cc&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://qwe.ngrok.cc'>刷新页面</a>")
End If
e.WriteString(sb.ToString)
End If
这段是通过UserId 来筛选考勤数据!
Select Case e.Path
Case "list.htm"
Dim page As Integer = 0 '默认page为0,显示第一页
Dim pageRows As Integer = 30 '每页10行
If e.GetValues.ContainsKey("page") Then '如果地址中有page参数
Integer.TryParse(e.GetValues("page"), page) '提取page参数
End If
Dim StartRow As Integer = page * pageRows '此页第一行
Dim EndRow As Integer = (page + 1) * pageRows - 1 '此页最后一行
Dim lst As List(of DataRow) = DataTables("统计").Select("userid ='" & UserId & "'","日期 Desc") '按日期顺序显示
If StartRow > lst.Count -1 Then
e.WriteString("已经是最后一页!")
Return
End If
EndRow = Math.Min(EndRow, lst.Count - 1) '这是必须的
Dim sb As New StringBuilder
Dim nms() As String = {"姓名","日期","星期","t1","t2","t3","t4","t6"}
sb.AppendLine("<Table border='1'>")
sb.AppendLine("<caption>考勤浏览<caption></br>")
sb.Append("<tr>")
For Each nm As String In nms
sb.Append("<td>" & nm & "</td>")
Next
sb.AppendLine("</tr>")
For r As Integer = StartRow To EndRow
sb.Append("<tr>")
For Each nm As String In nms
sb.Append("<td>" & lst(r)(nm) & "</td>")
Next
sb.AppendLine("</tr>")
Next
sb.AppendLine("</Table></br></br>")
If page > 0 Then
sb.Append("<a href='list.htm?page=" & page - 1 & "'>上一页</a> ")
End If
If EndRow < lst.Count -1 Then
sb.Append("<a href='list.htm?page=" & page + 1 & "'>下一页 </a>" )
End If
e.WriteString(sb.ToString)
End Select
要实现效果是通过企业号的微信id来查询每个员工自己的考勤数据!代码我已经分开测试成功!就是不知道怎么合在一起了!惭愧啊!
[此贴子已经被作者于2017/3/9 14:53:59编辑过]