php递归获取钉钉所有部门ID

4 篇文章 1 订阅
该博客主要介绍了一个PHP方法,用于通过钉钉API递归获取指定部门及其所有子部门的ID。`handleDeptIds`函数接收一个部门ID列表,并将它们连接成逗号分隔的字符串。同时,它还调用`getListsubid`函数获取每个部门的子级部门ID,进一步处理这些ID。整个过程利用了递归,确保获取到所有层级的部门ID。
摘要由CSDN通过智能技术生成
$str = '';
$res = $this->getListsubid(['dept_id' => 1]);// 根数据
$idsStr = $this->handleDeptIds($res, $str);


// 处理数据
protected function handleDeptIds(&$res, &$str)
    {
        if (! empty($res['dept_id_list'])) {
            foreach($res['dept_id_list'] as $key => $dept_id) {
                $str .= $dept_id.',';
                $res = $this->getListsubid(['dept_id' => $dept_id]);
                $this->handleDeptIds($res, $str);
                $this->line($dept_id);
            }
            return $str;
        }

    }
    // 根据部门ID获取其子级部门ID
    protected function getListsubid(array $params = [])
    {
        $url = "https://oapi.dingtalk.com/topapi/v2/department/listsubid"."?access_token=".$this->access_token;
        $res = common::curl($url, $params, true);
        if ($res['errcode'] == 0 && $res['errmsg'] == 'ok') {
            return $res['result'];
        }
        $this->info(json_encode($res, JSON_UNESCAPED_UNICODE));
    }

// 打印$idsStr 会返回所有部门的id以,分割
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

PHP开光程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值