Foxtable(狐表)用户栏目专家坐堂 → 钉钉接口


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

主题:钉钉接口

帅哥哟,离线,有人找我吗?
BG小白
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:603 积分:4102 威望:0 精华:0 注册:2019/11/14 23:06:00
钉钉接口  发帖心情 Post By:2021/12/1 2:04:00 [只看该作者]

Dim client As DingTalk.Api.IDingTalkClient = New DingTalk.Api.DefaultDingTalkClient("https://oapi.dingtalk.com/department/list")
Dim req As DingTalk.Api.Request.OapiDepartmentListRequest = New DingTalk.Api.Request.OapiDepartmentListRequest()
req.SetHttpMethod("GET")
Dim rsp As DingTalk.Api.Response.OapiDepartmentListResponse = client.Execute(req, access_token)
DataTables("表B").DataRows.Clear
For i As Integer = 0 To rsp.Department.count -1 
Dim r As Row
r = Tables("表B").AddNew
r("第一列") = rsp.Department.Item(I).id
r("第二列") = rsp.Department.Item(I).name
r("第三列") = rsp.Department.Item(I).Parentid
Next
DataTables("表B").Save
MessageBox.Show("读取完成")

上面的是用钉钉提供的sdk获取到的所有部门信息

Dim ul As String = "https://oapi.dingtalk.com/department/list?access_token={0}"
Dim hc As New HttpClient(CExp(ul,Functions.Execute("access_token")))
Dim jo As JObject = JObject.Parse(hc.GetData())
If jo("errcode") = "0" Then
    MessageBox.Show("成功")
Else
    MessageBox.Show(jo.ToString)
End If

怎么用上面这种获取所有部门信息呢?红色的部分不知道该怎么实现?获取到的只有根部门,不是所有部门,要获得所有部门必须提供父部门dept_id
[此贴子已经被作者于2021/12/1 2:09:40编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
z769036165
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:760 积分:5430 威望:0 精华:0 注册:2012/10/5 21:53:00
  发帖心情 Post By:2021/12/1 8:28:00 [只看该作者]

建立一个内部函数-同步部门,用递归循环调用
Functions.Execute("同步部门",1)

同步部门:
Dim id As Integer = args(0)
Dim ur As String = "https://oapi.dingtalk.com/topapi/v2/department/listsub"
Dim hc As New HttpClient(ur)
hc.FormData.Add("access_token",Functions.Execute("access_token"))
hc.FormData.Add("dept_id",id)
hc.FormData.Add("language","zh_CN")
Dim jo As JObject = JObject.Parse(hc.GetData())
Dim dt As DataTable = DataTables("dept")
Dim w As DataRow
If jo("errcode") = "0" Then
    For Each jt As JToken In jo("result")
            w = dt.Find("dept_id = '"& jt("dept_id").tostring &"'")
            If w IsNot Nothing Then
                w("name") = jt("name").tostring
                w("parent_id") = jt("parent_id").tostring
                Functions.Execute("同步部门",jt("dept_id").tostring)
            Else
                w = dt.AddNew
                w("dept_id") = jt("dept_id").tostring
                w("name") = jt("name").tostring
                w("parent_id") = jt("parent_id").tostring
                Functions.Execute("同步部门",jt("dept_id").tostring)
            End If
    Next
else
    Output.show(jo("errmsg").Tostring)
End If
[此贴子已经被作者于2021/12/1 8:30:01编辑过]

 回到顶部