From bfb5395b56eb752e71f16bc29ad9a71547b4937a Mon Sep 17 00:00:00 2001 From: outlaws Date: Sun, 19 Sep 2021 23:51:39 +0800 Subject: [PATCH] Fixed w7corp/easywechat#2205 (#225) --- src/Providers/WeWork.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Providers/WeWork.php b/src/Providers/WeWork.php index c36e85b..a361774 100644 --- a/src/Providers/WeWork.php +++ b/src/Providers/WeWork.php @@ -13,6 +13,15 @@ class WeWork extends Base protected bool $detailed = false; protected ?int $agentId; protected ?string $apiAccessToken; + protected string $baseUrl = 'https://qyapi.weixin.qq.com'; + + public function __construct(array $config) + { + parent::__construct($config); + if ($this->getConfig()->has('base_url')) { + $this->baseUrl = $this->getConfig()->get('base_url'); + } + } /** * @param int $agentId @@ -26,6 +35,11 @@ public function setAgentId(int $agentId) return $this; } + public function getBaseUrl() + { + return $this->baseUrl; + } + public function userFromCode(string $code): User { $token = $this->getApiAccessToken(); @@ -128,7 +142,7 @@ protected function getApiAccessToken() protected function getUserId(string $token, string $code): array { $response = $this->getHttpClient()->get( - 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo', + $this->baseUrl . '/cgi-bin/user/getuserinfo', [ 'query' => array_filter( [ @@ -160,7 +174,7 @@ protected function getUserId(string $token, string $code): array protected function getUserById(string $userId): array { $response = $this->getHttpClient()->post( - 'https://qyapi.weixin.qq.com/cgi-bin/user/get', + $this->baseUrl . '/cgi-bin/user/get', [ 'query' => [ 'access_token' => $this->getApiAccessToken(), @@ -211,7 +225,7 @@ protected function mapUserToObject(array $user): User protected function createApiAccessToken(): string { $response = $this->getHttpClient()->get( - 'https://qyapi.weixin.qq.com/cgi-bin/gettoken', + $this->baseUrl . '/cgi-bin/gettoken', [ 'query' => array_filter( [