diff --git a/config/wx.php b/config/wx.php index 6b71d0a..f2aaed2 100644 --- a/config/wx.php +++ b/config/wx.php @@ -5,9 +5,13 @@ return [ */ 'work' => [ //企业ID - 'corp_id' => env('WECHAT_WORK_CORP_ID','ww9ed271946b8fc4a4'), + 'corp_id' => env('WECHAT_WORK_CORP_ID', 'ww9ed271946b8fc4a4'), //企业内各个应用的 secrets 'agents' => [ + 'default' => [ + 'id' => env('WECHAT_WORK_AGENT_ID'), + 'secret' => env('WECHAT_WORK_AGENT_SECRET'), + ], 'notify' => [ 'id' => '1000015', 'secret' => env('WECHAT_WORK_NOTIFY_SECRET'), diff --git a/src/Wechat/Work/Base.php b/src/Wechat/Work/Base.php index 0805967..57f9b63 100644 --- a/src/Wechat/Work/Base.php +++ b/src/Wechat/Work/Base.php @@ -21,6 +21,7 @@ class Base 'base_uri' => 'https://qyapi.weixin.qq.com/cgi-bin/', 'timeout' => '3', ]); + $this->agent('default'); } public function agent($key) @@ -29,11 +30,21 @@ class Base return $this; } + /** + * 获取当前使用的agent + * @return mixed + */ public function getAgentId() { return $this->getAgentConfig()['id']; } + /** + * POST 请求 ,传递的body为json格式 + * @param $uri + * @param array|null $params + * @return Request + */ public function transformForJsonRequest($uri, array $params = null) { $uri = new Uri($uri); @@ -48,6 +59,12 @@ class Base return $request; } + /** + * GET 请求,不自动附加 access token,用于获取access token 接口 + * @param $uri + * @param $params + * @return Request + */ public function transformForAccessTokenRequest($uri, $params) { $uri = new Uri($uri); @@ -59,6 +76,12 @@ class Base return $request; } + /** + * GET 请求附带上 access token + * @param $uri + * @param $params + * @return Request + */ public function transformForGetRequest($uri, $params) { $uri = new Uri($uri); diff --git a/src/Wechat/Work/User.php b/src/Wechat/Work/User.php new file mode 100644 index 0000000..5b86630 --- /dev/null +++ b/src/Wechat/Work/User.php @@ -0,0 +1,35 @@ +work = $work; + } + + public function getUserByCode($code) + { + $request = $this->work->transformForGetRequest('user/getuserinfo', [ + 'code' => $code, + ]); + return $this->work->request($request); + } + + public function get($id) + { + $request = $this->work->transformForGetRequest('user/get', [ + 'userid' => $id, + ]); + return $this->work->request($request); + } + +} \ No newline at end of file diff --git a/src/Wechat/Work/Work.php b/src/Wechat/Work/Work.php index 7c417cb..64c4da4 100644 --- a/src/Wechat/Work/Work.php +++ b/src/Wechat/Work/Work.php @@ -32,8 +32,18 @@ class Work extends Base * 小程序接口 * @return Miniprogram */ - public function miniProgram(){ + public function miniProgram() + { return new Miniprogram($this); } + /** + * 用户接口 + * @return User + */ + public function user() + { + return new User($this); + } + } \ No newline at end of file