123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace app\common\service;
- use app\extend\Dingtalk\Sample;
- /**
- * 钉钉服务类
- */
- class DingtalkService
- {
- public static function get_obj()
- {
- require_once env('root_path') . '/vendor/dingapi/TopSdk.php';
- date_default_timezone_set('Asia/Shanghai');
- $c = new \DingTalkClient(\DingTalkConstant::$CALL_TYPE_OAPI, \DingTalkConstant::$METHOD_POST, \DingTalkConstant::$FORMAT_JSON);
- return $c;
- }
- /**
- * 获取部门列表
- *
- * @param string $parent_id 父部门ID
- * @return mixed
- */
- public static function department_listsub($parent_id)
- {
- $accessToken = Sample::main()['accessToken'];
- $c = self::get_obj();
- $req = new \OapiV2DepartmentListsubRequest;
- $req->setDeptId($parent_id);
- $resp = $c->execute($req, $accessToken, "https://oapi.dingtalk.com/topapi/v2/department/listsub");
- return $resp;
- }
- /**
- * 获取部门详情
- *
- * @param string $dept_id 部门ID
- * @return mixed
- */
- public static function department_get($dept_id)
- {
- $accessToken = Sample::main()['accessToken'];
- $c = self::get_obj();
- $req = new \OapiV2DepartmentListsubRequest;
- $req->setDeptId($dept_id);
- $resp = $c->execute($req, $accessToken, "https://oapi.dingtalk.com/topapi/v2/department/get");
- return $resp;
- }
- /**
- * 获取部门用户详情
- *
- * @param string $dept_id 部门ID
- * @return mixed
- */
- public static function user_list($dept_id)
- {
- $accessToken = Sample::main()['accessToken'];
- $c = self::get_obj();
- $req = new \OapiV2UserListRequest;
- $req->setDeptId($dept_id);
- $req->setCursor("0");
- $req->setSize("100");
- $resp = $c->execute($req, $accessToken, "https://oapi.dingtalk.com/topapi/v2/user/list");
- return $resp;
- }
- /**
- * 查询用户详情
- *
- * @param string $userid 用户的userId
- * @return mixed
- */
- public static function user_get($userid)
- {
- $accessToken = Sample::main()['accessToken'];
- $c = self::get_obj();
- $req = new \OapiV2UserGetRequest;
- $req->setUserid($userid);
- $resp = $c->execute($req, $accessToken, "https://oapi.dingtalk.com/topapi/v2/user/get");
- return $resp;
- }
- /**
- * 通过免登码获取用户信息
- *
- * @param string $code 免登授权码
- * @return mixed
- */
- public static function get_user_info($code)
- {
- $accessToken = Sample::main()['accessToken'];
- $c = self::get_obj();
- $req = new \OapiV2UserGetuserinfoRequest;
- $req->setCode($code);
- $resp = $c->execute($req, $accessToken, "https://oapi.dingtalk.com/topapi/v2/user/getuserinfo");
- return $resp;
- }
- }
|