This commit is contained in:
候学杰 2019-06-11 16:43:08 +08:00
parent f069d47bce
commit db20f3453c
4 changed files with 74 additions and 2 deletions

View File

@ -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'),

View File

@ -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);

35
src/Wechat/Work/User.php Normal file
View File

@ -0,0 +1,35 @@
<?php
namespace Wechat\Work;
class User
{
/**
* @var Work
*/
protected $work;
public function __construct($work)
{
$this->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);
}
}

View File

@ -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);
}
}