Foxtable(狐表)用户栏目专家坐堂 → 微信授权问题!


  共有2972人关注过本帖树形打印复制链接

主题:微信授权问题!

帅哥,在线噢!
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106241 积分:540328 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/11/30 16:09:00 [显示全部帖子]

验证函数:
Dim e As RequestEventArgs = args(0)
Dim path As RequestEventArgs = args(1)
Dim UserId As String
Dim sb As New StringBuilder
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
If UserId  > "" then'授权成功
    e.AppendCookie("userid",UserId) '将userid和username存储在Cookie中
    Return UserId
ElseIf e.GetValues.ContainsKey("code") = False Then '如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
   
    Dim ul1 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://wx.tt.com.cn/" path)
    ul1 = CExp(ul1,"wxc47938dd3fd523d4",ul2,"123")
    sb.Append("<meta http-equiv='Refresh' c>") '跳转到授权链接

     e.WriteString(sb.ToString)
    Return ""
End If


kq函数:
Dim e As RequestEventArgs = args(0)
Dim wb As New weui
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "SELECT * From {wxkq}"
dt = cmd.ExecuteReader
Dim userid = Functions.Execute("order",e,"kq.htm")
  If userid > "" Then
    With wb.AddTable("","Table1")
        '按日期顺序列出考勤明细
        .CreateFromDataTable(dt,False,"userid ='" & UserId & "'","日期","姓名","日期","星期","t1","t2")
    End With
e.WriteString(wb.Build)
End If


 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106241 积分:540328 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/11/30 17:24:00 [显示全部帖子]

报什么错?如果传入8楼的参数,不可能报错

 回到顶部
帅哥,在线噢!
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106241 积分:540328 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/11/30 18:02:00 [显示全部帖子]

好吧,忘记改类型了图片点击可在新窗口打开查看

Dim path As string = args(1)

 回到顶部
帅哥,在线噢!
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106241 积分:540328 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/12/1 15:11:00 [显示全部帖子]

一是为了获取userid,其次如果无法获取userid,就会重新生成授权页面,然后跳转

 回到顶部