Commit eb8f3a44 authored by 张育槟's avatar 张育槟

优化ad域功能

parent b3772e5d
......@@ -16,15 +16,15 @@ class LdapController extends Controller
public $provider=null;
public function __construct()
{
$ad = new \Adldap\Adldap();
$config = [
'hosts'=>[$this->host],
'base_dn'=>$this->dn,
'username' => $this->username,
'password' =>$this->password
];
$ad->addProvider($config);
$this->provider = $ad->connect();
// $ad = new \Adldap\Adldap();
// $config = [
// 'hosts'=>[$this->host],
// 'base_dn'=>$this->dn,
// 'username' => $this->username,
// 'password' =>$this->password
// ];
// $ad->addProvider($config);
// $this->provider = $ad->connect();
}
public function handle(Request $request)
{
......@@ -298,22 +298,37 @@ class LdapController extends Controller
public function getData()
{
$result=$this->provider->search()->ous()->get();
$result = json_decode(json_encode($result),true);
foreach ($result as $value) {
$new_distinguishedname_arr = [];
$distinguishedname = $value['distinguishedname'][0];
$distinguishedname_arr = explode(',',$distinguishedname);
foreach ($distinguishedname_arr as $k=>$v) {
$vv = explode('=',$v);
if ($vv[0] === 'DC') continue;
$new_distinguishedname_arr[] = $vv[1];
}
if ($new_distinguishedname_arr) {
$new_distinguishedname_str=implode('/',$new_distinguishedname_arr);
try {
$data=[];
// $data=['人力资源部/Users_Hoto','IT发展部/Users_Hoto','工程经济专业/Users_Hoto','项目管理部/Users_Hoto','EPC项目管理/项目管理部/Users_Hoto',
// '档案出版管理/项目管理部/Users_Hoto','产品技术中心/IT发展部/Users_Hoto','测试部/产品技术中心/IT发展部/Users_Hoto'];
$result = $this->provider->search()->ous()->get();
$result = json_decode(json_encode($result), true);
foreach ($result as $key=>$value) {
$new_distinguishedname_arr = [];
$distinguishedname = $value['distinguishedname'][0];
$distinguishedname_arr = explode(',', $distinguishedname);
foreach ($distinguishedname_arr as $k => $v) {
$vv = explode('=', $v);
if ($vv[0] === 'DC') continue;
$new_distinguishedname_arr[] = $vv[1];
}
if ($new_distinguishedname_arr) {
$new_distinguishedname_str = implode('/', $new_distinguishedname_arr);
}
//echo $new_distinguishedname_str . "....\r\n";
$data[$key]=$new_distinguishedname_str;
}
echo $new_distinguishedname_str."....\r\n";
$res= ['status' => true,'msg'=>'success'];
//测试部/产品技术中心2/IT发展部
} catch (\Exception $e) {
$res = self::recordLog($e);
}
$res['data']=$data;
Log::info(json_encode($res));
return response()->json($res);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment