以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  企业微信获取部门报错  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=148592)

--  作者:lshshlxsh
--  发布时间:2020/4/10 17:08:00
--  企业微信获取部门报错

图片点击可在新窗口打开查看此主题相关图片如下:aa.png
图片点击可在新窗口打开查看

麻烦老师帮看一下 我根据帮助中复制过去 获取部门报错  这个是什么原因导致的?

Static CreateTime As Date \'记录最近一次生成access_token的时间
Static
AccessTocken As String \'记录最近一次生成的access_token
Dim
CorpID As String"ww7deed3af842576ed" \'企业号的CorpID
Dim
Secret As String = "sO7RjwoisX82kB_gcRY4isEU8ZC6sJVcGs6CDlz8Nkc" \'管理组的Secret
Dim
tp As TimeSpan = Date.Now - CreateTime
If
tp.TotalSeconds > 3600 Then
    Dim url As String = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}"
    Dim hc As New HttpClient(CExp(url, CorpID, Secret))
    Dim ret As String = hc.GetData()
    If ret = "" Then \'
如果失败,再尝试一次
        hc.GetData()
    End If
    CreateTime = Date.Now()
    Dim jo As JObject = JObject.Parse(ret)
    If jo("access_token") IsNot Nothing Then
       
AccessTocken = jo("access_token")
    Else
        MessageBox.show("获取access_token失败,原因:" & vbcrlf & jo.ToString)
    End If

End
If
Return
AccessTocken



Dim ur As String = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={0}&id={1}"
Dim
hc As New HttpClient(CExp(ur,Functions.Execute("GetQYAccessToken"),1))
Dim
jo As JObject = JObject.Parse(hc.GetData())
If
jo("errcode") = "0" Then
    DataTables("Departments").DataRows.Clear()
    For Each jt As JToken In jo("department")
        Dim dr As DataRow= DataTables("Departments").AddNew()
        dr("id") = jt("id")
        dr("name") = jt("name")
        dr("parentid") = jt("parentid")
        dr("order") = jt("order")
        dr.Save
   
Next

Else

    MessageBox.Show(jo.Tostring)

End
If
[此贴子已经被作者于2020/4/10 17:09:36编辑过]

--  作者:有点蓝
--  发布时间:2020/4/10 17:14:00
--  
Dim ur As String = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={0}&id={1}"
Dim
 hc As New HttpClient(CExp(ur,Functions.Execute("GetQYAccessToken"),1))
dim res As string = hc.GetData()
msgbox(res) 这里显示什么内容?
Dim jo As JObject = JObject.Parse(res)