$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以,分割
php递归获取钉钉所有部门ID
最新推荐文章于 2024-03-07 11:22:52 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)