From f85f55bd77cb5db857bca7afa08967b08bc6bdb8 Mon Sep 17 00:00:00 2001
From: wuliangbo
Date: Thu, 14 Jul 2022 16:56:45 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 3 +-
composer.json | 13 +-
src/BasicService/ContentSecurity/Client.php | 19 +-
src/BasicService/Jssdk/Client.php | 50 +-
src/BasicService/Media/Client.php | 13 +-
src/BasicService/QrCode/Client.php | 21 +-
src/BasicService/Url/Client.php | 5 -
src/Kernel/AccessToken.php | 11 +-
src/Kernel/BaseClient.php | 67 +-
src/Kernel/Clauses/Clause.php | 13 +-
src/Kernel/Encryptor.php | 30 +-
src/Kernel/Http/Response.php | 2 +-
src/Kernel/Log/LogManager.php | 74 +-
src/Kernel/Messages/InteractiveTaskCard.php | 49 +
src/Kernel/Messages/Message.php | 34 +-
src/Kernel/Messages/MiniprogramNotice.php | 13 +
.../Messages/ReplyInteractiveTaskCard.php | 60 ++
src/Kernel/Messages/Text.php | 2 +-
.../Providers/ConfigServiceProvider.php | 2 +-
.../EventDispatcherServiceProvider.php | 2 +-
.../Providers/ExtensionServiceProvider.php | 2 +-
.../Providers/HttpClientServiceProvider.php | 2 +-
src/Kernel/Providers/LogServiceProvider.php | 38 +-
.../Providers/RequestServiceProvider.php | 2 +-
src/Kernel/ServerGuard.php | 4 +-
src/Kernel/ServiceContainer.php | 4 +-
src/Kernel/Support/Arr.php | 2 +-
src/Kernel/Support/Collection.php | 23 +-
src/Kernel/Support/XML.php | 4 +-
src/Kernel/Traits/Observable.php | 6 +-
src/MicroMerchant/Kernel/BaseClient.php | 2 +-
src/MiniProgram/Application.php | 33 +-
src/MiniProgram/Auth/AccessToken.php | 2 +-
src/MiniProgram/Broadcast/Client.php | 333 +++++-
src/MiniProgram/Business/Client.php | 149 +++
src/MiniProgram/Business/Messenger.php | 179 ++++
src/MiniProgram/Business/ServiceProvider.php | 29 +
src/MiniProgram/DataCube/Client.php | 29 +
src/MiniProgram/Express/Client.php | 64 ++
src/MiniProgram/OpenData/Client.php | 9 +-
src/MiniProgram/PhoneNumber/Client.php | 47 +
.../PhoneNumber/ServiceProvider.php | 28 +
src/MiniProgram/QrCode/Client.php | 126 +++
src/MiniProgram/QrCode/ServiceProvider.php | 33 +
src/MiniProgram/RiskControl/Client.php | 32 +
.../RiskControl/ServiceProvider.php | 25 +
src/MiniProgram/Shop/Account/Client.php | 67 ++
.../Shop/Account/ServiceProvider.php | 25 +
src/MiniProgram/Shop/Aftersale/Client.php | 54 +
.../Shop/Aftersale/ServiceProvider.php | 25 +
src/MiniProgram/Shop/Basic/Client.php | 110 ++
.../Shop/Basic/ServiceProvider.php | 25 +
src/MiniProgram/Shop/Delivery/Client.php | 52 +
.../Shop/Delivery/ServiceProvider.php | 25 +
src/MiniProgram/Shop/Order/Client.php | 157 +++
.../Shop/Order/ServiceProvider.php | 25 +
src/MiniProgram/Shop/Register/Client.php | 76 ++
.../Shop/Register/ServiceProvider.php | 33 +
src/MiniProgram/Shop/Spu/Client.php | 132 +++
src/MiniProgram/Shop/Spu/ServiceProvider.php | 25 +
src/MiniProgram/ShortLink/Client.php | 42 +
src/MiniProgram/ShortLink/ServiceProvider.php | 19 +
src/MiniProgram/SubscribeMessage/Client.php | 3 +-
src/MiniProgram/TemplateMessage/Client.php | 2 +-
src/MiniProgram/UniformMessage/Client.php | 2 +-
src/MiniProgram/Union/Client.php | 228 ++++
src/MiniProgram/Union/ServiceProvider.php | 33 +
src/MiniProgram/UrlLink/Client.php | 32 +
src/MiniProgram/UrlLink/ServiceProvider.php | 19 +
src/MiniProgram/UrlScheme/Client.php | 32 +
src/MiniProgram/UrlScheme/ServiceProvider.php | 19 +
src/OfficialAccount/Application.php | 11 +-
src/OfficialAccount/Auth/AccessToken.php | 2 +-
src/OfficialAccount/Base/Client.php | 19 +
src/OfficialAccount/Broadcasting/Client.php | 4 +-
src/OfficialAccount/Card/Client.php | 2 +-
src/OfficialAccount/Card/InvoiceClient.php | 78 ++
src/OfficialAccount/Draft/Client.php | 108 ++
src/OfficialAccount/Draft/ServiceProvider.php | 35 +
src/OfficialAccount/FreePublish/Client.php | 90 ++
.../FreePublish/ServiceProvider.php | 35 +
src/OfficialAccount/Guide/Client.php | 991 ++++++++++++++++++
src/OfficialAccount/Guide/ServiceProvider.php | 33 +
src/OfficialAccount/OAuth/ServiceProvider.php | 17 +-
src/OfficialAccount/OCR/Client.php | 75 +-
.../Server/Handlers/EchoStrHandler.php | 2 +
.../ShakeAround/ShakeAround.php | 1 +
src/OfficialAccount/Store/Client.php | 2 +-
.../SubscribeMessage/Client.php | 189 ++++
.../SubscribeMessage/ServiceProvider.php | 27 +
.../TemplateMessage/Client.php | 4 +-
src/OpenPlatform/Application.php | 169 +--
.../Authorizer/MiniProgram/Account/Client.php | 21 +-
.../Authorizer/MiniProgram/Application.php | 14 +-
.../Authorizer/MiniProgram/Code/Client.php | 10 +-
.../MiniProgram/Material/Client.php | 51 +
.../MiniProgram/Material/ServiceProvider.php | 44 +
.../Authorizer/MiniProgram/Privacy/Client.php | 66 ++
.../MiniProgram/Privacy/ServiceProvider.php | 25 +
.../MiniProgram/Security/Client.php | 45 +
.../MiniProgram/Security/ServiceProvider.php | 25 +
.../Authorizer/MiniProgram/Tester/Client.php | 14 +-
src/OpenPlatform/CodeTemplate/Client.php | 14 +-
src/OpenPlatform/Server/Guard.php | 12 +-
.../Server/Handlers/VerifyTicketRefreshed.php | 11 +-
src/OpenWork/Application.php | 12 +-
src/OpenWork/Contact/Client.php | 92 ++
src/OpenWork/Contact/ServiceProvider.php | 33 +
src/OpenWork/Corp/Client.php | 46 +-
src/OpenWork/Device/Client.php | 187 ++++
src/OpenWork/Device/ServiceProvider.php | 33 +
src/OpenWork/License/Account.php | 206 ++++
src/OpenWork/License/App.php | 51 +
src/OpenWork/License/AutoActive.php | 69 ++
src/OpenWork/License/Client.php | 175 ++++
src/OpenWork/License/ServiceProvider.php | 45 +
src/OpenWork/Media/Client.php | 105 ++
src/OpenWork/Media/ServiceProvider.php | 33 +
src/OpenWork/Provider/Client.php | 91 +-
.../Server/Handlers/EchoStrHandler.php | 4 +
src/OpenWork/Work/Application.php | 2 +-
src/Payment/Contract/Client.php | 2 +-
src/Payment/Jssdk/Client.php | 37 +-
src/Payment/Kernel/BaseClient.php | 2 +-
src/Payment/Notify/Handler.php | 4 +-
src/Payment/Redpack/Client.php | 1 +
src/Payment/Transfer/Client.php | 2 +-
src/Work/Agent/ServiceProvider.php | 4 +
src/Work/Agent/WorkbenchClient.php | 74 ++
src/Work/Application.php | 66 +-
src/Work/CorpGroup/Client.php | 121 +++
src/Work/CorpGroup/ServiceProvider.php | 35 +
src/Work/Department/Client.php | 32 +-
src/Work/ExternalContact/Client.php | 531 +++++++++-
src/Work/ExternalContact/ContactWayClient.php | 51 +
.../ExternalContact/GroupChatWayClient.php | 94 ++
src/Work/ExternalContact/InterceptClient.php | 106 ++
src/Work/ExternalContact/MessageClient.php | 112 +-
.../ExternalContact/MessageTemplateClient.php | 166 +++
src/Work/ExternalContact/MomentClient.php | 166 +++
src/Work/ExternalContact/ProductClient.php | 133 +++
src/Work/ExternalContact/SchoolClient.php | 441 ++++++++
src/Work/ExternalContact/ServiceProvider.php | 24 +
src/Work/ExternalContact/StatisticsClient.php | 59 +-
src/Work/GroupWelcomeTemplate/Client.php | 84 ++
.../GroupWelcomeTemplate/ServiceProvider.php | 34 +
src/Work/Jssdk/Client.php | 150 ++-
src/Work/Kf/AccountClient.php | 131 +++
src/Work/Kf/MessageClient.php | 133 +++
src/Work/Kf/ServiceProvider.php | 43 +
src/Work/Kf/ServicerClient.php | 91 ++
src/Work/Live/Client.php | 84 ++
src/Work/Live/ServiceProvider.php | 33 +
src/Work/Media/Client.php | 99 +-
src/Work/Message/Client.php | 29 +-
src/Work/Message/Messenger.php | 13 +-
src/Work/Message/ServiceProvider.php | 2 +-
src/Work/Mobile/Auth/Client.php | 40 +
src/Work/Mobile/ServiceProvider.php | 36 +
src/Work/MsgAudit/Client.php | 85 ++
src/Work/MsgAudit/ServiceProvider.php | 33 +
src/Work/OA/Client.php | 168 +++
src/Work/OAuth/Manager.php | 51 +
src/Work/OAuth/ServiceProvider.php | 10 +-
src/Work/Server/Handlers/EchoStrHandler.php | 2 +
src/Work/User/BatchJobsClient.php | 94 ++
src/Work/User/Client.php | 64 ++
src/Work/User/LinkedCorpClient.php | 125 +++
src/Work/User/ServiceProvider.php | 8 +
src/Work/Wedrive/Client.php | 54 +
src/Work/Wedrive/FileClient.php | 324 ++++++
src/Work/Wedrive/ServiceProvider.php | 37 +
src/Work/Wedrive/SpaceClient.php | 201 ++++
src/Work/Wedrive/Wedrive.php | 32 +
174 files changed, 10420 insertions(+), 515 deletions(-)
create mode 100644 src/Kernel/Messages/InteractiveTaskCard.php
create mode 100644 src/Kernel/Messages/MiniprogramNotice.php
create mode 100755 src/Kernel/Messages/ReplyInteractiveTaskCard.php
create mode 100644 src/MiniProgram/Business/Client.php
create mode 100644 src/MiniProgram/Business/Messenger.php
create mode 100644 src/MiniProgram/Business/ServiceProvider.php
create mode 100644 src/MiniProgram/PhoneNumber/Client.php
create mode 100644 src/MiniProgram/PhoneNumber/ServiceProvider.php
create mode 100644 src/MiniProgram/QrCode/Client.php
create mode 100644 src/MiniProgram/QrCode/ServiceProvider.php
create mode 100644 src/MiniProgram/RiskControl/Client.php
create mode 100644 src/MiniProgram/RiskControl/ServiceProvider.php
create mode 100644 src/MiniProgram/Shop/Account/Client.php
create mode 100644 src/MiniProgram/Shop/Account/ServiceProvider.php
create mode 100644 src/MiniProgram/Shop/Aftersale/Client.php
create mode 100644 src/MiniProgram/Shop/Aftersale/ServiceProvider.php
create mode 100644 src/MiniProgram/Shop/Basic/Client.php
create mode 100644 src/MiniProgram/Shop/Basic/ServiceProvider.php
create mode 100644 src/MiniProgram/Shop/Delivery/Client.php
create mode 100644 src/MiniProgram/Shop/Delivery/ServiceProvider.php
create mode 100644 src/MiniProgram/Shop/Order/Client.php
create mode 100644 src/MiniProgram/Shop/Order/ServiceProvider.php
create mode 100644 src/MiniProgram/Shop/Register/Client.php
create mode 100644 src/MiniProgram/Shop/Register/ServiceProvider.php
create mode 100644 src/MiniProgram/Shop/Spu/Client.php
create mode 100644 src/MiniProgram/Shop/Spu/ServiceProvider.php
create mode 100644 src/MiniProgram/ShortLink/Client.php
create mode 100644 src/MiniProgram/ShortLink/ServiceProvider.php
create mode 100644 src/MiniProgram/Union/Client.php
create mode 100644 src/MiniProgram/Union/ServiceProvider.php
create mode 100644 src/MiniProgram/UrlLink/Client.php
create mode 100644 src/MiniProgram/UrlLink/ServiceProvider.php
create mode 100644 src/MiniProgram/UrlScheme/Client.php
create mode 100644 src/MiniProgram/UrlScheme/ServiceProvider.php
create mode 100644 src/OfficialAccount/Draft/Client.php
create mode 100644 src/OfficialAccount/Draft/ServiceProvider.php
create mode 100644 src/OfficialAccount/FreePublish/Client.php
create mode 100644 src/OfficialAccount/FreePublish/ServiceProvider.php
create mode 100644 src/OfficialAccount/Guide/Client.php
create mode 100644 src/OfficialAccount/Guide/ServiceProvider.php
create mode 100644 src/OfficialAccount/SubscribeMessage/Client.php
create mode 100644 src/OfficialAccount/SubscribeMessage/ServiceProvider.php
create mode 100644 src/OpenPlatform/Authorizer/MiniProgram/Material/Client.php
create mode 100644 src/OpenPlatform/Authorizer/MiniProgram/Material/ServiceProvider.php
create mode 100644 src/OpenPlatform/Authorizer/MiniProgram/Privacy/Client.php
create mode 100644 src/OpenPlatform/Authorizer/MiniProgram/Privacy/ServiceProvider.php
create mode 100644 src/OpenPlatform/Authorizer/MiniProgram/Security/Client.php
create mode 100644 src/OpenPlatform/Authorizer/MiniProgram/Security/ServiceProvider.php
create mode 100644 src/OpenWork/Contact/Client.php
create mode 100644 src/OpenWork/Contact/ServiceProvider.php
create mode 100644 src/OpenWork/Device/Client.php
create mode 100644 src/OpenWork/Device/ServiceProvider.php
create mode 100644 src/OpenWork/License/Account.php
create mode 100644 src/OpenWork/License/App.php
create mode 100644 src/OpenWork/License/AutoActive.php
create mode 100644 src/OpenWork/License/Client.php
create mode 100644 src/OpenWork/License/ServiceProvider.php
create mode 100644 src/OpenWork/Media/Client.php
create mode 100644 src/OpenWork/Media/ServiceProvider.php
create mode 100644 src/Work/Agent/WorkbenchClient.php
create mode 100644 src/Work/CorpGroup/Client.php
create mode 100644 src/Work/CorpGroup/ServiceProvider.php
create mode 100644 src/Work/ExternalContact/GroupChatWayClient.php
create mode 100644 src/Work/ExternalContact/InterceptClient.php
create mode 100644 src/Work/ExternalContact/MessageTemplateClient.php
create mode 100644 src/Work/ExternalContact/MomentClient.php
create mode 100644 src/Work/ExternalContact/ProductClient.php
create mode 100644 src/Work/ExternalContact/SchoolClient.php
create mode 100644 src/Work/GroupWelcomeTemplate/Client.php
create mode 100644 src/Work/GroupWelcomeTemplate/ServiceProvider.php
create mode 100644 src/Work/Kf/AccountClient.php
create mode 100644 src/Work/Kf/MessageClient.php
create mode 100644 src/Work/Kf/ServiceProvider.php
create mode 100644 src/Work/Kf/ServicerClient.php
create mode 100644 src/Work/Live/Client.php
create mode 100644 src/Work/Live/ServiceProvider.php
create mode 100644 src/Work/Mobile/Auth/Client.php
create mode 100644 src/Work/Mobile/ServiceProvider.php
create mode 100644 src/Work/MsgAudit/Client.php
create mode 100644 src/Work/MsgAudit/ServiceProvider.php
create mode 100644 src/Work/OAuth/Manager.php
create mode 100644 src/Work/User/BatchJobsClient.php
create mode 100644 src/Work/User/LinkedCorpClient.php
create mode 100644 src/Work/Wedrive/Client.php
create mode 100644 src/Work/Wedrive/FileClient.php
create mode 100644 src/Work/Wedrive/ServiceProvider.php
create mode 100644 src/Work/Wedrive/SpaceClient.php
create mode 100644 src/Work/Wedrive/Wedrive.php
diff --git a/.gitignore b/.gitignore
index 78d01d7..4f22bbd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,5 @@
/vendor
*.log
.env
-composer.lock
\ No newline at end of file
+composer.lock
+.git
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 60853fd..d12b77d 100644
--- a/composer.json
+++ b/composer.json
@@ -20,15 +20,16 @@
"ext-fileinfo": "*",
"ext-openssl": "*",
"ext-simplexml": "*",
+ "ext-libxml": "*",
"easywechat-composer/easywechat-composer": "^1.1",
- "guzzlehttp/guzzle": "^6.2",
+ "guzzlehttp/guzzle": "^6.2 || ^7.0",
"monolog/monolog": "^1.22 || ^2.0",
- "overtrue/socialite": "~2.0",
+ "overtrue/socialite": "^3.2 || ^4.0",
"pimple/pimple": "^3.0",
- "psr/simple-cache": "^1.0",
- "symfony/cache": "^3.3 || ^4.3 || ^5.0",
- "symfony/event-dispatcher": "^4.3 || ^5.0",
- "symfony/http-foundation": "^2.7 || ^3.0 || ^4.0 || ^5.0",
+ "psr/simple-cache": "^1.0||^2.0||^3.0",
+ "symfony/cache": "^3.3 || ^4.3 || ^5.0 || ^6.0",
+ "symfony/event-dispatcher": "^4.3 || ^5.0 || ^6.0",
+ "symfony/http-foundation": "^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/psr-http-message-bridge": "^0.3 || ^1.0 || ^2.0"
},
"require-dev": {
diff --git a/src/BasicService/ContentSecurity/Client.php b/src/BasicService/ContentSecurity/Client.php
index 7bc11bd..bad4236 100644
--- a/src/BasicService/ContentSecurity/Client.php
+++ b/src/BasicService/ContentSecurity/Client.php
@@ -21,28 +21,21 @@ use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
*/
class Client extends BaseClient
{
- /**
- * @var string
- */
- protected $baseUri = 'https://api.weixin.qq.com/wxa/';
-
/**
* Text content security check.
*
* @param string $text
- *
+ * @param array $extra
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function checkText(string $text)
+ public function checkText(string $text, array $extra = [])
{
- $params = [
- 'content' => $text,
- ];
+ $params = array_merge(['content' => $text], $extra);
- return $this->httpPostJson('msg_sec_check', $params);
+ return $this->httpPostJson('wxa/msg_sec_check', $params);
}
/**
@@ -57,7 +50,7 @@ class Client extends BaseClient
*/
public function checkImage(string $path)
{
- return $this->httpUpload('img_sec_check', ['media' => $path]);
+ return $this->httpUpload('wxa/img_sec_check', ['media' => $path]);
}
/**
@@ -88,7 +81,7 @@ class Client extends BaseClient
'media_type' => $mediaType,
];
- return $this->httpPostJson('media_check_async', $params);
+ return $this->httpPostJson('wxa/media_check_async', $params);
}
/**
diff --git a/src/BasicService/Jssdk/Client.php b/src/BasicService/Jssdk/Client.php
index 33367fc..0c0a2fa 100644
--- a/src/BasicService/Jssdk/Client.php
+++ b/src/BasicService/Jssdk/Client.php
@@ -28,7 +28,7 @@ class Client extends BaseClient
/**
* @var string
*/
- protected $ticketEndpoint = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket';
+ protected $ticketEndpoint = 'cgi-bin/ticket/getticket';
/**
* Current URI.
@@ -40,20 +40,24 @@ class Client extends BaseClient
/**
* Get config json for jsapi.
*
- * @param array $jsApiList
- * @param bool $debug
- * @param bool $beta
- * @param bool $json
+ * @param array $jsApiList
+ * @param bool $debug
+ * @param bool $beta
+ * @param bool $json
+ * @param array $openTagList
+ * @param string|null $url
*
* @return array|string
*
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
+ * @throws \Psr\SimpleCache\InvalidArgumentException
+ * @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function buildConfig(array $jsApiList, bool $debug = false, bool $beta = false, bool $json = true)
+ public function buildConfig(array $jsApiList, bool $debug = false, bool $beta = false, bool $json = true, array $openTagList = [], string $url = null)
{
- $config = array_merge(compact('debug', 'beta', 'jsApiList'), $this->configSignature());
+ $config = array_merge(compact('debug', 'beta', 'jsApiList', 'openTagList'), $this->configSignature($url));
return $json ? json_encode($config) : $config;
}
@@ -61,19 +65,22 @@ class Client extends BaseClient
/**
* Return jsapi config as a PHP array.
*
- * @param array $apis
- * @param bool $debug
- * @param bool $beta
- *
- * @return array
+ * @param array $apis
+ * @param bool $debug
+ * @param bool $beta
+ * @param array $openTagList
+ * @param string|null $url
*
+ * @return array|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
+ * @throws \Psr\SimpleCache\InvalidArgumentException
+ * @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function getConfigArray(array $apis, bool $debug = false, bool $beta = false)
+ public function getConfigArray(array $apis, bool $debug = false, bool $beta = false, array $openTagList = [], string $url = null)
{
- return $this->buildConfig($apis, $debug, $beta, false);
+ return $this->buildConfig($apis, $debug, $beta, false, $openTagList, $url);
}
/**
@@ -118,13 +125,14 @@ class Client extends BaseClient
*
* @param string|null $url
* @param string|null $nonce
- * @param int|null $timestamp
+ * @param null $timestamp
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
+ * @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
protected function configSignature(string $url = null, string $nonce = null, $timestamp = null): array
@@ -204,4 +212,12 @@ class Client extends BaseClient
{
return $this->app['config']->get('app_id');
}
+
+ /**
+ * @return string
+ */
+ protected function getAgentId()
+ {
+ return $this->app['config']->get('agent_id');
+ }
}
diff --git a/src/BasicService/Media/Client.php b/src/BasicService/Media/Client.php
index 13f1afa..73345d8 100644
--- a/src/BasicService/Media/Client.php
+++ b/src/BasicService/Media/Client.php
@@ -22,11 +22,6 @@ use EasyWeChat\Kernel\Http\StreamResponse;
*/
class Client extends BaseClient
{
- /**
- * @var string
- */
- protected $baseUri = 'https://api.weixin.qq.com/cgi-bin/';
-
/**
* Allow media type.
*
@@ -116,7 +111,7 @@ class Client extends BaseClient
throw new InvalidArgumentException(sprintf("Unsupported media type: '%s'", $type));
}
- return $this->httpUpload('media/upload', ['media' => $path], ['type' => $type]);
+ return $this->httpUpload('cgi-bin/media/upload', ['media' => $path], ['type' => $type]);
}
/**
@@ -155,7 +150,7 @@ class Client extends BaseClient
*/
public function createVideoForBroadcasting(string $mediaId, string $title, string $description)
{
- return $this->httpPostJson('media/uploadvideo', [
+ return $this->httpPostJson('cgi-bin/media/uploadvideo', [
'media_id' => $mediaId,
'title' => $title,
'description' => $description,
@@ -174,7 +169,7 @@ class Client extends BaseClient
*/
public function get(string $mediaId)
{
- $response = $this->requestRaw('media/get', 'GET', [
+ $response = $this->requestRaw('cgi-bin/media/get', 'GET', [
'query' => [
'media_id' => $mediaId,
],
@@ -197,7 +192,7 @@ class Client extends BaseClient
*/
public function getJssdkMedia(string $mediaId)
{
- $response = $this->requestRaw('media/get/jssdk', 'GET', [
+ $response = $this->requestRaw('cgi-bin/media/get/jssdk', 'GET', [
'query' => [
'media_id' => $mediaId,
],
diff --git a/src/BasicService/QrCode/Client.php b/src/BasicService/QrCode/Client.php
index ac606a3..92caeeb 100644
--- a/src/BasicService/QrCode/Client.php
+++ b/src/BasicService/QrCode/Client.php
@@ -20,18 +20,13 @@ use EasyWeChat\Kernel\BaseClient;
*/
class Client extends BaseClient
{
- /**
- * @var string
- */
- protected $baseUri = 'https://api.weixin.qq.com/cgi-bin/';
-
- const DAY = 86400;
- const SCENE_MAX_VALUE = 100000;
- const SCENE_QR_CARD = 'QR_CARD';
- const SCENE_QR_TEMPORARY = 'QR_SCENE';
- const SCENE_QR_TEMPORARY_STR = 'QR_STR_SCENE';
- const SCENE_QR_FOREVER = 'QR_LIMIT_SCENE';
- const SCENE_QR_FOREVER_STR = 'QR_LIMIT_STR_SCENE';
+ public const DAY = 86400;
+ public const SCENE_MAX_VALUE = 100000;
+ public const SCENE_QR_CARD = 'QR_CARD';
+ public const SCENE_QR_TEMPORARY = 'QR_SCENE';
+ public const SCENE_QR_TEMPORARY_STR = 'QR_STR_SCENE';
+ public const SCENE_QR_FOREVER = 'QR_LIMIT_SCENE';
+ public const SCENE_QR_FOREVER_STR = 'QR_LIMIT_STR_SCENE';
/**
* Create forever QR code.
@@ -115,6 +110,6 @@ class Client extends BaseClient
$params['expire_seconds'] = min($expireSeconds, 30 * self::DAY);
}
- return $this->httpPostJson('qrcode/create', $params);
+ return $this->httpPostJson('cgi-bin/qrcode/create', $params);
}
}
diff --git a/src/BasicService/Url/Client.php b/src/BasicService/Url/Client.php
index 19a5fb1..0363b52 100644
--- a/src/BasicService/Url/Client.php
+++ b/src/BasicService/Url/Client.php
@@ -20,11 +20,6 @@ use EasyWeChat\Kernel\BaseClient;
*/
class Client extends BaseClient
{
- /**
- * @var string
- */
- protected $baseUri = 'https://api.weixin.qq.com/';
-
/**
* Shorten the url.
*
diff --git a/src/Kernel/AccessToken.php b/src/Kernel/AccessToken.php
index e7ae696..bbf84ec 100644
--- a/src/Kernel/AccessToken.php
+++ b/src/Kernel/AccessToken.php
@@ -75,6 +75,11 @@ abstract class AccessToken implements AccessTokenInterface
$this->app = $app;
}
+ public function getLastToken(): array
+ {
+ return $this->token;
+ }
+
/**
* @return array
*
@@ -105,8 +110,8 @@ abstract class AccessToken implements AccessTokenInterface
$cacheKey = $this->getCacheKey();
$cache = $this->getCache();
- if (!$refresh && $cache->has($cacheKey)) {
- return $cache->get($cacheKey);
+ if (!$refresh && $cache->has($cacheKey) && $result = $cache->get($cacheKey)) {
+ return $result;
}
/** @var array $token */
@@ -114,6 +119,8 @@ abstract class AccessToken implements AccessTokenInterface
$this->setToken($token[$this->tokenKey], $token['expires_in'] ?? 7200);
+ $this->token = $token;
+
$this->app->events->dispatch(new Events\AccessTokenRefreshed($this));
return $token;
diff --git a/src/Kernel/BaseClient.php b/src/Kernel/BaseClient.php
index 75e79e8..ed02f0d 100644
--- a/src/Kernel/BaseClient.php
+++ b/src/Kernel/BaseClient.php
@@ -27,18 +27,18 @@ use Psr\Log\LogLevel;
*/
class BaseClient
{
- use HasHttpRequests { request as performRequest; }
+ use HasHttpRequests {
+ request as performRequest;
+ }
/**
* @var \EasyWeChat\Kernel\ServiceContainer
*/
protected $app;
-
/**
- * @var \EasyWeChat\Kernel\Contracts\AccessTokenInterface
+ * @var \EasyWeChat\Kernel\Contracts\AccessTokenInterface|null
*/
- protected $accessToken;
-
+ protected $accessToken = null;
/**
* @var string
*/
@@ -121,11 +121,19 @@ class BaseClient
public function httpUpload(string $url, array $files = [], array $form = [], array $query = [])
{
$multipart = [];
+ $headers = [];
+
+ if (isset($form['filename'])) {
+ $headers = [
+ 'Content-Disposition' => 'form-data; name="media"; filename="'.$form['filename'].'"'
+ ];
+ }
foreach ($files as $name => $path) {
$multipart[] = [
'name' => $name,
'contents' => fopen($path, 'r'),
+ 'headers' => $headers
];
}
@@ -133,7 +141,11 @@ class BaseClient
$multipart[] = compact('name', 'contents');
}
- return $this->request($url, 'POST', ['query' => $query, 'multipart' => $multipart, 'connect_timeout' => 30, 'timeout' => 30, 'read_timeout' => 30]);
+ return $this->request(
+ $url,
+ 'POST',
+ ['query' => $query, 'multipart' => $multipart, 'connect_timeout' => 30, 'timeout' => 30, 'read_timeout' => 30]
+ );
}
/**
@@ -245,27 +257,30 @@ class BaseClient
*/
protected function retryMiddleware()
{
- return Middleware::retry(function (
- $retries,
- RequestInterface $request,
- ResponseInterface $response = null
- ) {
- // Limit the number of retries to 2
- if ($retries < $this->app->config->get('http.max_retries', 1) && $response && $body = $response->getBody()) {
- // Retry on server errors
- $response = json_decode($body, true);
-
- if (!empty($response['errcode']) && in_array(abs($response['errcode']), [40001, 40014, 42001], true)) {
- $this->accessToken->refresh();
- $this->app['logger']->debug('Retrying with refreshed access token.');
-
- return true;
+ return Middleware::retry(
+ function (
+ $retries,
+ RequestInterface $request,
+ ResponseInterface $response = null
+ ) {
+ // Limit the number of retries to 2
+ if ($retries < $this->app->config->get('http.max_retries', 1) && $response && $body = $response->getBody()) {
+ // Retry on server errors
+ $response = json_decode($body, true);
+
+ if (!empty($response['errcode']) && in_array(abs($response['errcode']), [40001, 40014, 42001], true)) {
+ $this->accessToken->refresh();
+ $this->app['logger']->debug('Retrying with refreshed access token.');
+
+ return true;
+ }
}
- }
- return false;
- }, function () {
- return abs($this->app->config->get('http.retry_delay', 500));
- });
+ return false;
+ },
+ function () {
+ return abs($this->app->config->get('http.retry_delay', 500));
+ }
+ );
}
}
diff --git a/src/Kernel/Clauses/Clause.php b/src/Kernel/Clauses/Clause.php
index 49bbb22..b798f32 100644
--- a/src/Kernel/Clauses/Clause.php
+++ b/src/Kernel/Clauses/Clause.php
@@ -56,9 +56,20 @@ class Clause
{
foreach ($this->clauses['where'] as $item) {
list($key, $value) = $item;
- if (isset($payload[$key]) && $payload[$key] !== $value) {
+
+ if (!isset($payload[$key])) {
+ continue;
+ }
+
+ if (is_array($value) && !in_array($payload[$key], $value)) {
+ return true;
+ }
+
+ if (!is_array($value) && $payload[$key] !== $value) {
return true;
}
}
+
+ return false;
}
}
diff --git a/src/Kernel/Encryptor.php b/src/Kernel/Encryptor.php
index 150ad21..a154809 100644
--- a/src/Kernel/Encryptor.php
+++ b/src/Kernel/Encryptor.php
@@ -13,9 +13,9 @@ namespace EasyWeChat\Kernel;
use EasyWeChat\Kernel\Exceptions\RuntimeException;
use EasyWeChat\Kernel\Support\AES;
-use function EasyWeChat\Kernel\Support\str_random;
use EasyWeChat\Kernel\Support\XML;
use Throwable;
+use function EasyWeChat\Kernel\Support\str_random;
/**
* Class Encryptor.
@@ -24,18 +24,18 @@ use Throwable;
*/
class Encryptor
{
- const ERROR_INVALID_SIGNATURE = -40001; // Signature verification failed
- const ERROR_PARSE_XML = -40002; // Parse XML failed
- const ERROR_CALC_SIGNATURE = -40003; // Calculating the signature failed
- const ERROR_INVALID_AES_KEY = -40004; // Invalid AESKey
- const ERROR_INVALID_APP_ID = -40005; // Check AppID failed
- const ERROR_ENCRYPT_AES = -40006; // AES EncryptionInterface failed
- const ERROR_DECRYPT_AES = -40007; // AES decryption failed
- const ERROR_INVALID_XML = -40008; // Invalid XML
- const ERROR_BASE64_ENCODE = -40009; // Base64 encoding failed
- const ERROR_BASE64_DECODE = -40010; // Base64 decoding failed
- const ERROR_XML_BUILD = -40011; // XML build failed
- const ILLEGAL_BUFFER = -41003; // Illegal buffer
+ public const ERROR_INVALID_SIGNATURE = -40001; // Signature verification failed
+ public const ERROR_PARSE_XML = -40002; // Parse XML failed
+ public const ERROR_CALC_SIGNATURE = -40003; // Calculating the signature failed
+ public const ERROR_INVALID_AES_KEY = -40004; // Invalid AESKey
+ public const ERROR_INVALID_APP_ID = -40005; // Check AppID failed
+ public const ERROR_ENCRYPT_AES = -40006; // AES EncryptionInterface failed
+ public const ERROR_DECRYPT_AES = -40007; // AES decryption failed
+ public const ERROR_INVALID_XML = -40008; // Invalid XML
+ public const ERROR_BASE64_ENCODE = -40009; // Base64 encoding failed
+ public const ERROR_BASE64_DECODE = -40010; // Base64 decoding failed
+ public const ERROR_XML_BUILD = -40011; // XML build failed
+ public const ILLEGAL_BUFFER = -41003; // Illegal buffer
/**
* App id.
@@ -107,7 +107,7 @@ class Encryptor
$xml,
$this->aesKey,
substr($this->aesKey, 0, 16),
- OPENSSL_NO_PADDING
+ OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING
));
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
@@ -153,7 +153,7 @@ class Encryptor
base64_decode($content, true),
$this->aesKey,
substr($this->aesKey, 0, 16),
- OPENSSL_NO_PADDING
+ OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING
);
$result = $this->pkcs7Unpad($decrypted);
$content = substr($result, 16, strlen($result));
diff --git a/src/Kernel/Http/Response.php b/src/Kernel/Http/Response.php
index adcd416..401857a 100644
--- a/src/Kernel/Http/Response.php
+++ b/src/Kernel/Http/Response.php
@@ -116,6 +116,6 @@ class Response extends GuzzleResponse
*/
protected function removeControlCharacters(string $content)
{
- return \preg_replace('/[\x00-\x1F\x80-\x9F]/u', '', $content);
+ return \preg_replace('/[\x00-\x1F\x80-\x9F]/u', '', \mb_convert_encoding($content, 'UTF-8', 'UTF-8'));
}
}
diff --git a/src/Kernel/Log/LogManager.php b/src/Kernel/Log/LogManager.php
index 9159464..870b46f 100644
--- a/src/Kernel/Log/LogManager.php
+++ b/src/Kernel/Log/LogManager.php
@@ -271,9 +271,10 @@ class LogManager implements LoggerInterface
/**
* Create an instance of the Slack log driver.
*
- * @param array $config
+ * @param array $config
*
* @return \Psr\Log\LoggerInterface
+ * @throws \Monolog\Handler\MissingExtensionException
*/
protected function createSlackDriver(array $config)
{
@@ -337,7 +338,7 @@ class LogManager implements LoggerInterface
*
* @return array
*/
- protected function prepareHandlers(array $handlers)
+ protected function prepareHandlers(array $handlers): array
{
foreach ($handlers as $key => $handler) {
$handlers[$key] = $this->prepareHandler($handler);
@@ -349,7 +350,8 @@ class LogManager implements LoggerInterface
/**
* Prepare the handler for usage by Monolog.
*
- * @param \Monolog\Handler\HandlerInterface $handler
+ * @param \Monolog\Handler\HandlerInterface $handler
+ * @param array $config
*
* @return \Monolog\Handler\HandlerInterface
*/
@@ -384,7 +386,7 @@ class LogManager implements LoggerInterface
*
* @return string
*/
- protected function parseChannel(array $config)
+ protected function parseChannel(array $config): string
{
return $config['name'] ?? 'EasyWeChat';
}
@@ -398,7 +400,7 @@ class LogManager implements LoggerInterface
*
* @throws InvalidArgumentException
*/
- protected function level(array $config)
+ protected function level(array $config): int
{
$level = $config['level'] ?? 'debug';
@@ -414,7 +416,7 @@ class LogManager implements LoggerInterface
*
* @return string
*/
- public function getDefaultDriver()
+ public function getDefaultDriver(): ?string
{
return $this->app['config']['log.default'];
}
@@ -432,12 +434,12 @@ class LogManager implements LoggerInterface
/**
* Register a custom driver creator Closure.
*
- * @param string $driver
+ * @param string $driver
* @param \Closure $callback
*
* @return $this
*/
- public function extend($driver, \Closure $callback)
+ public function extend(string $driver, \Closure $callback): LogManager
{
$this->customCreators[$driver] = $callback->bindTo($this, $this);
@@ -450,13 +452,13 @@ class LogManager implements LoggerInterface
* @param string $message
* @param array $context
*
- * @return mixed
+ * @return void
*
* @throws \Exception
*/
- public function emergency($message, array $context = [])
+ public function emergency($message, array $context = []): void
{
- return $this->driver()->emergency($message, $context);
+ $this->driver()->emergency($message, $context);
}
/**
@@ -468,13 +470,13 @@ class LogManager implements LoggerInterface
* @param string $message
* @param array $context
*
- * @return mixed
+ * @return void
*
* @throws \Exception
*/
- public function alert($message, array $context = [])
+ public function alert($message, array $context = []): void
{
- return $this->driver()->alert($message, $context);
+ $this->driver()->alert($message, $context);
}
/**
@@ -485,13 +487,11 @@ class LogManager implements LoggerInterface
* @param string $message
* @param array $context
*
- * @return mixed
- *
* @throws \Exception
*/
- public function critical($message, array $context = [])
+ public function critical($message, array $context = []): void
{
- return $this->driver()->critical($message, $context);
+ $this->driver()->critical($message, $context);
}
/**
@@ -501,13 +501,11 @@ class LogManager implements LoggerInterface
* @param string $message
* @param array $context
*
- * @return mixed
- *
* @throws \Exception
*/
- public function error($message, array $context = [])
+ public function error($message, array $context = []): void
{
- return $this->driver()->error($message, $context);
+ $this->driver()->error($message, $context);
}
/**
@@ -519,13 +517,11 @@ class LogManager implements LoggerInterface
* @param string $message
* @param array $context
*
- * @return mixed
- *
* @throws \Exception
*/
- public function warning($message, array $context = [])
+ public function warning($message, array $context = []): void
{
- return $this->driver()->warning($message, $context);
+ $this->driver()->warning($message, $context);
}
/**
@@ -534,13 +530,11 @@ class LogManager implements LoggerInterface
* @param string $message
* @param array $context
*
- * @return mixed
- *
* @throws \Exception
*/
- public function notice($message, array $context = [])
+ public function notice($message, array $context = []): void
{
- return $this->driver()->notice($message, $context);
+ $this->driver()->notice($message, $context);
}
/**
@@ -551,13 +545,11 @@ class LogManager implements LoggerInterface
* @param string $message
* @param array $context
*
- * @return mixed
- *
* @throws \Exception
*/
- public function info($message, array $context = [])
+ public function info($message, array $context = []): void
{
- return $this->driver()->info($message, $context);
+ $this->driver()->info($message, $context);
}
/**
@@ -566,13 +558,11 @@ class LogManager implements LoggerInterface
* @param string $message
* @param array $context
*
- * @return mixed
- *
* @throws \Exception
*/
- public function debug($message, array $context = [])
+ public function debug($message, array $context = []): void
{
- return $this->driver()->debug($message, $context);
+ $this->driver()->debug($message, $context);
}
/**
@@ -582,13 +572,11 @@ class LogManager implements LoggerInterface
* @param string $message
* @param array $context
*
- * @return mixed
- *
* @throws \Exception
*/
- public function log($level, $message, array $context = [])
+ public function log($level, $message, array $context = []): void
{
- return $this->driver()->log($level, $message, $context);
+ $this->driver()->log($level, $message, $context);
}
/**
@@ -597,8 +585,6 @@ class LogManager implements LoggerInterface
* @param string $method
* @param array $parameters
*
- * @return mixed
- *
* @throws \Exception
*/
public function __call($method, $parameters)
diff --git a/src/Kernel/Messages/InteractiveTaskCard.php b/src/Kernel/Messages/InteractiveTaskCard.php
new file mode 100644
index 0000000..e0f7d13
--- /dev/null
+++ b/src/Kernel/Messages/InteractiveTaskCard.php
@@ -0,0 +1,49 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Kernel\Messages;
+
+/**
+ * Class InteractiveTaskCard.
+ *
+ * @description 企业微信 interactive_taskcard 任务卡片消息类型
+ *
+ * @author xyj2156
+ * @date 2021年5月25日 15:21:03
+ *
+ * @property string $title
+ * @property string $description
+ * @property string $url
+ * @property string $task_id
+ * @property array $btn
+ */
+class InteractiveTaskCard extends Message
+{
+ /**
+ * Messages type.
+ *
+ * @var string
+ */
+ protected $type = 'interactive_taskcard';
+
+ /**
+ * Properties.
+ *
+ * @var array
+ */
+ protected $properties = [
+ 'title',
+ 'description',
+ 'url',
+ 'task_id',
+ 'btn',
+ ];
+}
diff --git a/src/Kernel/Messages/Message.php b/src/Kernel/Messages/Message.php
index fda087c..3135cb1 100644
--- a/src/Kernel/Messages/Message.php
+++ b/src/Kernel/Messages/Message.php
@@ -23,22 +23,24 @@ abstract class Message implements MessageInterface
{
use HasAttributes;
- const TEXT = 2;
- const IMAGE = 4;
- const VOICE = 8;
- const VIDEO = 16;
- const SHORT_VIDEO = 32;
- const LOCATION = 64;
- const LINK = 128;
- const DEVICE_EVENT = 256;
- const DEVICE_TEXT = 512;
- const FILE = 1024;
- const TEXT_CARD = 2048;
- const TRANSFER = 4096;
- const EVENT = 1048576;
- const MINIPROGRAM_PAGE = 2097152;
- const ALL = self::TEXT | self::IMAGE | self::VOICE | self::VIDEO | self::SHORT_VIDEO | self::LOCATION | self::LINK
- | self::DEVICE_EVENT | self::DEVICE_TEXT | self::FILE | self::TEXT_CARD | self::TRANSFER | self::EVENT | self::MINIPROGRAM_PAGE;
+ public const TEXT = 2;
+ public const IMAGE = 4;
+ public const VOICE = 8;
+ public const VIDEO = 16;
+ public const SHORT_VIDEO = 32;
+ public const LOCATION = 64;
+ public const LINK = 128;
+ public const DEVICE_EVENT = 256;
+ public const DEVICE_TEXT = 512;
+ public const FILE = 1024;
+ public const TEXT_CARD = 2048;
+ public const TRANSFER = 4096;
+ public const EVENT = 1048576;
+ public const MINIPROGRAM_PAGE = 2097152;
+ public const MINIPROGRAM_NOTICE = 4194304;
+ public const ALL = self::TEXT | self::IMAGE | self::VOICE | self::VIDEO | self::SHORT_VIDEO | self::LOCATION | self::LINK
+ | self::DEVICE_EVENT | self::DEVICE_TEXT | self::FILE | self::TEXT_CARD | self::TRANSFER | self::EVENT
+ | self::MINIPROGRAM_PAGE | self::MINIPROGRAM_NOTICE;
/**
* @var string
diff --git a/src/Kernel/Messages/MiniprogramNotice.php b/src/Kernel/Messages/MiniprogramNotice.php
new file mode 100644
index 0000000..c18b259
--- /dev/null
+++ b/src/Kernel/Messages/MiniprogramNotice.php
@@ -0,0 +1,13 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Kernel\Messages;
+
+/**
+ * Class ReplyInteractiveTaskCard
+ *
+ * @property array{'replace_name':string} $properties
+ *
+ * @description 专门为回复 InteractiveTaskCard 类型任务卡片消息而创建的类型
+ * @author xyj2156
+ *
+ * @package App\Extend\EnterpriseApplication\BusinessWX\Message
+ */
+class ReplyInteractiveTaskCard extends Message
+{
+ /**
+ * Message Type
+ *
+ * @var string
+ */
+ protected $type = 'update_taskcard';
+
+ /**
+ * Properties.
+ *
+ * @var array
+ */
+ protected $properties = [
+ 'replace_name',
+ ];
+
+ /**
+ * ReplyInteractiveTaskCard constructor.
+ *
+ * @param string $replace_name
+ */
+ public function __construct(string $replace_name = '')
+ {
+ parent::__construct(compact('replace_name'));
+ }
+
+ public function toXmlArray()
+ {
+ return [
+ 'TaskCard' => [
+ 'ReplaceName' => $this->get('replace_name'),
+ ],
+ ];
+ }
+}
diff --git a/src/Kernel/Messages/Text.php b/src/Kernel/Messages/Text.php
index e355743..050e54a 100644
--- a/src/Kernel/Messages/Text.php
+++ b/src/Kernel/Messages/Text.php
@@ -37,7 +37,7 @@ class Text extends Message
*
* @param string $content
*/
- public function __construct(string $content)
+ public function __construct(string $content = '')
{
parent::__construct(compact('content'));
}
diff --git a/src/Kernel/Providers/ConfigServiceProvider.php b/src/Kernel/Providers/ConfigServiceProvider.php
index b33f4a1..24ff919 100644
--- a/src/Kernel/Providers/ConfigServiceProvider.php
+++ b/src/Kernel/Providers/ConfigServiceProvider.php
@@ -32,7 +32,7 @@ class ConfigServiceProvider implements ServiceProviderInterface
*/
public function register(Container $pimple)
{
- $pimple['config'] = function ($app) {
+ !isset($pimple['config']) && $pimple['config'] = function ($app) {
return new Config($app->getConfig());
};
}
diff --git a/src/Kernel/Providers/EventDispatcherServiceProvider.php b/src/Kernel/Providers/EventDispatcherServiceProvider.php
index 9095cef..97b2b99 100644
--- a/src/Kernel/Providers/EventDispatcherServiceProvider.php
+++ b/src/Kernel/Providers/EventDispatcherServiceProvider.php
@@ -32,7 +32,7 @@ class EventDispatcherServiceProvider implements ServiceProviderInterface
*/
public function register(Container $pimple)
{
- $pimple['events'] = function ($app) {
+ !isset($pimple['events']) && $pimple['events'] = function ($app) {
$dispatcher = new EventDispatcher();
foreach ($app->config->get('events.listen', []) as $event => $listeners) {
diff --git a/src/Kernel/Providers/ExtensionServiceProvider.php b/src/Kernel/Providers/ExtensionServiceProvider.php
index 23af832..1d8badd 100644
--- a/src/Kernel/Providers/ExtensionServiceProvider.php
+++ b/src/Kernel/Providers/ExtensionServiceProvider.php
@@ -32,7 +32,7 @@ class ExtensionServiceProvider implements ServiceProviderInterface
*/
public function register(Container $pimple)
{
- $pimple['extension'] = function ($app) {
+ !isset($pimple['extension']) && $pimple['extension'] = function ($app) {
return new Extension($app);
};
}
diff --git a/src/Kernel/Providers/HttpClientServiceProvider.php b/src/Kernel/Providers/HttpClientServiceProvider.php
index aca7fa9..e21edfa 100644
--- a/src/Kernel/Providers/HttpClientServiceProvider.php
+++ b/src/Kernel/Providers/HttpClientServiceProvider.php
@@ -32,7 +32,7 @@ class HttpClientServiceProvider implements ServiceProviderInterface
*/
public function register(Container $pimple)
{
- $pimple['http_client'] = function ($app) {
+ !isset($pimple['http_client']) && $pimple['http_client'] = function ($app) {
return new Client($app['config']->get('http', []));
};
}
diff --git a/src/Kernel/Providers/LogServiceProvider.php b/src/Kernel/Providers/LogServiceProvider.php
index 83498ac..88058bb 100644
--- a/src/Kernel/Providers/LogServiceProvider.php
+++ b/src/Kernel/Providers/LogServiceProvider.php
@@ -32,8 +32,8 @@ class LogServiceProvider implements ServiceProviderInterface
*/
public function register(Container $pimple)
{
- $pimple['logger'] = $pimple['log'] = function ($app) {
- $config = $this->formatLogConfig($app);
+ !isset($pimple['log']) && $pimple['log'] = function ($app) {
+ $config = $app['config']->get('log');
if (!empty($config)) {
$app->rebind('config', $app['config']->merge($config));
@@ -41,39 +41,7 @@ class LogServiceProvider implements ServiceProviderInterface
return new LogManager($app);
};
- }
-
- public function formatLogConfig($app)
- {
- if (!empty($app['config']->get('log.channels'))) {
- return $app['config']->get('log');
- }
-
- if (empty($app['config']->get('log'))) {
- return [
- 'log' => [
- 'default' => 'errorlog',
- 'channels' => [
- 'errorlog' => [
- 'driver' => 'errorlog',
- 'level' => 'debug',
- ],
- ],
- ],
- ];
- }
- return [
- 'log' => [
- 'default' => 'single',
- 'channels' => [
- 'single' => [
- 'driver' => 'single',
- 'path' => $app['config']->get('log.file') ?: \sys_get_temp_dir().'/logs/easywechat.log',
- 'level' => $app['config']->get('log.level', 'debug'),
- ],
- ],
- ],
- ];
+ !isset($pimple['logger']) && $pimple['logger'] = $pimple['log'];
}
}
diff --git a/src/Kernel/Providers/RequestServiceProvider.php b/src/Kernel/Providers/RequestServiceProvider.php
index a0b111d..d38522e 100644
--- a/src/Kernel/Providers/RequestServiceProvider.php
+++ b/src/Kernel/Providers/RequestServiceProvider.php
@@ -32,7 +32,7 @@ class RequestServiceProvider implements ServiceProviderInterface
*/
public function register(Container $pimple)
{
- $pimple['request'] = function () {
+ !isset($pimple['request']) && $pimple['request'] = function () {
return Request::createFromGlobals();
};
}
diff --git a/src/Kernel/ServerGuard.php b/src/Kernel/ServerGuard.php
index c135e12..066b220 100644
--- a/src/Kernel/ServerGuard.php
+++ b/src/Kernel/ServerGuard.php
@@ -45,12 +45,12 @@ class ServerGuard
/**
* Empty string.
*/
- const SUCCESS_EMPTY_RESPONSE = 'success';
+ public const SUCCESS_EMPTY_RESPONSE = 'success';
/**
* @var array
*/
- const MESSAGE_TYPE_MAPPING = [
+ public const MESSAGE_TYPE_MAPPING = [
'text' => Message::TEXT,
'image' => Message::IMAGE,
'voice' => Message::VOICE,
diff --git a/src/Kernel/ServiceContainer.php b/src/Kernel/ServiceContainer.php
index af1f35b..be1e0a1 100644
--- a/src/Kernel/ServiceContainer.php
+++ b/src/Kernel/ServiceContainer.php
@@ -64,11 +64,11 @@ class ServiceContainer extends Container
*/
public function __construct(array $config = [], array $prepends = [], string $id = null)
{
- $this->registerProviders($this->getProviders());
+ $this->userConfig = $config;
parent::__construct($prepends);
- $this->userConfig = $config;
+ $this->registerProviders($this->getProviders());
$this->id = $id;
diff --git a/src/Kernel/Support/Arr.php b/src/Kernel/Support/Arr.php
index ac34038..c251da2 100644
--- a/src/Kernel/Support/Arr.php
+++ b/src/Kernel/Support/Arr.php
@@ -181,7 +181,7 @@ class Arr
*
* @return array
*/
- public static function flatten(array $array, $depth = INF)
+ public static function flatten(array $array, $depth = \PHP_INT_MAX)
{
return array_reduce($array, function ($result, $item) use ($depth) {
$item = $item instanceof Collection ? $item->all() : $item;
diff --git a/src/Kernel/Support/Collection.php b/src/Kernel/Support/Collection.php
index adf24ea..d1b77a9 100644
--- a/src/Kernel/Support/Collection.php
+++ b/src/Kernel/Support/Collection.php
@@ -229,11 +229,17 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @return mixed data which can be serialized by json_encode,
* which is a value of any type other than a resource
*/
+ #[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->items;
}
+ public function __serialize(): array
+ {
+ return $this->items;
+ }
+
/**
* (PHP 5 >= 5.1.0)
* String representation of object.
@@ -256,6 +262,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @return \ArrayIterator An instance of an object implementing Iterator or
* Traversable
*/
+ #[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->items);
@@ -272,11 +279,17 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
*
* The return value is cast to an integer
*/
+ #[\ReturnTypeWillChange]
public function count()
{
return count($this->items);
}
+ public function __unserialize(array $data): void
+ {
+ $this->items = $data;
+ }
+
/**
* (PHP 5 >= 5.1.0)
* Constructs the object.
@@ -342,11 +355,13 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
/**
* var_export.
*
+ * @param array $properties
+ *
* @return array
*/
- public function __set_state()
+ public static function __set_state(array $properties)
{
- return $this->all();
+ return (new static($properties))->all();
}
/**
@@ -362,6 +377,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @return bool true on success or false on failure.
* The return value will be casted to boolean if non-boolean was returned
*/
+ #[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->has($offset);
@@ -377,6 +393,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* The offset to unset.
*
*/
+ #[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
@@ -396,6 +413,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
*
* @return mixed Can return all value types
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->offsetExists($offset) ? $this->get($offset) : null;
@@ -414,6 +432,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* The value to set.
*
*/
+ #[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->set($offset, $value);
diff --git a/src/Kernel/Support/XML.php b/src/Kernel/Support/XML.php
index 93026e6..1d22bc5 100644
--- a/src/Kernel/Support/XML.php
+++ b/src/Kernel/Support/XML.php
@@ -27,11 +27,11 @@ class XML
*/
public static function parse($xml)
{
- $backup = libxml_disable_entity_loader(true);
+ $backup = PHP_MAJOR_VERSION < 8 ? libxml_disable_entity_loader(true) : null;
$result = self::normalize(simplexml_load_string(self::sanitize($xml), 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_NOCDATA | LIBXML_NOBLANKS));
- libxml_disable_entity_loader($backup);
+ PHP_MAJOR_VERSION < 8 && libxml_disable_entity_loader($backup);
return $result;
}
diff --git a/src/Kernel/Traits/Observable.php b/src/Kernel/Traits/Observable.php
index bf0e216..ba46fd9 100644
--- a/src/Kernel/Traits/Observable.php
+++ b/src/Kernel/Traits/Observable.php
@@ -56,10 +56,10 @@ trait Observable
return $this->newClause($handler);
}
-
+
/**
* @param array $handlers
- *
+ *
* @return $this
*/
public function setHandlers(array $handlers = [])
@@ -157,7 +157,7 @@ trait Observable
case true === $response:
continue 2;
case false === $response:
- break 2;
+ break 3;
case !empty($response) && !($result instanceof FinallyResult):
$result = $response;
}
diff --git a/src/MicroMerchant/Kernel/BaseClient.php b/src/MicroMerchant/Kernel/BaseClient.php
index d91b467..6f49542 100644
--- a/src/MicroMerchant/Kernel/BaseClient.php
+++ b/src/MicroMerchant/Kernel/BaseClient.php
@@ -204,7 +204,7 @@ class BaseClient extends PaymentBaseClient
$encrypted = '';
$publicKeyResource = openssl_get_publickey($certificates);
- $f = openssl_public_encrypt($string, $encrypted, $publicKeyResource);
+ $f = openssl_public_encrypt($string, $encrypted, $publicKeyResource, OPENSSL_NO_PADDING);
openssl_free_key($publicKeyResource);
if ($f) {
return base64_encode($encrypted);
diff --git a/src/MiniProgram/Application.php b/src/MiniProgram/Application.php
index ee655a7..d012c2b 100644
--- a/src/MiniProgram/Application.php
+++ b/src/MiniProgram/Application.php
@@ -31,7 +31,7 @@ use EasyWeChat\Kernel\ServiceContainer;
* @property \EasyWeChat\MiniProgram\Plugin\DevClient $plugin_dev
* @property \EasyWeChat\MiniProgram\UniformMessage\Client $uniform_message
* @property \EasyWeChat\MiniProgram\ActivityMessage\Client $activity_message
- * @property \EasyWeChat\MiniProgram\Express\Client $logistics
+ * @property \EasyWeChat\MiniProgram\Express\Client $express
* @property \EasyWeChat\MiniProgram\NearbyPoi\Client $nearby_poi
* @property \EasyWeChat\MiniProgram\OCR\Client $ocr
* @property \EasyWeChat\MiniProgram\Soter\Client $soter
@@ -40,9 +40,24 @@ use EasyWeChat\Kernel\ServiceContainer;
* @property \EasyWeChat\MiniProgram\Mall\ForwardsMall $mall
* @property \EasyWeChat\MiniProgram\SubscribeMessage\Client $subscribe_message
* @property \EasyWeChat\MiniProgram\RealtimeLog\Client $realtime_log
+ * @property \EasyWeChat\MiniProgram\RiskControl\Client $risk_control
* @property \EasyWeChat\MiniProgram\Search\Client $search
* @property \EasyWeChat\MiniProgram\Live\Client $live
* @property \EasyWeChat\MiniProgram\Broadcast\Client $broadcast
+ * @property \EasyWeChat\MiniProgram\UrlScheme\Client $url_scheme
+ * @property \EasyWeChat\MiniProgram\Union\Client $union
+ * @property \EasyWeChat\MiniProgram\Shop\Register\Client $shop_register
+ * @property \EasyWeChat\MiniProgram\Shop\Basic\Client $shop_basic
+ * @property \EasyWeChat\MiniProgram\Shop\Account\Client $shop_account
+ * @property \EasyWeChat\MiniProgram\Shop\Spu\Client $shop_spu
+ * @property \EasyWeChat\MiniProgram\Shop\Order\Client $shop_order
+ * @property \EasyWeChat\MiniProgram\Shop\Delivery\Client $shop_delivery
+ * @property \EasyWeChat\MiniProgram\Shop\Aftersale\Client $shop_aftersale
+ * @property \EasyWeChat\MiniProgram\Business\Client $business
+ * @property \EasyWeChat\MiniProgram\UrlLink\Client $url_link
+ * @property \EasyWeChat\MiniProgram\QrCode\Client $qr_code
+ * @property \EasyWeChat\MiniProgram\PhoneNumber\Client $phone_number
+ * @property \EasyWeChat\MiniProgram\ShortLink\Client $short_link
*/
class Application extends ServiceContainer
{
@@ -60,6 +75,7 @@ class Application extends ServiceContainer
ActivityMessage\ServiceProvider::class,
OpenData\ServiceProvider::class,
Plugin\ServiceProvider::class,
+ QrCode\ServiceProvider::class,
Base\ServiceProvider::class,
Express\ServiceProvider::class,
NearbyPoi\ServiceProvider::class,
@@ -68,12 +84,27 @@ class Application extends ServiceContainer
Mall\ServiceProvider::class,
SubscribeMessage\ServiceProvider::class,
RealtimeLog\ServiceProvider::class,
+ RiskControl\ServiceProvider::class,
Search\ServiceProvider::class,
Live\ServiceProvider::class,
Broadcast\ServiceProvider::class,
+ UrlScheme\ServiceProvider::class,
+ UrlLink\ServiceProvider::class,
+ Union\ServiceProvider::class,
+ PhoneNumber\ServiceProvider::class,
+ ShortLink\ServiceProvider::class,
// Base services
BasicService\Media\ServiceProvider::class,
BasicService\ContentSecurity\ServiceProvider::class,
+
+ Shop\Register\ServiceProvider::class,
+ Shop\Basic\ServiceProvider::class,
+ Shop\Account\ServiceProvider::class,
+ Shop\Spu\ServiceProvider::class,
+ Shop\Order\ServiceProvider::class,
+ Shop\Delivery\ServiceProvider::class,
+ Shop\Aftersale\ServiceProvider::class,
+ Business\ServiceProvider::class,
];
/**
diff --git a/src/MiniProgram/Auth/AccessToken.php b/src/MiniProgram/Auth/AccessToken.php
index 8147d25..af08921 100644
--- a/src/MiniProgram/Auth/AccessToken.php
+++ b/src/MiniProgram/Auth/AccessToken.php
@@ -23,7 +23,7 @@ class AccessToken extends BaseAccessToken
/**
* @var string
*/
- protected $endpointToGetToken = 'https://api.weixin.qq.com/cgi-bin/token';
+ protected $endpointToGetToken = 'cgi-bin/token';
/**
* {@inheritdoc}
diff --git a/src/MiniProgram/Broadcast/Client.php b/src/MiniProgram/Broadcast/Client.php
index d0767f2..d9fd6ca 100644
--- a/src/MiniProgram/Broadcast/Client.php
+++ b/src/MiniProgram/Broadcast/Client.php
@@ -135,7 +135,7 @@ class Client extends BaseClient
return $this->httpPostJson('wxa/business/getgoodswarehouse', $params);
}
-
+
/**
* Get goods list based on status
*
@@ -148,7 +148,7 @@ class Client extends BaseClient
{
return $this->httpGet('wxaapi/broadcast/goods/getapproved', $params);
}
-
+
/**
* Add goods to the designated live room.
*
@@ -161,7 +161,7 @@ class Client extends BaseClient
{
return $this->httpPost('wxaapi/broadcast/room/addgoods', $params);
}
-
+
/**
* Get Room List.
*
@@ -178,10 +178,10 @@ class Client extends BaseClient
'start' => $start,
'limit' => $limit,
];
-
+
return $this->httpPostJson('wxa/business/getliveinfo', $params);
}
-
+
/**
* Get Playback List.
*
@@ -201,10 +201,10 @@ class Client extends BaseClient
'start' => $start,
'limit' => $limit,
];
-
+
return $this->httpPostJson('wxa/business/getliveinfo', $params);
}
-
+
/**
* Create a live room.
*
@@ -217,4 +217,323 @@ class Client extends BaseClient
{
return $this->httpPost('wxaapi/broadcast/room/create', $params);
}
+
+ /**
+ * Delete a live room.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function deleteLiveRoom(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/deleteroom', $params);
+ }
+
+ /**
+ * Update a live room.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateLiveRoom(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/editroom', $params);
+ }
+
+ /**
+ * Gets the live room push stream url.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getPushUrl(array $params)
+ {
+ return $this->httpGet('wxaapi/broadcast/room/getpushurl', $params);
+ }
+
+ /**
+ * Gets the live room share qrcode.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getShareQrcode(array $params)
+ {
+ return $this->httpGet('wxaapi/broadcast/room/getsharedcode', $params);
+ }
+
+ /**
+ * Add a live room assistant.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function addAssistant(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/addassistant', $params);
+ }
+
+ /**
+ * Update a live room assistant.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateAssistant(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/modifyassistant', $params);
+ }
+
+ /**
+ * Delete a live room assistant.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function deleteAssistant(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/removeassistant', $params);
+ }
+
+ /**
+ * Gets the assistant list.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getAssistantList(array $params)
+ {
+ return $this->httpGet('wxaapi/broadcast/room/getassistantlist', $params);
+ }
+
+ /**
+ * Add the sub anchor.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function addSubAnchor(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/addsubanchor', $params);
+ }
+
+ /**
+ * Update the sub anchor.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateSubAnchor(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/modifysubanchor', $params);
+ }
+
+ /**
+ * Delete the sub anchor.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function deleteSubAnchor(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/deletesubanchor', $params);
+ }
+
+ /**
+ * Gets the sub anchor info.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getSubAnchor(array $params)
+ {
+ return $this->httpGet('wxaapi/broadcast/room/getsubanchor', $params);
+ }
+
+ /**
+ * Turn official index on/off.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateFeedPublic(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/updatefeedpublic', $params);
+ }
+
+ /**
+ * Turn playback status on/off.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateReplay(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/updatereplay', $params);
+ }
+
+ /**
+ * Turn customer service status on/off.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateKf(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/updatekf', $params);
+ }
+
+ /**
+ * Turn global comments status on/off.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateComment(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/room/updatecomment', $params);
+ }
+
+ /**
+ * Add member role.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function addRole(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/role/addrole', $params);
+ }
+
+ /**
+ * Delete member role.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function deleteRole(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/role/deleterole', $params);
+ }
+
+ /**
+ * Gets the role list.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getRoleList(array $params)
+ {
+ return $this->httpGet('wxaapi/broadcast/role/getrolelist', $params);
+ }
+
+ /**
+ * Gets long-term subscribers.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getFollowers(array $params)
+ {
+ return $this->httpPost('wxa/business/get_wxa_followers', $params);
+ }
+
+ /**
+ * Sending live broadcast start event to long-term subscribers.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function pushMessage(array $params)
+ {
+ return $this->httpPost('wxa/business/push_message', $params);
+ }
+
+ /**
+ * Change the status of goods on/off shelves in room.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function updateGoodsInRoom(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/goods/onsale', $params);
+ }
+
+ /**
+ * Delete goods in room.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function deleteGoodsInRoom(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/goods/deleteInRoom', $params);
+ }
+
+ /**
+ * Push goods in room.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function pushGoods(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/goods/push', $params);
+ }
+
+ /**
+ * Change goods sort in room.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function sortGoods(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/goods/sort', $params);
+ }
+
+ /**
+ * Download goods explanation video.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function downloadGoodsExplanationVideo(array $params)
+ {
+ return $this->httpPost('wxaapi/broadcast/goods/getVideo', $params);
+ }
}
diff --git a/src/MiniProgram/Business/Client.php b/src/MiniProgram/Business/Client.php
new file mode 100644
index 0000000..b320b70
--- /dev/null
+++ b/src/MiniProgram/Business/Client.php
@@ -0,0 +1,149 @@
+
+ */
+class Client extends BaseClient
+{
+ /**
+ * Business register
+ * @param string $accountName
+ * @param string $nickname
+ * @param string $iconMediaId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function register(string $accountName, string $nickname, string $iconMediaId)
+ {
+ $params = [
+ 'account_name' => $accountName,
+ 'nickname' => $nickname,
+ 'icon_media_id' => $iconMediaId,
+ ];
+
+ return $this->httpPostJson('cgi-bin/business/register', $params);
+ }
+
+ /**
+ * Get business
+ * @param int $businessId
+ * @param string $accountName
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getBusiness(int $businessId = 0, string $accountName = '')
+ {
+ if (empty($businessId) && empty($accountName)) {
+ throw new InvalidArgumentException('Missing parameter.');
+ }
+ if ($businessId) {
+ $params = [
+ 'business_id' => $businessId,
+ ];
+ } else {
+ $params = [
+ 'account_name' => $accountName,
+ ];
+ }
+
+ return $this->httpPostJson('cgi-bin/business/get', $params);
+ }
+
+ /**
+ * Get business list
+ * @param int $offset
+ * @param int $count
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function list(int $offset = 0, int $count = 10)
+ {
+ $params = [
+ 'offset' => $offset,
+ 'count' => $count,
+ ];
+
+ return $this->httpPostJson('cgi-bin/business/list', $params);
+ }
+
+ /**
+ * Update business.
+ * @param int $businessId
+ * @param string $nickname
+ * @param string $iconMediaId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function update(int $businessId, string $nickname = '', string $iconMediaId = '')
+ {
+ $params = [
+ 'business_id' => $businessId,
+ 'nickname' => $nickname,
+ 'icon_media_id' => $iconMediaId,
+ ];
+
+ return $this->httpPostJson('cgi-bin/business/update', $params);
+ }
+
+ /**
+ * Get message builder.
+ *
+ * @param \EasyWeChat\Kernel\Messages\Message|string $message
+ *
+ * @return \EasyWeChat\MiniProgram\Business\Messenger
+ */
+ public function message($message)
+ {
+ $messageBuilder = new Messenger($this);
+
+ return $messageBuilder->message($message);
+ }
+
+ /**
+ * Send a message.
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function send(array $message)
+ {
+ return $this->httpPostJson('cgi-bin/message/custom/business/send', $message);
+ }
+
+ /**
+ * Typing status.
+ * @param int $businessId
+ * @param string $toUser openid
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function typing(int $businessId, string $toUser)
+ {
+ $params = [
+ 'business_id' => $businessId,
+ 'touser' => $toUser,
+ 'command' => 'Typing',
+ ];
+
+ return $this->httpPostJson('cgi-bin/business/typing', $params);
+ }
+}
diff --git a/src/MiniProgram/Business/Messenger.php b/src/MiniProgram/Business/Messenger.php
new file mode 100644
index 0000000..fee2e50
--- /dev/null
+++ b/src/MiniProgram/Business/Messenger.php
@@ -0,0 +1,179 @@
+
+ */
+class Messenger
+{
+ /**
+ * Messages to send.
+ *
+ * @var \EasyWeChat\Kernel\Messages\Message;
+ */
+ protected $message;
+
+ /**
+ * Messages target user open id.
+ *
+ * @var string
+ */
+ protected $to;
+
+ /**
+ * Messages sender staff id.
+ *
+ * @var string
+ */
+ protected $account;
+
+ /**
+ * Customer service instance.
+ *
+ * @var \EasyWeChat\MiniProgram\Business\Client
+ */
+ protected $client;
+
+ /**
+ * Messages businessId
+ *
+ * @var int
+ */
+ protected $businessId;
+
+ /**
+ * MessageBuilder constructor.
+ *
+ * @param \EasyWeChat\MiniProgram\Business\Client $client
+ */
+ public function __construct(Client $client)
+ {
+ $this->client = $client;
+ }
+
+ /**
+ * Set message to send.
+ *
+ * @param string|Message $message
+ *
+ * @return Messenger
+ */
+ public function message($message)
+ {
+ if (is_string($message)) {
+ $message = new Text($message);
+ }
+
+ $this->message = $message;
+
+ return $this;
+ }
+
+ /**
+ * Set staff account to send message.
+ *
+ * @return Messenger
+ */
+ public function by(string $account)
+ {
+ $this->account = $account;
+
+ return $this;
+ }
+
+ /**
+ * @return Messenger
+ */
+ public function from(string $account)
+ {
+ return $this->by($account);
+ }
+
+ /**
+ * Set target user open id.
+ *
+ * @param string $openid
+ *
+ * @return Messenger
+ */
+ public function to($openid)
+ {
+ $this->to = $openid;
+
+ return $this;
+ }
+
+ /**
+ * Set target business id.
+ *
+ * @param int $businessId
+ *
+ * @return Messenger
+ */
+ public function business($businessId)
+ {
+ $this->businessId = $businessId;
+
+ return $this;
+ }
+
+ /**
+ * Send the message.
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
+ */
+ public function send()
+ {
+ if (empty($this->message)) {
+ throw new RuntimeException('No message to send.');
+ }
+
+ if ($this->message instanceof RawMessage) {
+ $message = json_decode($this->message->get('content'), true);
+ } else {
+ $prepends = [
+ 'touser' => $this->to,
+ ];
+ if ($this->account) {
+ $prepends['customservice'] = ['kf_account' => $this->account];
+ }
+ if ($this->businessId) {
+ $prepends['businessid'] = $this->businessId;
+ }
+ $message = $this->message->transformForJsonRequest($prepends);
+ }
+
+ return $this->client->send($message);
+ }
+
+ /**
+ * Return property.
+ *
+ * @return mixed
+ */
+ public function __get(string $property)
+ {
+ if (property_exists($this, $property)) {
+ return $this->$property;
+ }
+
+ return null;
+ }
+}
diff --git a/src/MiniProgram/Business/ServiceProvider.php b/src/MiniProgram/Business/ServiceProvider.php
new file mode 100644
index 0000000..8a4c5d1
--- /dev/null
+++ b/src/MiniProgram/Business/ServiceProvider.php
@@ -0,0 +1,29 @@
+
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['business'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/DataCube/Client.php b/src/MiniProgram/DataCube/Client.php
index 8a10b7e..385ef45 100644
--- a/src/MiniProgram/DataCube/Client.php
+++ b/src/MiniProgram/DataCube/Client.php
@@ -150,6 +150,35 @@ class Client extends BaseClient
return $this->query('datacube/getweanalysisappiduserportrait', $from, $to);
}
+ /**
+ * get performance data
+ * @param string $from
+ * @param string $to
+ * @param string $module
+ * @param string $networktype
+ * @param string $device_level
+ * @param string $device
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function devicePerformanceData(string $from, string $to, string $module, string $networktype = '-1', string $device_level = '-1', string $device = '-1')
+ {
+ $payload = [
+ 'time' => [
+ 'end_timestamp' => strtotime($to),
+ 'begin_timestamp' => strtotime($from),
+ ],
+ 'module' => $module,
+ 'params' => [
+ ['field' => 'networktype', 'value' => $networktype],
+ ['field' => 'device_level', 'value' => $device_level],
+ ['field' => 'device', 'value' => $device],
+ ]
+ ];
+ return $this->httpPostJson('wxa/business/performance/boot', $payload);
+ }
+
/**
* Unify query.
*
diff --git a/src/MiniProgram/Express/Client.php b/src/MiniProgram/Express/Client.php
index 1877e09..86fd309 100644
--- a/src/MiniProgram/Express/Client.php
+++ b/src/MiniProgram/Express/Client.php
@@ -12,6 +12,7 @@
namespace EasyWeChat\MiniProgram\Express;
use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
/**
* Class Client.
@@ -20,6 +21,22 @@ use EasyWeChat\Kernel\BaseClient;
*/
class Client extends BaseClient
{
+ /**
+ * 绑定、解绑物流账号
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function bind(array $params = [])
+ {
+ if (empty($params['type']) || empty($params['biz_id']) || empty($params['delivery_id'])) {
+ throw new InvalidArgumentException('Missing parameter.');
+ }
+
+ return $this->httpPostJson('cgi-bin/express/business/account/bind', $params);
+ }
+
/**
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
@@ -30,6 +47,16 @@ class Client extends BaseClient
return $this->httpGet('cgi-bin/express/business/delivery/getall');
}
+ /**
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getAllAccount()
+ {
+ return $this->httpGet('cgi-bin/express/business/account/getall');
+ }
+
/**
* @param array $params
*
@@ -141,4 +168,41 @@ class Client extends BaseClient
'openid' => $openid,
]);
}
+
+ /**
+ * 创建退货 ID
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function createReturn(array $params = [])
+ {
+ return $this->httpPostJson('cgi-bin/express/delivery/return/add', $params);
+ }
+
+ /**
+ * 查询退货 ID 状态
+ * @param string $returnId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getReturn(string $returnId)
+ {
+ return $this->httpPostJson('cgi-bin/express/delivery/return/get', [
+ 'return_id' => $returnId
+ ]);
+ }
+
+ /**
+ * 解绑退货 ID
+ * @param string $returnId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function unbindReturn(string $returnId)
+ {
+ return $this->httpPostJson('cgi-bin/express/delivery/return/unbind', [
+ 'return_id' => $returnId
+ ]);
+ }
}
diff --git a/src/MiniProgram/OpenData/Client.php b/src/MiniProgram/OpenData/Client.php
index c9472c6..21da580 100644
--- a/src/MiniProgram/OpenData/Client.php
+++ b/src/MiniProgram/OpenData/Client.php
@@ -20,11 +20,6 @@ use EasyWeChat\Kernel\BaseClient;
*/
class Client extends BaseClient
{
- /**
- * @var string
- */
- protected $baseUri = 'https://api.weixin.qq.com/wxa/';
-
/**
* removeUserStorage.
*
@@ -46,7 +41,7 @@ class Client extends BaseClient
'signature' => hash_hmac('sha256', json_encode($data), $sessionKey),
];
- return $this->httpPostJson('remove_user_storage', $data, $query);
+ return $this->httpPostJson('wxa/remove_user_storage', $data, $query);
}
/**
@@ -72,7 +67,7 @@ class Client extends BaseClient
'signature' => hash_hmac('sha256', json_encode($data), $sessionKey),
];
- return $this->httpPostJson('set_user_storage', $data, $query);
+ return $this->httpPostJson('wxa/set_user_storage', $data, $query);
}
/**
diff --git a/src/MiniProgram/PhoneNumber/Client.php b/src/MiniProgram/PhoneNumber/Client.php
new file mode 100644
index 0000000..4052cae
--- /dev/null
+++ b/src/MiniProgram/PhoneNumber/Client.php
@@ -0,0 +1,47 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\MiniProgram\PhoneNumber;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ *
+ * @package EasyWeChat\MiniProgram\PhoneNumber
+ *
+ * @author 读心印
+ */
+class Client extends BaseClient
+{
+ /**
+ * 获取用户手机号.
+ *
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/phonenumber/phonenumber.getPhoneNumber.html
+ *
+ * @param string $code
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author 读心印
+ */
+ public function getUserPhoneNumber(string $code)
+ {
+ $params = [
+ 'code' => $code
+ ];
+
+ return $this->httpPostJson('wxa/business/getuserphonenumber', $params);
+ }
+}
diff --git a/src/MiniProgram/PhoneNumber/ServiceProvider.php b/src/MiniProgram/PhoneNumber/ServiceProvider.php
new file mode 100644
index 0000000..db4e76f
--- /dev/null
+++ b/src/MiniProgram/PhoneNumber/ServiceProvider.php
@@ -0,0 +1,28 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\MiniProgram\PhoneNumber;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['phone_number'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/QrCode/Client.php b/src/MiniProgram/QrCode/Client.php
new file mode 100644
index 0000000..2fb98e5
--- /dev/null
+++ b/src/MiniProgram/QrCode/Client.php
@@ -0,0 +1,126 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\MiniProgram\QrCode;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
+use EasyWeChat\Kernel\Support\Collection;
+use GuzzleHttp\Exception\GuzzleException;
+use Psr\Http\Message\ResponseInterface;
+
+/**
+ * QrCode Client
+ *
+ * 普通链接二维码
+ *
+ * @link https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/qrcode/qrcode.html
+ * @link https://developers.weixin.qq.com/miniprogram/introduction/qrcode.html
+ *
+ * @author dysodeng
+ */
+class Client extends BaseClient
+{
+ /**
+ * 获取已设置的二维码规则
+ *
+ * @return array|Collection|object|ResponseInterface|string
+ *
+ * @throws InvalidConfigException
+ * @throws GuzzleException
+ */
+ public function list()
+ {
+ return $this->httpPostJson('cgi-bin/wxopen/qrcodejumpget');
+ }
+
+ /**
+ * 获取校验文件名称及内容
+ *
+ * @return array|Collection|object|ResponseInterface|string
+ *
+ * @throws GuzzleException
+ * @throws InvalidConfigException
+ */
+ public function getVerifyFile()
+ {
+ return $this->httpPostJson('cgi-bin/wxopen/qrcodejumpdownload');
+ }
+
+ /**
+ * 增加或修改二维码规则
+ *
+ * @param array $params
+ *
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws GuzzleException
+ * @throws InvalidConfigException
+ */
+ public function set(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/wxopen/qrcodejumpadd', $params);
+ }
+
+ /**
+ * 发布已设置的二维码规则
+ *
+ * @param string $prefix
+ *
+ * @return array|Collection|object|ResponseInterface|string
+ *
+ * @throws GuzzleException
+ * @throws InvalidConfigException
+ */
+ public function publish(string $prefix)
+ {
+ $params = [
+ 'prefix' => $prefix
+ ];
+ return $this->httpPostJson('cgi-bin/wxopen/qrcodejumppublish', $params);
+ }
+
+ /**
+ * 删除已设置的二维码规则
+ *
+ * @param string $prefix
+ *
+ * @return array|Collection|object|ResponseInterface|string
+ *
+ * @throws GuzzleException
+ * @throws InvalidConfigException
+ */
+ public function delete(string $prefix)
+ {
+ $params = [
+ 'prefix' => $prefix
+ ];
+ return $this->httpPostJson('cgi-bin/wxopen/qrcodejumpdelete', $params);
+ }
+
+ /**
+ * 将二维码长链接转成短链接
+ *
+ * @param string $long_url
+ *
+ * @return array|Collection|object|ResponseInterface|string
+ *
+ * @throws GuzzleException
+ * @throws InvalidConfigException
+ */
+ public function shortUrl(string $long_url)
+ {
+ $params = [
+ 'long_url' => $long_url,
+ 'action' => 'long2short'
+ ];
+ return $this->httpPostJson('cgi-bin/shorturl', $params);
+ }
+}
diff --git a/src/MiniProgram/QrCode/ServiceProvider.php b/src/MiniProgram/QrCode/ServiceProvider.php
new file mode 100644
index 0000000..ee2a0aa
--- /dev/null
+++ b/src/MiniProgram/QrCode/ServiceProvider.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\MiniProgram\QrCode;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * QrCode ServiceProvider.
+ *
+ * @author dysodeng
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $pimple)
+ {
+ $pimple['qr_code'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/RiskControl/Client.php b/src/MiniProgram/RiskControl/Client.php
new file mode 100644
index 0000000..a6c00c0
--- /dev/null
+++ b/src/MiniProgram/RiskControl/Client.php
@@ -0,0 +1,32 @@
+httpPostJson('wxa/getuserriskrank', $params);
+ }
+}
diff --git a/src/MiniProgram/RiskControl/ServiceProvider.php b/src/MiniProgram/RiskControl/ServiceProvider.php
new file mode 100644
index 0000000..94d2758
--- /dev/null
+++ b/src/MiniProgram/RiskControl/ServiceProvider.php
@@ -0,0 +1,25 @@
+
+ */
+class Client extends BaseClient
+{
+ /**
+ * 获取商家类目列表
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getCategoryList()
+ {
+ return $this->httpPostJson('shop/account/get_category_list');
+ }
+
+ /**
+ * 获取商家品牌列表
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getBrandList()
+ {
+ return $this->httpPostJson('shop/account/get_brand_list');
+ }
+
+ /**
+ * 更新商家信息
+ *
+ * @param string $path 小程序path
+ * @param string $phone 客服联系方式
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function updateInfo(string $path = '', string $phone = '')
+ {
+ return $this->httpPostJson('shop/account/update_info', [
+ 'service_agent_path' => $path,
+ 'service_agent_phone' => $phone,
+ ]);
+ }
+
+ /**
+ * 获取商家信息
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getInfo()
+ {
+ return $this->httpPostJson('shop/account/get_info');
+ }
+}
diff --git a/src/MiniProgram/Shop/Account/ServiceProvider.php b/src/MiniProgram/Shop/Account/ServiceProvider.php
new file mode 100644
index 0000000..42e8bf8
--- /dev/null
+++ b/src/MiniProgram/Shop/Account/ServiceProvider.php
@@ -0,0 +1,25 @@
+
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function register(Container $app)
+ {
+ $app['shop_account'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/Shop/Aftersale/Client.php b/src/MiniProgram/Shop/Aftersale/Client.php
new file mode 100644
index 0000000..ebb83d1
--- /dev/null
+++ b/src/MiniProgram/Shop/Aftersale/Client.php
@@ -0,0 +1,54 @@
+
+ */
+class Client extends BaseClient
+{
+ /**
+ * 创建售后
+ *
+ * @param array $aftersale
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function add(array $aftersale)
+ {
+ return $this->httpPostJson('shop/ecaftersale/add', $aftersale);
+ }
+
+ /**
+ * 获取订单下售后单
+ *
+ * @param array $order 订单数据
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function get(array $order)
+ {
+ return $this->httpPostJson('shop/ecaftersale/get', $order);
+ }
+
+ /**
+ * 更新售后
+ *
+ * @param array $order 订单数据
+ * @param array $aftersale 售后数据
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function update(array $order, array $aftersale)
+ {
+ return $this->httpPostJson('shop/ecaftersale/update', array_merge($order, $aftersale));
+ }
+}
diff --git a/src/MiniProgram/Shop/Aftersale/ServiceProvider.php b/src/MiniProgram/Shop/Aftersale/ServiceProvider.php
new file mode 100644
index 0000000..91d9ab7
--- /dev/null
+++ b/src/MiniProgram/Shop/Aftersale/ServiceProvider.php
@@ -0,0 +1,25 @@
+
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * @inheritDoc
+ */
+ public function register(Container $app)
+ {
+ $app['shop_aftersale'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/Shop/Basic/Client.php b/src/MiniProgram/Shop/Basic/Client.php
new file mode 100644
index 0000000..b2cf95f
--- /dev/null
+++ b/src/MiniProgram/Shop/Basic/Client.php
@@ -0,0 +1,110 @@
+
+ */
+class Client extends BaseClient
+{
+ /**
+ * 获取商品类目
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getCat()
+ {
+ return $this->httpPostJson('shop/cat/get');
+ }
+
+ /**
+ * @param string $imageFilePath 图片文件路径
+ * @param int $respType 返回类型
+ * @param int $uploadType 上传类型,本地图片或者网络图片
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function imgUpload(string $imageFilePath, int $respType = 1, int $uploadType = 0)
+ {
+ if ($uploadType == 0) {
+ return $this->httpUpload('shop/img/upload', [
+ 'media' => $imageFilePath,
+ ], [
+ 'resp_type' => $respType,
+ ]);
+ } else {
+ return $this->httpPostJson('shop/img/upload', [], [
+ 'img_url' => $imageFilePath,
+ 'resp_type' => $respType,
+ 'upload_type' => $uploadType
+ ]);
+ }
+ }
+
+ /**
+ * 品牌审核
+ *
+ * @param array $brand 品牌信息
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function auditBrand(array $brand)
+ {
+ return $this->httpPostJson('shop/audit/audit_brand', [
+ 'audit_req' => $brand
+ ]);
+ }
+
+ /**
+ * 类目审核
+ *
+ * @param array $category 类目资质
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function auditCategory(array $category)
+ {
+ return $this->httpPostJson('shop/audit/audit_category', [
+ 'audit_req' => $category
+ ]);
+ }
+
+ /**
+ * 获取审核结果
+ *
+ * @param string $auditId 提交审核时返回的id
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function auditResult(string $auditId)
+ {
+ return $this->httpPostJson('shop/audit/result', [
+ 'audit_id' => $auditId
+ ]);
+ }
+
+ /**
+ * 获取小程序资质
+ *
+ * @param int $reqType
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getMiniAppCertificate(int $reqType = 2)
+ {
+ return $this->httpPostJson('shop/audit/get_miniapp_certificate', [
+ 'req_type' => $reqType
+ ]);
+ }
+}
diff --git a/src/MiniProgram/Shop/Basic/ServiceProvider.php b/src/MiniProgram/Shop/Basic/ServiceProvider.php
new file mode 100644
index 0000000..a8ed616
--- /dev/null
+++ b/src/MiniProgram/Shop/Basic/ServiceProvider.php
@@ -0,0 +1,25 @@
+
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * @inheritDoc
+ */
+ public function register(Container $app)
+ {
+ $app['shop_basic'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/Shop/Delivery/Client.php b/src/MiniProgram/Shop/Delivery/Client.php
new file mode 100644
index 0000000..c924034
--- /dev/null
+++ b/src/MiniProgram/Shop/Delivery/Client.php
@@ -0,0 +1,52 @@
+
+ */
+class Client extends BaseClient
+{
+ /**
+ * 获取快递公司列表
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getCompanyList()
+ {
+ return $this->httpPostJson('shop/delivery/get_company_list');
+ }
+
+ /**
+ * 订单发货
+ *
+ * @param array $order
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function send(array $order)
+ {
+ return $this->httpPostJson('shop/delivery/send', $order);
+ }
+
+ /**
+ * 订单确认收货
+ *
+ * @param array $order
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function recieve(array $order)
+ {
+ return $this->httpPostJson('shop/delivery/recieve', $order);
+ }
+}
diff --git a/src/MiniProgram/Shop/Delivery/ServiceProvider.php b/src/MiniProgram/Shop/Delivery/ServiceProvider.php
new file mode 100644
index 0000000..eb8ce16
--- /dev/null
+++ b/src/MiniProgram/Shop/Delivery/ServiceProvider.php
@@ -0,0 +1,25 @@
+
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * @inheritDoc
+ */
+ public function register(Container $app)
+ {
+ $app['shop_delivery'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/Shop/Order/Client.php b/src/MiniProgram/Shop/Order/Client.php
new file mode 100644
index 0000000..81a4cac
--- /dev/null
+++ b/src/MiniProgram/Shop/Order/Client.php
@@ -0,0 +1,157 @@
+
+ */
+class Client extends BaseClient
+{
+ /**
+ * 检查场景值是否在支付校验范围内
+ *
+ * @param int $scene 场景值
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function sceneCheck(int $scene)
+ {
+ return $this->httpPostJson('shop/scene/check', ['scene' => $scene]);
+ }
+
+ /**
+ * 生成订单
+ *
+ * @param array $order
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function create(array $order)
+ {
+ return $this->httpPostJson('shop/order/add', $order);
+ }
+
+ /**
+ * 生成订单
+ *
+ * @param array $order
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function add(array $order)
+ {
+ return $this->httpPostJson('shop/order/add', $order);
+ }
+
+ /**
+ * 获取订单详情
+ *
+ * @param string $openid 用户的openid
+ * @param array $orderId 微信侧订单id (订单id二选一)
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function get(string $openid, array $orderId)
+ {
+ return $this->httpPostJson('shop/order/get', array_merge($orderId, ['openid' => $openid]));
+ }
+
+ /**
+ * 关闭订单
+ *
+ * @param array $params 请求参数
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function close(array $params)
+ {
+ return $this->httpPostJson('shop/order/close', $params);
+ }
+
+ /**
+ * 获取订单列表
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getList(array $data)
+ {
+ return $this->httpPostJson('shop/order/get_list', $data);
+ }
+
+ /**
+ * 同步订单支付结果
+ *
+ * @param array $pay
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function pay(array $pay)
+ {
+ return $this->httpPostJson('shop/order/pay', $pay);
+ }
+
+ /**
+ * 同步订单支付结果
+ *
+ * @param array $pay
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function syncPayState(array $pay)
+ {
+ return $this->httpPostJson('shop/order/pay', $pay);
+ }
+
+ /**
+ * 同步订单支付结果
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getPayInfo(array $params)
+ {
+ return $this->httpPostJson('shop/order/getpaymentparams', $params);
+ }
+
+ /**
+ * 获取推广员订单
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getFinderOrders(array $params)
+ {
+ return $this->httpPostJson('shop/order/get_list_by_finder', $params);
+ }
+
+ /**
+ * 获取分享员订单
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getSharerOrders(array $params)
+ {
+ return $this->httpPostJson('shop/order/get_list_by_sharer', $params);
+ }
+}
diff --git a/src/MiniProgram/Shop/Order/ServiceProvider.php b/src/MiniProgram/Shop/Order/ServiceProvider.php
new file mode 100644
index 0000000..4b28114
--- /dev/null
+++ b/src/MiniProgram/Shop/Order/ServiceProvider.php
@@ -0,0 +1,25 @@
+
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * @inheritDoc
+ */
+ public function register(Container $app)
+ {
+ $app['shop_order'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/Shop/Register/Client.php b/src/MiniProgram/Shop/Register/Client.php
new file mode 100644
index 0000000..4667cee
--- /dev/null
+++ b/src/MiniProgram/Shop/Register/Client.php
@@ -0,0 +1,76 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\MiniProgram\Shop\Register;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ *
+ * @author her-cat
+ */
+class Client extends BaseClient
+{
+ /**
+ * 接入申请
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function apply()
+ {
+ return $this->httpPostJson('shop/register/apply');
+ }
+
+ /**
+ * 获取接入状态
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function check()
+ {
+ return $this->httpPostJson('shop/register/check');
+ }
+
+ /**
+ * 完成接入任务
+ *
+ * @param int $accessInfoItem
+ * 6:完成spu接口,7:完成订单接口,8:完成物流接口,9:完成售后接口,10:测试完成,11:发版完成
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function finishAccessInfo(int $accessInfoItem)
+ {
+ return $this->httpPostJson('shop/register/finish_access_info', [
+ 'access_info_item' => $accessInfoItem
+ ]);
+ }
+
+ /**
+ * 场景接入申请
+ *
+ * @param int $sceneGroupId 1:视频号、公众号场景
+
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function applyScene(int $sceneGroupId = 1)
+ {
+ return $this->httpPostJson('shop/register/apply_scene', [
+ 'scene_group_id' => $sceneGroupId
+ ]);
+ }
+}
diff --git a/src/MiniProgram/Shop/Register/ServiceProvider.php b/src/MiniProgram/Shop/Register/ServiceProvider.php
new file mode 100644
index 0000000..58fd286
--- /dev/null
+++ b/src/MiniProgram/Shop/Register/ServiceProvider.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\MiniProgram\Shop\Register;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider.
+ *
+ * @author her-cat
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function register(Container $app)
+ {
+ $app['shop_register'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/Shop/Spu/Client.php b/src/MiniProgram/Shop/Spu/Client.php
new file mode 100644
index 0000000..dc06fd1
--- /dev/null
+++ b/src/MiniProgram/Shop/Spu/Client.php
@@ -0,0 +1,132 @@
+
+ */
+class Client extends BaseClient
+{
+ /**
+ * 添加商品
+ *
+ * @param array $product 商品信息
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function add(array $product)
+ {
+ return $this->httpPostJson('shop/spu/add', $product);
+ }
+
+ /**
+ * 删除商品
+ *
+ * @param array $productId 商品编号信息
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function del(array $productId)
+ {
+ return $this->httpPostJson('shop/spu/del', $productId);
+ }
+
+ /**
+ * 获取商品
+ *
+ * @param array $productId 商品编号信息
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function get(array $productId)
+ {
+ return $this->httpPostJson('shop/spu/get', $productId);
+ }
+
+ /**
+ * 获取商品列表
+ *
+ * @param array $product 商品信息
+ * @param array $page 分页信息
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getList(array $product, array $page)
+ {
+ return $this->httpPostJson('shop/spu/get_list', array_merge($product, $page));
+ }
+
+ /**
+ * 撤回商品审核
+ *
+ * @param array $productId 商品编号信息 交易组件平台内部商品ID,与out_product_id二选一
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function delAudit(array $productId)
+ {
+ return $this->httpPostJson('shop/spu/del_audit', $productId);
+ }
+
+ /**
+ * 更新商品
+ *
+ * @param array $product
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function update(array $product)
+ {
+ return $this->httpPostJson('shop/spu/update', $product);
+ }
+
+ /**
+ * 该免审更新商品
+ *
+ * @param array $product
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function updateWithoutAudit(array $product)
+ {
+ return $this->httpPostJson('shop/spu/update_without_audit', $product);
+ }
+
+ /**
+ * 上架商品
+ *
+ * @param array $productId 商品编号数据 交易组件平台内部商品ID,与out_product_id二选一
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function listing(array $productId)
+ {
+ return $this->httpPostJson('shop/spu/listing', $productId);
+ }
+
+ /**
+ * 下架商品
+ *
+ * @param array $productId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function delisting(array $productId)
+ {
+ return $this->httpPostJson('shop/spu/delisting', $productId);
+ }
+}
diff --git a/src/MiniProgram/Shop/Spu/ServiceProvider.php b/src/MiniProgram/Shop/Spu/ServiceProvider.php
new file mode 100644
index 0000000..c87344d
--- /dev/null
+++ b/src/MiniProgram/Shop/Spu/ServiceProvider.php
@@ -0,0 +1,25 @@
+
+ * @package EasyWeChat\MiniProgram\Shop\Spu
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function register(Container $app)
+ {
+ $app['shop_spu'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/ShortLink/Client.php b/src/MiniProgram/ShortLink/Client.php
new file mode 100644
index 0000000..efce5f7
--- /dev/null
+++ b/src/MiniProgram/ShortLink/Client.php
@@ -0,0 +1,42 @@
+
+ */
+class Client extends BaseClient
+{
+ /**
+ * 获取小程序 Short Link
+ *
+ * @param string $pageUrl
+ * @param string $pageTitle
+ * @param bool $isPermanent
+ *
+ * @return array|Collection|object|ResponseInterface|string
+ *
+ * @throws GuzzleException
+ * @throws InvalidConfigException
+ */
+ public function getShortLink(string $pageUrl, string $pageTitle, bool $isPermanent = false)
+ {
+ $params = [
+ 'page_url' => $pageUrl,
+ 'page_title' => $pageTitle,
+ 'is_permanent' => $isPermanent,
+ ];
+
+ return $this->httpPostJson('wxa/genwxashortlink', $params);
+ }
+}
diff --git a/src/MiniProgram/ShortLink/ServiceProvider.php b/src/MiniProgram/ShortLink/ServiceProvider.php
new file mode 100644
index 0000000..79a28ec
--- /dev/null
+++ b/src/MiniProgram/ShortLink/ServiceProvider.php
@@ -0,0 +1,19 @@
+ '',
'page' => '',
'data' => [],
+ 'miniprogram_state' => 'formal',
];
/**
@@ -78,7 +79,7 @@ class Client extends BaseClient
foreach ($params['data'] as $key => $value) {
if (is_array($value)) {
- if (isset($value['value'])) {
+ if (\array_key_exists('value', $value)) {
$params['data'][$key] = ['value' => $value['value']];
continue;
diff --git a/src/MiniProgram/TemplateMessage/Client.php b/src/MiniProgram/TemplateMessage/Client.php
index 08f8a3b..06dfbcb 100644
--- a/src/MiniProgram/TemplateMessage/Client.php
+++ b/src/MiniProgram/TemplateMessage/Client.php
@@ -20,7 +20,7 @@ use EasyWeChat\OfficialAccount\TemplateMessage\Client as BaseClient;
*/
class Client extends BaseClient
{
- const API_SEND = 'cgi-bin/message/wxopen/template/send';
+ public const API_SEND = 'cgi-bin/message/wxopen/template/send';
/**
* {@inheritdoc}.
diff --git a/src/MiniProgram/UniformMessage/Client.php b/src/MiniProgram/UniformMessage/Client.php
index 6acb13e..0cc84fe 100644
--- a/src/MiniProgram/UniformMessage/Client.php
+++ b/src/MiniProgram/UniformMessage/Client.php
@@ -16,7 +16,7 @@ use EasyWeChat\OfficialAccount\TemplateMessage\Client as BaseClient;
class Client extends BaseClient
{
- const API_SEND = 'cgi-bin/message/wxopen/template/uniform_send';
+ public const API_SEND = 'cgi-bin/message/wxopen/template/uniform_send';
/**
* {@inheritdoc}.
diff --git a/src/MiniProgram/Union/Client.php b/src/MiniProgram/Union/Client.php
new file mode 100644
index 0000000..dd46d80
--- /dev/null
+++ b/src/MiniProgram/Union/Client.php
@@ -0,0 +1,228 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\MiniProgram\Union;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ *
+ * @author Abbotton
+ */
+class Client extends BaseClient
+{
+ /**
+ * Add promotion.
+ *
+ * @param string $promotionSourceName
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function createPromotion(string $promotionSourceName)
+ {
+ $params = [
+ 'promotionSourceName' => $promotionSourceName,
+ ];
+
+ return $this->httpPostJson('union/promoter/promotion/add', $params);
+ }
+
+ /**
+ * Delete promotion.
+ *
+ * @param string $promotionSourcePid
+ * @param string $promotionSourceName
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function deletePromotion(string $promotionSourcePid, string $promotionSourceName)
+ {
+ $params = [
+ 'promotionSourceName' => $promotionSourceName,
+ 'promotionSourcePid' => $promotionSourcePid,
+ ];
+
+ return $this->httpPostJson('union/promoter/promotion/del', $params);
+ }
+
+ /**
+ * Update promotion.
+ *
+ * @param array $previousPromotionInfo
+ * @param array $promotionInfo
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function updatePromotion(array $previousPromotionInfo, array $promotionInfo)
+ {
+ $params = [
+ 'previousPromotionInfo' => $previousPromotionInfo,
+ 'promotionInfo' => $promotionInfo,
+ ];
+
+ return $this->httpPostJson('union/promoter/promotion/upd', $params);
+ }
+
+ /**
+ * Get a list of promotion spots.
+ *
+ * @param int $start
+ * @param int $limit
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getPromotionSourceList(int $start = 0, int $limit = 20)
+ {
+ $params = [
+ 'start' => $start,
+ 'limit' => $limit
+ ];
+
+ return $this->httpGet('union/promoter/promotion/list', $params);
+ }
+
+ /**
+ * Get the list of affiliate product categories and category IDs.
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getProductCategory()
+ {
+ return $this->httpGet('union/promoter/product/category');
+ }
+
+ /**
+ * Get the list and detail of affiliate product.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getProductList(array $params)
+ {
+ return $this->httpGet('union/promoter/product/list', $params);
+ }
+
+ /**
+ * Get product promotion materials
+ *
+ * @param string $pid
+ * @param array $productList
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getProductMaterial(string $pid, array $productList)
+ {
+ $params = [
+ 'pid' => $pid,
+ 'productList' => $productList,
+ ];
+
+ return $this->httpPostJson('union/promoter/product/generate', $params);
+ }
+
+ /**
+ * Query order details based on order ID array.
+ *
+ * @param array $orderIdList
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getOrderInfo(array $orderIdList)
+ {
+ return $this->httpPostJson('union/promoter/order/info', $orderIdList);
+ }
+
+ /**
+ * Query and filter the order list.
+ *
+ * @param int $page
+ * @param string $startTimestamp
+ * @param string $endTimestamp
+ * @param string $commissionStatus
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function searchOrder(int $page = 1, $startTimestamp = '', $endTimestamp = '', $commissionStatus = '')
+ {
+ $params = [
+ 'page' => $page,
+ 'startTimestamp' => $startTimestamp,
+ 'endTimestamp' => $endTimestamp,
+ 'commissionStatus' => $commissionStatus
+ ];
+
+ return $this->httpGet('union/promoter/order/search', $params);
+ }
+
+ /**
+ * Get featured products of union.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getFeaturedProducts(array $params)
+ {
+ return $this->httpGet('union/promoter/product/select', $params);
+ }
+
+ /**
+ * Query the details of the targeted plan.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getTargetPlanInfo(array $params)
+ {
+ return $this->httpGet('union/promoter/target/plan_info', $params);
+ }
+
+ /**
+ * Apply to join the targeted plan.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function applyJoinTargetPlan(array $params)
+ {
+ return $this->httpPostJson('union/promoter/target/apply_target', $params);
+ }
+
+ /**
+ * Query the status of the targeted plan apply.
+ *
+ * @param array $params
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getTargetPlanStatus(array $params)
+ {
+ return $this->httpGet('union/promoter/target/apply_status', $params);
+ }
+}
diff --git a/src/MiniProgram/Union/ServiceProvider.php b/src/MiniProgram/Union/ServiceProvider.php
new file mode 100644
index 0000000..ba1207a
--- /dev/null
+++ b/src/MiniProgram/Union/ServiceProvider.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\MiniProgram\Union;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider.
+ *
+ * @author Abbotton
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['union'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/MiniProgram/UrlLink/Client.php b/src/MiniProgram/UrlLink/Client.php
new file mode 100644
index 0000000..45b189f
--- /dev/null
+++ b/src/MiniProgram/UrlLink/Client.php
@@ -0,0 +1,32 @@
+httpPostJson('wxa/generate_urllink', $param);
+ }
+}
diff --git a/src/MiniProgram/UrlLink/ServiceProvider.php b/src/MiniProgram/UrlLink/ServiceProvider.php
new file mode 100644
index 0000000..3201d36
--- /dev/null
+++ b/src/MiniProgram/UrlLink/ServiceProvider.php
@@ -0,0 +1,19 @@
+httpPostJson('wxa/generatescheme', $param);
+ }
+}
diff --git a/src/MiniProgram/UrlScheme/ServiceProvider.php b/src/MiniProgram/UrlScheme/ServiceProvider.php
new file mode 100644
index 0000000..cb8ad1a
--- /dev/null
+++ b/src/MiniProgram/UrlScheme/ServiceProvider.php
@@ -0,0 +1,19 @@
+ $cgiPath,
+ ];
+
+ return $this->httpPostJson('cgi-bin/openapi/quota/get', $params);
+ }
+
/**
* Clear quota.
*
diff --git a/src/OfficialAccount/Broadcasting/Client.php b/src/OfficialAccount/Broadcasting/Client.php
index 6c2eee1..4910a64 100644
--- a/src/OfficialAccount/Broadcasting/Client.php
+++ b/src/OfficialAccount/Broadcasting/Client.php
@@ -34,8 +34,8 @@ use EasyWeChat\Kernel\Support\Arr;
*/
class Client extends BaseClient
{
- const PREVIEW_BY_OPENID = 'touser';
- const PREVIEW_BY_NAME = 'towxname';
+ public const PREVIEW_BY_OPENID = 'touser';
+ public const PREVIEW_BY_NAME = 'towxname';
/**
* Send a message.
diff --git a/src/OfficialAccount/Card/Client.php b/src/OfficialAccount/Card/Client.php
index 5737d52..7395d09 100644
--- a/src/OfficialAccount/Card/Client.php
+++ b/src/OfficialAccount/Card/Client.php
@@ -77,7 +77,7 @@ class Client extends BaseClient
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function create($cardType = 'member_card', array $attributes)
+ public function create($cardType = 'member_card', array $attributes = [])
{
$params = [
'card' => [
diff --git a/src/OfficialAccount/Card/InvoiceClient.php b/src/OfficialAccount/Card/InvoiceClient.php
index 127b3af..ebf1e5f 100644
--- a/src/OfficialAccount/Card/InvoiceClient.php
+++ b/src/OfficialAccount/Card/InvoiceClient.php
@@ -98,6 +98,84 @@ class InvoiceClient extends BaseClient
return $this->httpPost('card/invoice/getauthdata', $params);
}
+ /**
+ * 创建卡券发票模板
+ *
+ * @param string $orderId
+ * @param string $appId
+ *
+ * @return mixed
+ */
+ public function createCard(array $params)
+ {
+ return $this->httpPostJson('/card/invoice/platform/createcard', $params);
+ }
+
+ /**
+ * 电子发票卡券插入用户卡包
+ *
+ * @param string $orderId
+ * @param string $appId
+ *
+ * @return mixed
+ */
+ public function insert(array $params)
+ {
+ return $this->httpPostJson('/card/invoice/insert', $params);
+ }
+
+ /**
+ * 更新发票卡券状态
+ *
+ * @param string $orderId
+ * @param string $appId
+ *
+ * @return mixed
+ */
+ public function updatestatus(array $params)
+ {
+ return $this->httpPostJson('/card/invoice/platform/updatestatus', $params);
+ }
+
+ /**
+ * 设置授权页字段信息接口.
+ *
+ * @param array $userData
+ * @param array $bizData
+ *
+ * @return mixed
+ */
+ public function setContact(array $params)
+ {
+ return $this->setBizAttr('set_contact', $params);
+ }
+
+ /**
+ * 获取授权页链接
+ *
+ * @param string $orderId
+ * @param string $appId
+ *
+ * @return mixed
+ */
+ public function getauthurl(array $params)
+ {
+ return $this->httpPostJson('/card/invoice/getauthurl', $params);
+ }
+
+ /**
+ * 创建卡券发票模板
+ *
+ * @param string $orderId
+ * @param string $appId
+ *
+ * @return mixed
+ */
+ public function setUrl()
+ {
+ return $this->httpPostJson('/card/invoice/seturl', []);
+ }
+
/**
* @param string $action
* @param array $params
diff --git a/src/OfficialAccount/Draft/Client.php b/src/OfficialAccount/Draft/Client.php
new file mode 100644
index 0000000..5c20698
--- /dev/null
+++ b/src/OfficialAccount/Draft/Client.php
@@ -0,0 +1,108 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OfficialAccount\Draft;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Messages\Article;
+
+/**
+ * Class Client.
+ *
+ * @author wangdongzhao
+ */
+class Client extends BaseClient
+{
+ /**
+ * Add new articles to the draft.
+ * @param array $articles
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function add(array $articles)
+ {
+ return $this->httpPostJson('cgi-bin/draft/add', $articles);
+ }
+
+ /**
+ * Get article from the draft.
+ * @param string $mediaId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function get(string $mediaId)
+ {
+ return $this->httpPostJson('cgi-bin/draft/get', ['media_id' => $mediaId]);
+ }
+
+ /**
+ * Update article
+ * @param string $mediaId
+ * @param int $index
+ * @param mixed $article
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function update(string $mediaId, int $index, $article)
+ {
+ $params = [
+ 'media_id' => $mediaId,
+ 'index' => $index,
+ 'articles' => $article
+ ];
+ return $this->httpPostJson('cgi-bin/draft/update', $params);
+ }
+
+ /**
+ * Get draft total count
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function count()
+ {
+ return $this->httpPostJson('cgi-bin/draft/count');
+ }
+
+ /**
+ * Batch get articles from the draft.
+ * @param int $offset
+ * @param int $count
+ * @param int $noContent
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function batchGet(int $offset = 0, int $count = 20, int $noContent = 0)
+ {
+ $params = [
+ 'offset' => $offset,
+ 'count' => $count,
+ 'no_content' => $noContent
+ ];
+ return $this->httpPostJson('cgi-bin/draft/batchget', $params);
+ }
+
+ /**
+ * Delete article.
+ * @param string $mediaId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function delete(string $mediaId)
+ {
+ return $this->httpPostJson('cgi-bin/draft/delete', ['media_id' => $mediaId]);
+ }
+}
diff --git a/src/OfficialAccount/Draft/ServiceProvider.php b/src/OfficialAccount/Draft/ServiceProvider.php
new file mode 100644
index 0000000..f38b8ea
--- /dev/null
+++ b/src/OfficialAccount/Draft/ServiceProvider.php
@@ -0,0 +1,35 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OfficialAccount\Draft;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider.
+ *
+ * @author wangdongzhao
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['draft'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OfficialAccount/FreePublish/Client.php b/src/OfficialAccount/FreePublish/Client.php
new file mode 100644
index 0000000..c885fcd
--- /dev/null
+++ b/src/OfficialAccount/FreePublish/Client.php
@@ -0,0 +1,90 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OfficialAccount\FreePublish;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Messages\Article;
+
+/**
+ * Class Client.
+ *
+ * @author wangdongzhao
+ */
+class Client extends BaseClient
+{
+ /**
+ * Get publish status.
+ * @param string $publishId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function get(string $publishId)
+ {
+ return $this->httpPostJson('cgi-bin/freepublish/get', ['publish_id' => $publishId]);
+ }
+
+ /**
+ * Submit article.
+ * @param string $mediaId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function submit(string $mediaId)
+ {
+ return $this->httpPostJson('cgi-bin/freepublish/submit', ['media_id' => $mediaId]);
+ }
+
+ /**
+ * Get article.
+ * @param string $articleId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getArticle(string $articleId)
+ {
+ return $this->httpPostJson('cgi-bin/freepublish/getarticle', ['article_id' => $articleId]);
+ }
+
+ /**
+ * Batch get articles.
+ * @param int $offset
+ * @param int $count
+ * @param int $noContent
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function batchGet(int $offset = 0, int $count = 20, int $noContent = 0)
+ {
+ $params = [
+ 'offset' => $offset,
+ 'count' => $count,
+ 'no_content' => $noContent
+ ];
+ return $this->httpPostJson('cgi-bin/freepublish/batchget', $params);
+ }
+
+ /**
+ * Delete article
+ * @param string $articleId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function delete(string $articleId)
+ {
+ return $this->httpPostJson('cgi-bin/freepublish/delete', ['article_id' => $articleId]);
+ }
+}
diff --git a/src/OfficialAccount/FreePublish/ServiceProvider.php b/src/OfficialAccount/FreePublish/ServiceProvider.php
new file mode 100644
index 0000000..a4696b5
--- /dev/null
+++ b/src/OfficialAccount/FreePublish/ServiceProvider.php
@@ -0,0 +1,35 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OfficialAccount\FreePublish;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider.
+ *
+ * @author wangdongzhao
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['free_publish'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OfficialAccount/Guide/Client.php b/src/OfficialAccount/Guide/Client.php
new file mode 100644
index 0000000..9c771dc
--- /dev/null
+++ b/src/OfficialAccount/Guide/Client.php
@@ -0,0 +1,991 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OfficialAccount\Guide;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
+use EasyWeChat\Kernel\Support\Collection;
+use Psr\Http\Message\ResponseInterface;
+
+/**
+ * Class Client.
+ *
+ * @author MillsGuo
+ */
+class Client extends BaseClient
+{
+ /**
+ * 添加顾问
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $guideHeadImgUrl
+ * @param string $guideNickname
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function createAdviser($guideAccount = '', $guideOpenid = '', $guideHeadImgUrl = '', $guideNickname = '')
+ {
+ $params = $this->selectAccountAndOpenid(array(), $guideAccount, $guideOpenid);
+ if (!empty($guideHeadImgUrl)) {
+ $params['guide_headimgurl'] = $guideHeadImgUrl;
+ }
+ if (!empty($guideNickname)) {
+ $params['guide_nickname'] = $guideNickname;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/addguideacct', $params);
+ }
+
+ /**
+ * 获取顾问信息
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getAdviser($guideAccount = '', $guideOpenid = '')
+ {
+ $params = $this->selectAccountAndOpenid(array(), $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/getguideacct', $params);
+ }
+
+ /**
+ * 修改顾问的昵称或头像
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $guideHeadImgUrl
+ * @param string $guideNickname
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function updateAdviser($guideAccount = '', $guideOpenid = '', $guideHeadImgUrl = '', $guideNickname = '')
+ {
+ $params = $this->selectAccountAndOpenid(array(), $guideAccount, $guideOpenid);
+ if (!empty($guideHeadImgUrl)) {
+ $params['guide_headimgurl'] = $guideHeadImgUrl;
+ }
+ if (!empty($guideNickname)) {
+ $params['guide_nickname'] = $guideNickname;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/updateguideacct', $params);
+ }
+
+ /**
+ * 删除顾问
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function deleteAdviser($guideAccount = '', $guideOpenid = '')
+ {
+ $params = $this->selectAccountAndOpenid(array(), $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/delguideacct', $params);
+ }
+
+ /**
+ * 获取服务号顾问列表
+ *
+ * @return mixed
+ *
+ * @throws InvalidConfigException
+ */
+ public function getAdvisers($count, $page)
+ {
+ $params = [
+ 'page' => $page,
+ 'num' => $count
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/getguideacctlist', $params);
+ }
+
+ /**
+ * 生成顾问二维码
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $qrCodeInfo
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function createQrCode($guideAccount = '', $guideOpenid = '', $qrCodeInfo = '')
+ {
+ $params = $this->selectAccountAndOpenid(array(), $guideAccount, $guideOpenid);
+ if (!empty($qrCodeInfo)) {
+ $params['qrcode_info'] = $qrCodeInfo;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/guidecreateqrcode', $params);
+ }
+
+ /**
+ * 获取顾问聊天记录
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $openid
+ * @param int $beginTime
+ * @param int $endTime
+ * @param int $page
+ * @param int $count
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getBuyerChatRecords($guideAccount = '', $guideOpenid = '', $openid = '', $beginTime = 0, $endTime = 0, $page = 1, $count = 100)
+ {
+ $params = [
+ 'page' => $page,
+ 'num' => $count
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+ if (!empty($openid)) {
+ $params['openid'] = $openid;
+ }
+ if (!empty($beginTime)) {
+ $params['begin_time'] = $beginTime;
+ }
+ if (!empty($endTime)) {
+ $params['end_time'] = $endTime;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/getguidebuyerchatrecord', $params);
+ }
+
+ /**
+ * 设置快捷回复与关注自动回复
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param bool $isDelete
+ * @param array $fastReplyListArray
+ * @param array $guideAutoReply
+ * @param array $guideAutoReplyPlus
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function setConfig($guideAccount = '', $guideOpenid = '', $isDelete = false, $fastReplyListArray = array(), $guideAutoReply = array(), $guideAutoReplyPlus = array())
+ {
+ $params = [
+ 'is_delete' => $isDelete
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+ if (!empty($fastReplyListArray)) {
+ $params['guide_fast_reply_list'] = $fastReplyListArray;
+ }
+ if (!empty($guideAutoReply)) {
+ $params['guide_auto_reply'] = $guideAutoReply;
+ }
+ if (!empty($guideAutoReplyPlus)) {
+ $params['guide_auto_reply_plus'] = $guideAutoReplyPlus;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/setguideconfig', $params);
+ }
+
+ /**
+ * 获取快捷回复与关注自动回复
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getConfig($guideAccount = '', $guideOpenid = '')
+ {
+ try {
+ $params = $this->selectAccountAndOpenid(array(), $guideAccount, $guideOpenid);
+ } catch (InvalidConfigException $e) {
+ $params = array();
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/getguideconfig', $params);
+ }
+
+ /**
+ * 设置离线自动回复与敏感词
+ * @param bool $isDelete
+ * @param array $blackKeyword
+ * @param array $guideAutoReply
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function setAdviserConfig(bool $isDelete, array $blackKeyword = [], array $guideAutoReply = [])
+ {
+ $params = [
+ 'is_delete' => $isDelete
+ ];
+ if (!empty($blackKeyword)) {
+ $params['black_keyword'] = $blackKeyword;
+ }
+ if (!empty($guideAutoReply)) {
+ $params['guide_auto_reply'] = $guideAutoReply;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/setguideacctconfig', $params);
+ }
+
+ /**
+ * 获取离线自动回复与敏感词
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getAdviserConfig()
+ {
+ return $this->httpPostJson('cgi-bin/guide/getguideacctconfig', array());
+ }
+
+ /**
+ * 允许微信用户复制小程序页面路径
+ * @param string $wxaAppid 小程序APPID
+ * @param string $wxUsername 微信用户的微信号
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function allowCopyMiniAppPath(string $wxaAppid, string $wxUsername)
+ {
+ $params = [
+ 'wxa_appid' => $wxaAppid,
+ 'wx_username' => $wxUsername
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/pushshowwxapathmenu', $params);
+ }
+
+ /**
+ * 传入微信号或OPENID二选一
+ * @param array $params
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @return array
+ * @throws InvalidConfigException
+ */
+ protected function selectAccountAndOpenid($params, $guideAccount = '', $guideOpenid = '')
+ {
+ if (!is_array($params)) {
+ throw new InvalidConfigException("传入配置参数必须为数组");
+ }
+ if (!empty($guideOpenid)) {
+ $params['guide_openid'] = $guideOpenid;
+ } elseif (!empty($guideAccount)) {
+ $params['guide_account'] = $guideAccount;
+ } else {
+ throw new InvalidConfigException("微信号和OPENID不能同时为空");
+ }
+
+ return $params;
+ }
+
+ /**
+ * 新建顾问分组
+ * @param string $groupName
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function createGroup(string $groupName)
+ {
+ $params = [
+ 'group_name' => $groupName
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/newguidegroup', $params);
+ }
+
+ /**
+ * 获取顾问分组列表
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getGuideGroups()
+ {
+ return $this->httpPostJson('cgi-bin/guide/getguidegrouplist', array());
+ }
+
+ /**
+ * 获取指定顾问分组信息
+ * @param int $groupId
+ * @param int $page
+ * @param int $num
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getGroups(int $groupId, int $page, int $num)
+ {
+ $params = [
+ 'group_id' => $groupId,
+ 'page' => $page,
+ 'num' => $num
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/getgroupinfo', $params);
+ }
+
+ /**
+ * 分组内添加顾问
+ * @param int $groupId
+ * @param string $guideAccount
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function addGroupGuide(int $groupId, string $guideAccount)
+ {
+ $params = [
+ 'group_id' => $groupId,
+ 'gruide_account' => $guideAccount
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/addguide2guidegroup', $params);
+ }
+
+ /**
+ * 分组内删除顾问
+ * @param int $groupId
+ * @param string $guideAccount
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function deleteGroupGuide(int $groupId, string $guideAccount)
+ {
+ $params = [
+ 'group_id' => $groupId,
+ 'guide_account' => $guideAccount
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/delguide2guidegroup', $params);
+ }
+
+ /**
+ * 获取顾问所在分组
+ * @param string $guideAccount
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getGuideGroup(string $guideAccount)
+ {
+ $params = [
+ 'guide_account' => $guideAccount
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/getgroupbyguide', $params);
+ }
+
+ /**
+ * 删除指定顾问分组
+ * @param int $groupId
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function deleteGroup(int $groupId)
+ {
+ $params = [
+ 'group_id' => $groupId
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/delguidegroup', $params);
+ }
+
+ /**
+ * 为顾问分配客户
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param array $buyerList
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function createBuyerRelation(string $guideAccount, string $guideOpenid, array $buyerList)
+ {
+ $params = [
+ 'buyer_list' => $buyerList
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/addguidebuyerrelation', $params);
+ }
+
+ /**
+ * 为顾问移除客户
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param array $openidList
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function deleteBuyerRelation(string $guideAccount, string $guideOpenid, array $openidList)
+ {
+ $params = [
+ 'openid_list' => $openidList
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/delguidebuyerrelation', $params);
+ }
+
+ /**
+ * 获取顾问的客户列表
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param int $page
+ * @param int $num
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getBuyerRelations(string $guideAccount, string $guideOpenid, int $page, int $num)
+ {
+ $params = [
+ 'page' => $page,
+ 'num' => $num
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/getguidebuyerrelationlist', $params);
+ }
+
+ /**
+ * 为客户更换顾问
+ * @param string $oldGuideTarget
+ * @param string $newGuideTarget
+ * @param array $openidList
+ * @param bool $useTargetOpenid true使用OPENID,false使用微信号
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function rebindBuyerGuide(string $oldGuideTarget, string $newGuideTarget, array $openidList, bool $useTargetOpenid = true)
+ {
+ $params = [
+ 'openid_list' => $openidList
+ ];
+ if ($useTargetOpenid) {
+ $params['old_guide_openid'] = $oldGuideTarget;
+ $params['new_guide_openid'] = $newGuideTarget;
+ } else {
+ $params['old_guide_account'] = $oldGuideTarget;
+ $params['new_guide_account'] = $newGuideTarget;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/rebindguideacctforbuyer', $params);
+ }
+
+ /**
+ * 修改客户昵称
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $openid
+ * @param string $nickname
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function updateBuyerRelation(string $guideAccount, string $guideOpenid, string $openid, string $nickname)
+ {
+ $params = [
+ 'openid' => $openid,
+ 'buyer_nickname' => $nickname
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/updateguidebuyerrelation', $params);
+ }
+
+ /**
+ * 查询客户所属顾问
+ * @param string $openid
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getBuyerRelation(string $openid)
+ {
+ $params = [
+ 'openid' => $openid
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/getguidebuyerrelationbybuyer', $params);
+ }
+
+ /**
+ * 查询指定顾问和客户的关系
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $openid
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getBuyerRelationByGuide(string $guideAccount, string $guideOpenid, string $openid)
+ {
+ $params = [
+ 'openid' => $openid
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/getguidebuyerrelation', $params);
+ }
+
+ /**
+ * 新建可查询的标签类型
+ * @param string $tagName
+ * @param array $tagValues
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function newTagOption(string $tagName, array $tagValues)
+ {
+ $params = [
+ 'tag_name' => $tagName,
+ 'tag_values' => $tagValues
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/newguidetagoption', $params);
+ }
+
+ /**
+ * 删除指定标签类型
+ * @param string $tagName
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function deleteTagOption(string $tagName)
+ {
+ $params = [
+ 'tag_name' => $tagName
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/delguidetagoption', $params);
+ }
+
+ /**
+ * 为标签添加可选值
+ * @param string $tagName
+ * @param array $tagValues
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function createTagOption(string $tagName, array $tagValues)
+ {
+ $params = [
+ 'tag_name' => $tagName,
+ 'tag_values' => $tagValues
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/addguidetagoption', $params);
+ }
+
+ /**
+ * 获取标签和可选值
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getTagOption()
+ {
+ return $this->httpPostJson('cgi-bin/guide/getguidetagoption', array());
+ }
+
+ /**
+ * 为客户设置标签
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param array $openidList
+ * @param string $tagValue
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function setBuyersTag(string $guideAccount, string $guideOpenid, array $openidList, string $tagValue)
+ {
+ $params = [
+ 'tag_value' => $tagValue,
+ 'openid_list' => $openidList
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/addguidebuyertag', $params);
+ }
+
+ /**
+ * 查询客户标签
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $openid
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getBuyerTags(string $guideAccount, string $guideOpenid, string $openid)
+ {
+ $params = [
+ 'openid' => $openid
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/getguidebuyertag', $params);
+ }
+
+ /**
+ * 根据标签值筛选粉丝
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param int $pushCount
+ * @param array $tagValues
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getBuyerByTag(string $guideAccount, string $guideOpenid, int $pushCount = 0, array $tagValues = array())
+ {
+ $params = $this->selectAccountAndOpenid(array(), $guideAccount, $guideOpenid);
+ if ($pushCount > 0) {
+ $params['push_count'] = $pushCount;
+ }
+ if (count($tagValues) > 0) {
+ $params['tag_values'] = $tagValues;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/queryguidebuyerbytag', $params);
+ }
+
+ /**
+ * 删除客户标签
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $tagValue
+ * @param array $openidList
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function deleteBuyerTag(string $guideAccount, string $guideOpenid, string $tagValue, array $openidList)
+ {
+ $params = [
+ 'tag_value' => $tagValue
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+ if (count($openidList) > 0) {
+ $params['openid_list'] = $openidList;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/delguidebuyertag', $params);
+ }
+
+ /**
+ * 设置自定义客户信息
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $openid
+ * @param array $displayTagList
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function setBuyerDisplayTags(string $guideAccount, string $guideOpenid, string $openid, array $displayTagList)
+ {
+ $params = [
+ 'openid' => $openid,
+ 'display_tag_list' => $displayTagList
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/addguidebuyerdisplaytag', $params);
+ }
+
+ /**
+ * 获取自定义客户信息
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $openid
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getBuyerDisplayTags(string $guideAccount, string $guideOpenid, string $openid)
+ {
+ $params = [
+ 'openid' => $openid
+ ];
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/getguidebuyerdisplaytag', $params);
+ }
+
+ /**
+ * 添加小程序卡片素材
+ * @param string $mediaId
+ * @param string $title
+ * @param string $path
+ * @param string $appid
+ * @param int $type
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function createCardMaterial(string $mediaId, string $title, string $path, string $appid, int $type = 0)
+ {
+ $params = [
+ 'media_id' => $mediaId,
+ 'type' => $type,
+ 'title' => $title,
+ 'path' => $path,
+ 'appid' => $appid
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/setguidecardmaterial', $params);
+ }
+
+ /**
+ * 查询小程序卡片素材
+ * @param int $type
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getCardMaterial(int $type = 0)
+ {
+ $params = [
+ 'type' => $type
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/getguidecardmaterial', $params);
+ }
+
+ /**
+ * 删除小程序卡片素材
+ * @param string $title
+ * @param string $path
+ * @param string $appid
+ * @param int $type
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function deleteCardMaterial(string $title, string $path, string $appid, int $type = 0)
+ {
+ $params = [
+ 'type' => $type,
+ 'title' => $title,
+ 'path' => $path,
+ 'appid' => $appid
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/delguidecardmaterial', $params);
+ }
+
+ /**
+ * 添加图片素材
+ * @param string $mediaId
+ * @param int $type
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function createImageMaterial(string $mediaId, int $type = 0)
+ {
+ $params = [
+ 'media_id' => $mediaId,
+ 'type' => $type
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/setguideimagematerial', $params);
+ }
+
+ /**
+ * 查询图片素材
+ * @param int $type
+ * @param int $start
+ * @param int $num
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getImageMaterial(int $type, int $start, int $num)
+ {
+ $params = [
+ 'type' => $type,
+ 'start' => $start,
+ 'num' => $num
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/getguideimagematerial', $params);
+ }
+
+ /**
+ * 删除图片素材
+ * @param int $type
+ * @param string $picUrl
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function deleteImageMaterial(int $type, string $picUrl)
+ {
+ $params = [
+ 'type' => $type,
+ 'picurl' => $picUrl
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/delguideimagematerial', $params);
+ }
+
+ /**
+ * 添加文字素材
+ * @param int $type
+ * @param string $word
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function createWordMaterial(int $type, string $word)
+ {
+ $params = [
+ 'type' => $type,
+ 'word' => $word
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/setguidewordmaterial', $params);
+ }
+
+ /**
+ * 查询文字素材
+ * @param int $type
+ * @param int $start
+ * @param int $num
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getWordMaterial(int $type, int $start, int $num)
+ {
+ $params = [
+ 'type' => $type,
+ 'start' => $start,
+ 'num' => $num
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/getguidewordmaterial', $params);
+ }
+
+ /**
+ * 删除文字素材
+ * @param int $type
+ * @param string $word
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function deleteWordMaterial(int $type, string $word)
+ {
+ $params = [
+ 'type' => $type,
+ 'word' => $word
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/delguidewordmaterial', $params);
+ }
+
+ /**
+ * 添加群发任务,为指定顾问添加群发任务
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param string $taskName
+ * @param string $taskRemark
+ * @param int $pushTime
+ * @param array $openidArray
+ * @param array $materialArray
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function createMasSendJob(string $guideAccount, string $guideOpenid, string $taskName, string $taskRemark, int $pushTime, array $openidArray, array $materialArray)
+ {
+ $params = [
+ 'task_name' => $taskName,
+ 'push_time' => $pushTime,
+ 'openid' => $openidArray,
+ 'material' => $materialArray
+ ];
+ if (!empty($taskRemark)) {
+ $params['task_remark'] = $taskRemark;
+ }
+ $params = $this->selectAccountAndOpenid($params, $guideAccount, $guideOpenid);
+
+ return $this->httpPostJson('cgi-bin/guide/addguidemassendjob', $params);
+ }
+
+ /**
+ * 获取群发任务列表
+ * @param string $guideAccount
+ * @param string $guideOpenid
+ * @param array $taskStatus
+ * @param int $offset
+ * @param int $limit
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getMasSendJobs(string $guideAccount, string $guideOpenid, array $taskStatus = [], int $offset = 0, int $limit = 50)
+ {
+ $params = $this->selectAccountAndOpenid(array(), $guideAccount, $guideOpenid);
+ if (!empty($taskStatus)) {
+ $params['task_status'] = $taskStatus;
+ }
+ if ($offset > 0) {
+ $params['offset'] = $offset;
+ }
+ if ($limit != 50) {
+ $params['limit'] = $limit;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/getguidemassendjoblist', $params);
+ }
+
+ /**
+ * 获取指定群发任务信息
+ * @param string $taskId
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function getMasSendJob(string $taskId)
+ {
+ $params = [
+ 'task_id' => $taskId
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/getguidemassendjob', $params);
+ }
+
+ /**
+ * 修改群发任务
+ * @param string $taskId
+ * @param string $taskName
+ * @param string $taskRemark
+ * @param int $pushTime
+ * @param array $openidArray
+ * @param array $materialArray
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function updateMasSendJob(string $taskId, string $taskName, string $taskRemark, int $pushTime, array $openidArray, array $materialArray)
+ {
+ $params = [
+ 'task_id' => $taskId
+ ];
+ if (!empty($taskName)) {
+ $params['task_name'] = $taskName;
+ }
+ if (!empty($taskRemark)) {
+ $params['task_remark'] = $taskRemark;
+ }
+ if (!empty($pushTime)) {
+ $params['push_time'] = $pushTime;
+ }
+ if (!empty($openidArray)) {
+ $params['openid'] = $openidArray;
+ }
+ if (!empty($materialArray)) {
+ $params['material'] = $materialArray;
+ }
+
+ return $this->httpPostJson('cgi-bin/guide/updateguidemassendjob', $params);
+ }
+
+ /**
+ * 取消群发任务
+ * @param string $taskId
+ * @return array|Collection|object|ResponseInterface|string
+ * @throws InvalidConfigException
+ */
+ public function cancelMasSendJob(string $taskId)
+ {
+ $params = [
+ 'task_id' => $taskId
+ ];
+
+ return $this->httpPostJson('cgi-bin/guide/cancelguidemassendjob', $params);
+ }
+}
diff --git a/src/OfficialAccount/Guide/ServiceProvider.php b/src/OfficialAccount/Guide/ServiceProvider.php
new file mode 100644
index 0000000..46ebbca
--- /dev/null
+++ b/src/OfficialAccount/Guide/ServiceProvider.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OfficialAccount\Guide;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider.
+ *
+ * @author millsguo
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['guide'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OfficialAccount/OAuth/ServiceProvider.php b/src/OfficialAccount/OAuth/ServiceProvider.php
index ba176dc..c9588c4 100644
--- a/src/OfficialAccount/OAuth/ServiceProvider.php
+++ b/src/OfficialAccount/OAuth/ServiceProvider.php
@@ -28,15 +28,24 @@ class ServiceProvider implements ServiceProviderInterface
public function register(Container $app)
{
$app['oauth'] = function ($app) {
- $socialite = (new Socialite([
+ $wechat = [
'wechat' => [
'client_id' => $app['config']['app_id'],
'client_secret' => $app['config']['secret'],
'redirect' => $this->prepareCallbackUrl($app),
],
- ], $app['request']))->driver('wechat');
+ ];
- $scopes = (array) $app['config']->get('oauth.scopes', ['snsapi_userinfo']);
+ if (!empty($app['config']['component_app_id'] && !empty($app['config']['component_app_token']))) {
+ $wechat['wechat']['component'] = [
+ 'id' => $app['config']['component_app_id'],
+ 'token' => $app['config']['token'],
+ ] ;
+ }
+
+ $socialite = (new Socialite($wechat))->create('wechat');
+
+ $scopes = (array)$app['config']->get('oauth.scopes', ['snsapi_userinfo']);
if (!empty($scopes)) {
$socialite->scopes($scopes);
@@ -61,6 +70,6 @@ class ServiceProvider implements ServiceProviderInterface
}
$baseUrl = $app['request']->getSchemeAndHttpHost();
- return $baseUrl.'/'.ltrim($callback, '/');
+ return $baseUrl . '/' . ltrim($callback, '/');
}
}
diff --git a/src/OfficialAccount/OCR/Client.php b/src/OfficialAccount/OCR/Client.php
index 7527e5e..57b5da5 100644
--- a/src/OfficialAccount/OCR/Client.php
+++ b/src/OfficialAccount/OCR/Client.php
@@ -38,7 +38,6 @@ class Client extends BaseClient
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
*/
public function idCard(string $path, string $type = 'photo')
{
@@ -46,7 +45,7 @@ class Client extends BaseClient
throw new InvalidArgumentException(sprintf("Unsupported type: '%s'", $type));
}
- return $this->httpPostJson('cv/ocr/idcard', [], [
+ return $this->httpPost('cv/ocr/idcard', [
'type' => $type,
'img_url' => $path,
]);
@@ -57,21 +56,13 @@ class Client extends BaseClient
*
* @param string $path
*
- * @param string $type
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws InvalidArgumentException
*/
- public function bankCard(string $path, string $type = 'photo')
+ public function bankCard(string $path)
{
- if (!\in_array($type, $this->allowTypes, true)) {
- throw new InvalidArgumentException(sprintf("Unsupported type: '%s'", $type));
- }
-
- return $this->httpPostJson('cv/ocr/bankcard', [], [
- 'type' => $type,
+ return $this->httpPost('cv/ocr/bankcard', [
'img_url' => $path,
]);
}
@@ -81,73 +72,77 @@ class Client extends BaseClient
*
* @param string $path
*
- * @param string $type
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws InvalidArgumentException
*/
- public function vehicleLicense(string $path, string $type = 'photo')
+ public function vehicleLicense(string $path)
{
- if (!\in_array($type, $this->allowTypes, true)) {
- throw new InvalidArgumentException(sprintf("Unsupported type: '%s'", $type));
- }
-
- return $this->httpPostJson('cv/ocr/driving', [], [
- 'type' => $type,
+ return $this->httpPost('cv/ocr/drivinglicense', [
'img_url' => $path,
]);
}
/**
- * Driver License OCR.
+ * Driving OCR.
*
* @param string $path
- * @param string $type
+ *
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws InvalidArgumentException
*/
- public function driverLicense(string $path, string $type = 'photo')
+ public function driving(string $path)
{
- if (!\in_array($type, $this->allowTypes, true)) {
- throw new InvalidArgumentException(sprintf("Unsupported type: '%s'", $type));
- }
+ return $this->httpPost('cv/ocr/driving', [
+ 'img_url' => $path,
+ ]);
+ }
- return $this->httpPostJson('cv/ocr/drivinglicense', [], [
- 'type' => $type,
+ /**
+ * Biz License OCR.
+ *
+ * @param string $path
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function bizLicense(string $path)
+ {
+ return $this->httpPost('cv/ocr/bizlicense', [
'img_url' => $path,
]);
}
/**
- * Business License OCR.
+ * Common OCR.
*
* @param string $path
+ *
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function businessLicense(string $path)
+ public function common(string $path)
{
- return $this->httpPostJson('cv/ocr/bizlicense', [], [
+ return $this->httpPost('cv/ocr/comm', [
'img_url' => $path,
]);
}
/**
- * Printed Text OCR.
+ * Plate Number OCR.
*
* @param string $path
+ *
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function printedText(string $path)
+ public function plateNumber(string $path)
{
- return $this->httpPostJson('cv/ocr/comm', [], [
+ return $this->httpPost('cv/ocr/platenum', [
'img_url' => $path,
]);
}
diff --git a/src/OfficialAccount/Server/Handlers/EchoStrHandler.php b/src/OfficialAccount/Server/Handlers/EchoStrHandler.php
index f076abf..e985692 100644
--- a/src/OfficialAccount/Server/Handlers/EchoStrHandler.php
+++ b/src/OfficialAccount/Server/Handlers/EchoStrHandler.php
@@ -47,5 +47,7 @@ class EchoStrHandler implements EventHandlerInterface
if ($str = $this->app['request']->get('echostr')) {
return new FinallyResult($str);
}
+
+ return null;
}
}
diff --git a/src/OfficialAccount/ShakeAround/ShakeAround.php b/src/OfficialAccount/ShakeAround/ShakeAround.php
index 666a38a..adcfcb4 100644
--- a/src/OfficialAccount/ShakeAround/ShakeAround.php
+++ b/src/OfficialAccount/ShakeAround/ShakeAround.php
@@ -23,6 +23,7 @@ use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
* @property \EasyWeChat\OfficialAccount\ShakeAround\MaterialClient $material
* @property \EasyWeChat\OfficialAccount\ShakeAround\RelationClient $relation
* @property \EasyWeChat\OfficialAccount\ShakeAround\StatsClient $stats
+ * @property \EasyWeChat\OfficialAccount\ShakeAround\PageClient $page
*/
class ShakeAround extends Client
{
diff --git a/src/OfficialAccount/Store/Client.php b/src/OfficialAccount/Store/Client.php
index 3643096..b873469 100644
--- a/src/OfficialAccount/Store/Client.php
+++ b/src/OfficialAccount/Store/Client.php
@@ -75,7 +75,7 @@ class Client extends BaseClient
*/
public function getStatus()
{
- return $this->httpPostJson('wxa/get_merchant_audit_info');
+ return $this->httpGet('wxa/get_merchant_audit_info');
}
/**
diff --git a/src/OfficialAccount/SubscribeMessage/Client.php b/src/OfficialAccount/SubscribeMessage/Client.php
new file mode 100644
index 0000000..f303fc4
--- /dev/null
+++ b/src/OfficialAccount/SubscribeMessage/Client.php
@@ -0,0 +1,189 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OfficialAccount\SubscribeMessage;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
+use ReflectionClass;
+
+/**
+ * Class Client.
+ *
+ * @author tegic
+ */
+class Client extends BaseClient
+{
+ protected $message = [
+ 'touser' => '',
+ 'template_id' => '',
+ 'page' => '',
+ 'miniprogram' => '',
+ 'data' => [],
+ ];
+
+ /**
+ * {@inheritdoc}.
+ */
+ protected $required = ['touser', 'template_id', 'data'];
+
+ /**
+ * Combine templates and add them to your personal template library under your account.
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function addTemplate(string $tid, array $kidList, string $sceneDesc = null)
+ {
+ $sceneDesc = $sceneDesc ?? '';
+ $data = \compact('tid', 'kidList', 'sceneDesc');
+
+ return $this->httpPost('wxaapi/newtmpl/addtemplate', $data);
+ }
+
+ /**
+ * Delete personal template under account.
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function deleteTemplate(string $id)
+ {
+ return $this->httpPost('wxaapi/newtmpl/deltemplate', ['priTmplId' => $id]);
+ }
+
+ /**
+ * Get the category of the applet account.
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getCategory()
+ {
+ return $this->httpGet('wxaapi/newtmpl/getcategory');
+ }
+
+ /**
+ * Get keyword list under template title.
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getTemplateKeywords(string $tid)
+ {
+ return $this->httpGet('wxaapi/newtmpl/getpubtemplatekeywords', compact('tid'));
+ }
+
+ /**
+ * Get the title of the public template under the category to which the account belongs.
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getTemplateTitles(array $ids, int $start = 0, int $limit = 30)
+ {
+ $ids = \implode(',', $ids);
+ $query = \compact('ids', 'start', 'limit');
+
+ return $this->httpGet('wxaapi/newtmpl/getpubtemplatetitles', $query);
+ }
+
+ /**
+ * Get list of personal templates under the current account.
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getTemplates()
+ {
+ return $this->httpGet('wxaapi/newtmpl/gettemplate');
+ }
+
+ /**
+ * Send a subscribe message.
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function send(array $data = [])
+ {
+ $params = $this->formatMessage($data);
+
+ $this->restoreMessage();
+
+ return $this->httpPostJson('cgi-bin/message/subscribe/bizsend', $params);
+ }
+
+ /**
+ * @return array
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ */
+ protected function formatMessage(array $data = [])
+ {
+ $params = array_merge($this->message, $data);
+
+ foreach ($params as $key => $value) {
+ if (in_array($key, $this->required, true) && empty($value) && empty($this->message[$key])) {
+ throw new InvalidArgumentException(sprintf('Attribute "%s" can not be empty!', $key));
+ }
+
+ $params[$key] = empty($value) ? $this->message[$key] : $value;
+ }
+
+ foreach ($params['data'] as $key => $value) {
+ if (is_array($value)) {
+ if (\array_key_exists('value', $value)) {
+ $params['data'][$key] = ['value' => $value['value']];
+
+ continue;
+ }
+
+ if (count($value) >= 1) {
+ $value = [
+ 'value' => $value[0],
+// 'color' => $value[1],// color unsupported
+ ];
+ }
+ } else {
+ $value = [
+ 'value' => strval($value),
+ ];
+ }
+
+ $params['data'][$key] = $value;
+ }
+
+ return $params;
+ }
+
+ /**
+ * Restore message.
+ */
+ protected function restoreMessage()
+ {
+ $this->message = (new ReflectionClass(static::class))->getDefaultProperties()['message'];
+ }
+}
diff --git a/src/OfficialAccount/SubscribeMessage/ServiceProvider.php b/src/OfficialAccount/SubscribeMessage/ServiceProvider.php
new file mode 100644
index 0000000..da0eef9
--- /dev/null
+++ b/src/OfficialAccount/SubscribeMessage/ServiceProvider.php
@@ -0,0 +1,27 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OfficialAccount\SubscribeMessage;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['subscribe_message'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OfficialAccount/TemplateMessage/Client.php b/src/OfficialAccount/TemplateMessage/Client.php
index be1fa4d..475be1b 100644
--- a/src/OfficialAccount/TemplateMessage/Client.php
+++ b/src/OfficialAccount/TemplateMessage/Client.php
@@ -22,7 +22,7 @@ use ReflectionClass;
*/
class Client extends BaseClient
{
- const API_SEND = 'cgi-bin/message/template/send';
+ public const API_SEND = 'cgi-bin/message/template/send';
/**
* Attributes.
@@ -200,7 +200,7 @@ class Client extends BaseClient
foreach ($data as $key => $value) {
if (is_array($value)) {
- if (isset($value['value'])) {
+ if (\array_key_exists('value', $value)) {
$formatted[$key] = $value;
continue;
diff --git a/src/OpenPlatform/Application.php b/src/OpenPlatform/Application.php
index 459bb96..386e7a3 100644
--- a/src/OpenPlatform/Application.php
+++ b/src/OpenPlatform/Application.php
@@ -1,29 +1,20 @@
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
-
namespace EasyWeChat\OpenPlatform;
use EasyWeChat\Kernel\ServiceContainer;
+use EasyWeChat\Kernel\Traits\ResponseCastable;
use EasyWeChat\MiniProgram\Encryptor;
use EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken;
use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Application as MiniProgram;
use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Auth\Client;
use EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Account\Client as AccountClient;
use EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Application as OfficialAccount;
-use EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\OAuth\ComponentDelegate;
use EasyWeChat\OpenPlatform\Authorizer\Server\Guard;
+use function EasyWeChat\Kernel\data_get;
+
/**
- * Class Application.
- *
* @property \EasyWeChat\OpenPlatform\Server\Guard $server
* @property \EasyWeChat\OpenPlatform\Auth\AccessToken $access_token
* @property \EasyWeChat\OpenPlatform\CodeTemplate\Client $code_template
@@ -38,6 +29,8 @@ use EasyWeChat\OpenPlatform\Authorizer\Server\Guard;
*/
class Application extends ServiceContainer
{
+ use ResponseCastable;
+
/**
* @var array
*/
@@ -62,26 +55,42 @@ class Application extends ServiceContainer
/**
* Creates the officialAccount application.
*
- * @param string $appId
- * @param string|null $refreshToken
- * @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken
+ * @param string $appId
+ * @param string|null $refreshToken
+ * @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken
*
* @return \EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Application
*/
- public function officialAccount(string $appId, string $refreshToken = null, AccessToken $accessToken = null): OfficialAccount
- {
- $application = new OfficialAccount($this->getAuthorizerConfig($appId, $refreshToken), $this->getReplaceServices($accessToken) + [
- 'encryptor' => $this['encryptor'],
-
- 'account' => function ($app) {
- return new AccountClient($app, $this);
- },
- ]);
-
- $application->extend('oauth', function ($socialite) {
- /* @var \Overtrue\Socialite\Providers\WeChatProvider $socialite */
- return $socialite->component(new ComponentDelegate($this));
- });
+ public function officialAccount(
+ string $appId,
+ string $refreshToken = null,
+ AccessToken $accessToken = null
+ ): OfficialAccount {
+ $application = new OfficialAccount(
+ $this->getAuthorizerConfig($appId, $refreshToken),
+ $this->getReplaceServices($accessToken) + [
+ 'encryptor' => $this['encryptor'],
+
+ 'account' => function ($app) {
+ return new AccountClient($app, $this);
+ },
+ ]
+ );
+
+ $application->extend(
+ 'oauth',
+ function ($socialite) {
+ /* @var \Overtrue\Socialite\Providers\WeChat $socialite */
+ $socialite->withComponent(
+ [
+ 'id' => $this['config']['app_id'],
+ 'token' => fn () => $this['access_token']->getToken()['component_access_token'],
+ ]
+ );
+
+ return $socialite;
+ }
+ );
return $application;
}
@@ -89,32 +98,43 @@ class Application extends ServiceContainer
/**
* Creates the miniProgram application.
*
- * @param string $appId
- * @param string|null $refreshToken
- * @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken
+ * @param string $appId
+ * @param string|null $refreshToken
+ * @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken
*
* @return \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Application
*/
- public function miniProgram(string $appId, string $refreshToken = null, AccessToken $accessToken = null): MiniProgram
- {
- return new MiniProgram($this->getAuthorizerConfig($appId, $refreshToken), $this->getReplaceServices($accessToken) + [
- 'encryptor' => function () {
- return new Encryptor($this['config']['app_id'], $this['config']['token'], $this['config']['aes_key']);
- },
-
- 'auth' => function ($app) {
- return new Client($app, $this);
- },
- ]);
+ public function miniProgram(
+ string $appId,
+ string $refreshToken = null,
+ AccessToken $accessToken = null
+ ): MiniProgram {
+ return new MiniProgram(
+ $this->getAuthorizerConfig($appId, $refreshToken),
+ $this->getReplaceServices($accessToken) + [
+ 'encryptor' => function () {
+ return new Encryptor(
+ $this['config']['app_id'],
+ $this['config']['token'],
+ $this['config']['aes_key']
+ );
+ },
+
+ 'auth' => function ($app) {
+ return new Client($app, $this);
+ },
+ ]
+ );
}
/**
* Return the pre-authorization login page url.
*
- * @param string $callbackUrl
- * @param string|array|null $optional
+ * @param string $callbackUrl
+ * @param string|array|null $optional
*
* @return string
+ * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
*/
public function getPreAuthorizationUrl(string $callbackUrl, $optional = []): string
{
@@ -124,13 +144,16 @@ class Application extends ServiceContainer
'pre_auth_code' => $optional,
];
} else {
- $optional['pre_auth_code'] = $this->createPreAuthorizationCode()['pre_auth_code'];
+ $optional['pre_auth_code'] = data_get($this->createPreAuthorizationCode(), 'pre_auth_code');
}
- $queries = \array_merge($optional, [
- 'component_appid' => $this['config']['app_id'],
- 'redirect_uri' => $callbackUrl,
- ]);
+ $queries = \array_merge(
+ $optional,
+ [
+ 'component_appid' => $this['config']['app_id'],
+ 'redirect_uri' => $callbackUrl,
+ ]
+ );
return 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?'.http_build_query($queries);
}
@@ -138,10 +161,11 @@ class Application extends ServiceContainer
/**
* Return the pre-authorization login page url (mobile).
*
- * @param string $callbackUrl
- * @param string|array|null $optional
+ * @param string $callbackUrl
+ * @param string|array|null $optional
*
* @return string
+ * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
*/
public function getMobilePreAuthorizationUrl(string $callbackUrl, $optional = []): string
{
@@ -151,36 +175,43 @@ class Application extends ServiceContainer
'pre_auth_code' => $optional,
];
} else {
- $optional['pre_auth_code'] = $this->createPreAuthorizationCode()['pre_auth_code'];
+ $optional['pre_auth_code'] = data_get($this->createPreAuthorizationCode(), 'pre_auth_code');
}
- $queries = \array_merge($optional, [
- 'component_appid' => $this['config']['app_id'],
- 'redirect_uri' => $callbackUrl,
- 'action' => 'bindcomponent',
- 'no_scan' => 1,
- ]);
+ $queries = \array_merge(
+ ['auth_type' => 3],
+ $optional,
+ [
+ 'component_appid' => $this['config']['app_id'],
+ 'redirect_uri' => $callbackUrl,
+ 'action' => 'bindcomponent',
+ 'no_scan' => 1,
+ ]
+ );
return 'https://mp.weixin.qq.com/safe/bindcomponent?'.http_build_query($queries).'#wechat_redirect';
}
/**
- * @param string $appId
- * @param string|null $refreshToken
+ * @param string $appId
+ * @param string|null $refreshToken
*
* @return array
*/
protected function getAuthorizerConfig(string $appId, string $refreshToken = null): array
{
- return $this['config']->merge([
- 'component_app_id' => $this['config']['app_id'],
- 'app_id' => $appId,
- 'refresh_token' => $refreshToken,
- ])->toArray();
+ return $this['config']->merge(
+ [
+ 'component_app_id' => $this['config']['app_id'],
+ 'component_app_token' => $this['access_token']->getToken()['component_access_token'],
+ 'app_id' => $appId,
+ 'refresh_token' => $refreshToken,
+ ]
+ )->toArray();
}
/**
- * @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken
+ * @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken
*
* @return array
*/
@@ -208,8 +239,8 @@ class Application extends ServiceContainer
/**
* Handle dynamic calls.
*
- * @param string $method
- * @param array $args
+ * @param string $method
+ * @param array $args
*
* @return mixed
*/
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Account/Client.php b/src/OpenPlatform/Authorizer/MiniProgram/Account/Client.php
index c23772d..f1b7afb 100644
--- a/src/OpenPlatform/Authorizer/MiniProgram/Account/Client.php
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Account/Client.php
@@ -32,10 +32,10 @@ class Client extends BaseClient
* 修改头像.
*
* @param string $mediaId 头像素材mediaId
- * @param float $left 剪裁框左上角x坐标(取值范围:[0, 1])
- * @param float $top 剪裁框左上角y坐标(取值范围:[0, 1])
- * @param float $right 剪裁框右下角x坐标(取值范围:[0, 1])
- * @param float $bottom 剪裁框右下角y坐标(取值范围:[0, 1])
+ * @param string $left 剪裁框左上角x坐标(取值范围:[0, 1])
+ * @param string $top 剪裁框左上角y坐标(取值范围:[0, 1])
+ * @param string $right 剪裁框右下角x坐标(取值范围:[0, 1])
+ * @param string $bottom 剪裁框右下角y坐标(取值范围:[0, 1])
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
@@ -44,14 +44,17 @@ class Client extends BaseClient
*/
public function updateAvatar(
string $mediaId,
- float $left = 0.0,
- float $top = 0.0,
- float $right = 1.0,
- float $bottom = 1.0
+ $left = '0.0',
+ $top = '0.0',
+ $right = '1.0',
+ $bottom = '1.0'
) {
$params = [
'head_img_media_id' => $mediaId,
- 'x1' => $left, 'y1' => $top, 'x2' => $right, 'y2' => $bottom,
+ 'x1' => \strval($left),
+ 'y1' => \strval($top),
+ 'x2' => \strval($right),
+ 'y2' => \strval($bottom),
];
return $this->httpPostJson('cgi-bin/account/modifyheadimage', $params);
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Application.php b/src/OpenPlatform/Authorizer/MiniProgram/Application.php
index b4b8c13..09b52cb 100644
--- a/src/OpenPlatform/Authorizer/MiniProgram/Application.php
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Application.php
@@ -19,11 +19,12 @@ use EasyWeChat\OpenPlatform\Authorizer\Aggregate\AggregateServiceProvider;
*
* @author mingyoung
*
- * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Account\Client $account
- * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client $code
- * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Domain\Client $domain
- * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Setting\Client $setting
- * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester\Client $tester
+ * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Account\Client $account
+ * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client $code
+ * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Domain\Client $domain
+ * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Setting\Client $setting
+ * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester\Client $tester
+ * @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Material\Client $material
*/
class Application extends MiniProgram
{
@@ -44,6 +45,9 @@ class Application extends MiniProgram
Account\ServiceProvider::class,
Setting\ServiceProvider::class,
Tester\ServiceProvider::class,
+ Material\ServiceProvider::class,
+ Privacy\ServiceProvider::class,
+ Security\ServiceProvider::class,
];
foreach ($providers as $provider) {
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Code/Client.php b/src/OpenPlatform/Authorizer/MiniProgram/Code/Client.php
index 700e76a..3d1b823 100644
--- a/src/OpenPlatform/Authorizer/MiniProgram/Code/Client.php
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Code/Client.php
@@ -77,7 +77,7 @@ class Client extends BaseClient
}
/**
- * @param array $itemList
+ * @param array $data
* @param string|null $feedbackInfo
* @param string|null $feedbackStuff
*
@@ -86,10 +86,14 @@ class Client extends BaseClient
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function submitAudit(array $itemList, string $feedbackInfo = null, string $feedbackStuff = null)
+ public function submitAudit(array $data, string $feedbackInfo = null, string $feedbackStuff = null)
{
+ if (isset($data['item_list'])) {
+ return $this->httpPostJson('wxa/submit_audit', $data);
+ }
+
return $this->httpPostJson('wxa/submit_audit', [
- 'item_list' => $itemList,
+ 'item_list' => $data,
'feedback_info' => $feedbackInfo,
'feedback_stuff' => $feedbackStuff,
]);
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Material/Client.php b/src/OpenPlatform/Authorizer/MiniProgram/Material/Client.php
new file mode 100644
index 0000000..a9686c9
--- /dev/null
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Material/Client.php
@@ -0,0 +1,51 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Material;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Http\StreamResponse;
+
+/**
+ * Class Client.
+ *
+ * @author overtrue
+ */
+class Client extends BaseClient
+{
+ /**
+ * Allow media type.
+ *
+ * @var array
+ */
+ protected $allowTypes = ['image', 'voice', 'video', 'thumb', 'news_image'];
+
+ /**
+ * Fetch material.
+ *
+ * @param string $mediaId
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function get(string $mediaId)
+ {
+ $response = $this->requestRaw('cgi-bin/material/get_material', 'POST', ['json' => ['media_id' => $mediaId]]);
+
+ if (false !== stripos($response->getHeaderLine('Content-disposition'), 'attachment')) {
+ return StreamResponse::buildFromPsrResponse($response);
+ }
+
+ return $this->castResponseToType($response, $this->app['config']->get('response_type'));
+ }
+}
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Material/ServiceProvider.php b/src/OpenPlatform/Authorizer/MiniProgram/Material/ServiceProvider.php
new file mode 100644
index 0000000..820a1ac
--- /dev/null
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Material/ServiceProvider.php
@@ -0,0 +1,44 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * ServiceProvider.php.
+ *
+ * This file is part of the wechat.
+ *
+ * (c) overtrue
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Material;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider.
+ *
+ * @author overtrue
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['material'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Privacy/Client.php b/src/OpenPlatform/Authorizer/MiniProgram/Privacy/Client.php
new file mode 100644
index 0000000..3b159d3
--- /dev/null
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Privacy/Client.php
@@ -0,0 +1,66 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Privacy;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
+
+/**
+ * Class Client.
+ *
+ * @author lujunyi
+ */
+class Client extends BaseClient
+{
+ /**
+ * 查询小程序用户隐私保护指引.
+ */
+ public function get()
+ {
+ return $this->httpPostJson('cgi-bin/component/getprivacysetting', []);
+ }
+
+ /**
+ * 配置小程序用户隐私保护指引
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function set(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/component/setprivacysetting', $params);
+ }
+
+ /**
+ * 上传小程序用户隐私保护指引
+ *
+ * @param string $path
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidSignException
+ */
+ public function upload(string $path)
+ {
+ if (!file_exists($path) || !is_readable($path)) {
+ throw new InvalidArgumentException(sprintf("File does not exist, or the file is unreadable: '%s'", $path));
+ }
+
+ return $this->httpUpload('cgi-bin/component/uploadprivacyextfile', ['file' => $path]);
+ }
+}
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Privacy/ServiceProvider.php b/src/OpenPlatform/Authorizer/MiniProgram/Privacy/ServiceProvider.php
new file mode 100644
index 0000000..85ec390
--- /dev/null
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Privacy/ServiceProvider.php
@@ -0,0 +1,25 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Privacy;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+class ServiceProvider implements ServiceProviderInterface
+{
+ public function register(Container $app)
+ {
+ $app['privacy'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Security/Client.php b/src/OpenPlatform/Authorizer/MiniProgram/Security/Client.php
new file mode 100644
index 0000000..f227ad5
--- /dev/null
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Security/Client.php
@@ -0,0 +1,45 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Security;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ *
+ * @author lujunyi
+ */
+class Client extends BaseClient
+{
+ /**
+ * 获取隐私接口列表.
+ */
+ public function get()
+ {
+ return $this->httpGet('wxa/security/get_privacy_interface');
+ }
+
+ /**
+ * 申请隐私接口
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function set(array $params)
+ {
+ return $this->httpPostJson('wxa/security/apply_privacy_interface', $params);
+ }
+}
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Security/ServiceProvider.php b/src/OpenPlatform/Authorizer/MiniProgram/Security/ServiceProvider.php
new file mode 100644
index 0000000..66223e3
--- /dev/null
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Security/ServiceProvider.php
@@ -0,0 +1,25 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Security;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+class ServiceProvider implements ServiceProviderInterface
+{
+ public function register(Container $app)
+ {
+ $app['security'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OpenPlatform/Authorizer/MiniProgram/Tester/Client.php b/src/OpenPlatform/Authorizer/MiniProgram/Tester/Client.php
index 011c933..58c9854 100644
--- a/src/OpenPlatform/Authorizer/MiniProgram/Tester/Client.php
+++ b/src/OpenPlatform/Authorizer/MiniProgram/Tester/Client.php
@@ -41,17 +41,25 @@ class Client extends BaseClient
* 解绑小程序体验者.
*
* @param string $wechatId
+ * @param string $userStr
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function unbind(string $wechatId)
+ public function unbind(string $wechatId = null, string $userStr = null)
{
return $this->httpPostJson('wxa/unbind_tester', [
- 'wechatid' => $wechatId,
- ]);
+ ($userStr ? 'userstr' : 'wechatid') => $userStr ?? $wechatId,
+ ]);
+ }
+
+ public function unbindWithUserStr(string $userStr)
+ {
+ return $this->httpPostJson('wxa/unbind_tester', [
+ 'userstr' => $userStr,
+ ]);
}
/**
diff --git a/src/OpenPlatform/CodeTemplate/Client.php b/src/OpenPlatform/CodeTemplate/Client.php
index 2929cb6..3441041 100644
--- a/src/OpenPlatform/CodeTemplate/Client.php
+++ b/src/OpenPlatform/CodeTemplate/Client.php
@@ -37,16 +37,18 @@ class Client extends BaseClient
* 将草稿箱的草稿选为小程序代码模版.
*
* @param int $draftId
+ * @param int $templateType
*
* @return mixed
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function createFromDraft(int $draftId)
+ public function createFromDraft(int $draftId, int $templateType = 0)
{
$params = [
'draft_id' => $draftId,
+ 'template_type' => $templateType,
];
return $this->httpPostJson('wxa/addtotemplate', $params);
@@ -55,14 +57,20 @@ class Client extends BaseClient
/**
* 获取代码模版库中的所有小程序代码模版.
*
+ * @param int $templateType
+ *
* @return mixed
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function list()
+ public function list(int $templateType = null)
{
- return $this->httpGet('wxa/gettemplatelist');
+ $params = [
+ 'template_type' => $templateType,
+ ];
+
+ return $this->httpGet('wxa/gettemplatelist', $params);
}
/**
diff --git a/src/OpenPlatform/Server/Guard.php b/src/OpenPlatform/Server/Guard.php
index ee306ab..8d29d5e 100644
--- a/src/OpenPlatform/Server/Guard.php
+++ b/src/OpenPlatform/Server/Guard.php
@@ -11,13 +11,13 @@
namespace EasyWeChat\OpenPlatform\Server;
-use function EasyWeChat\Kernel\data_get;
use EasyWeChat\Kernel\ServerGuard;
use EasyWeChat\OpenPlatform\Server\Handlers\Authorized;
use EasyWeChat\OpenPlatform\Server\Handlers\Unauthorized;
use EasyWeChat\OpenPlatform\Server\Handlers\UpdateAuthorized;
use EasyWeChat\OpenPlatform\Server\Handlers\VerifyTicketRefreshed;
use Symfony\Component\HttpFoundation\Response;
+use function EasyWeChat\Kernel\data_get;
/**
* Class Guard.
@@ -26,11 +26,11 @@ use Symfony\Component\HttpFoundation\Response;
*/
class Guard extends ServerGuard
{
- const EVENT_AUTHORIZED = 'authorized';
- const EVENT_UNAUTHORIZED = 'unauthorized';
- const EVENT_UPDATE_AUTHORIZED = 'updateauthorized';
- const EVENT_COMPONENT_VERIFY_TICKET = 'component_verify_ticket';
- const EVENT_THIRD_FAST_REGISTERED = 'notify_third_fasteregister';
+ public const EVENT_AUTHORIZED = 'authorized';
+ public const EVENT_UNAUTHORIZED = 'unauthorized';
+ public const EVENT_UPDATE_AUTHORIZED = 'updateauthorized';
+ public const EVENT_COMPONENT_VERIFY_TICKET = 'component_verify_ticket';
+ public const EVENT_THIRD_FAST_REGISTERED = 'notify_third_fasteregister';
/**
* @return \Symfony\Component\HttpFoundation\Response
diff --git a/src/OpenPlatform/Server/Handlers/VerifyTicketRefreshed.php b/src/OpenPlatform/Server/Handlers/VerifyTicketRefreshed.php
index e5ce58d..f268a85 100644
--- a/src/OpenPlatform/Server/Handlers/VerifyTicketRefreshed.php
+++ b/src/OpenPlatform/Server/Handlers/VerifyTicketRefreshed.php
@@ -12,8 +12,11 @@
namespace EasyWeChat\OpenPlatform\Server\Handlers;
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
+use EasyWeChat\Kernel\Traits\ResponseCastable;
use EasyWeChat\OpenPlatform\Application;
+use function EasyWeChat\Kernel\data_get;
+
/**
* Class VerifyTicketRefreshed.
*
@@ -21,6 +24,8 @@ use EasyWeChat\OpenPlatform\Application;
*/
class VerifyTicketRefreshed implements EventHandlerInterface
{
+ use ResponseCastable;
+
/**
* @var \EasyWeChat\OpenPlatform\Application
*/
@@ -41,8 +46,10 @@ class VerifyTicketRefreshed implements EventHandlerInterface
*/
public function handle($payload = null)
{
- if (!empty($payload['ComponentVerifyTicket'])) {
- $this->app['verify_ticket']->setTicket($payload['ComponentVerifyTicket']);
+ $ticket = data_get($payload, 'ComponentVerifyTicket');
+
+ if (!empty($ticket)) {
+ $this->app['verify_ticket']->setTicket($ticket);
}
}
}
diff --git a/src/OpenWork/Application.php b/src/OpenWork/Application.php
index bde1421..4fc9ac0 100644
--- a/src/OpenWork/Application.php
+++ b/src/OpenWork/Application.php
@@ -25,7 +25,13 @@ use EasyWeChat\OpenWork\Work\Application as Work;
* @property \EasyWeChat\OpenWork\SuiteAuth\AccessToken $suite_access_token
* @property \EasyWeChat\OpenWork\Auth\AccessToken $provider_access_token
* @property \EasyWeChat\OpenWork\SuiteAuth\SuiteTicket $suite_ticket
- * @property \EasyWeChat\OpenWork\MiniProgram\Auth\Client $mini_program
+ * @property \EasyWeChat\OpenWork\MiniProgram\Client $mini_program
+ * @property \EasyWeChat\OpenWork\Media\Client $media
+ * @property \EasyWeChat\OpenWork\Contact\Client $contact
+ * @property \EasyWeChat\OpenWork\License\Client $license_order
+ * @property \EasyWeChat\OpenWork\License\Account $license_account
+ * @property \EasyWeChat\OpenWork\Device\Client $device
+ * @noinspection PhpFullyQualifiedNameUsageInspection
*/
class Application extends ServiceContainer
{
@@ -39,6 +45,10 @@ class Application extends ServiceContainer
Corp\ServiceProvider::class,
Provider\ServiceProvider::class,
MiniProgram\ServiceProvider::class,
+ Media\ServiceProvider::class,
+ Contact\ServiceProvider::class,
+ License\ServiceProvider::class,
+ Device\ServiceProvider::class,
];
/**
diff --git a/src/OpenWork/Contact/Client.php b/src/OpenWork/Contact/Client.php
new file mode 100644
index 0000000..3e314e7
--- /dev/null
+++ b/src/OpenWork/Contact/Client.php
@@ -0,0 +1,92 @@
+
+ */
+class Client extends BaseClient
+{
+ public function __construct(ServiceContainer $app)
+ {
+ parent::__construct($app, $app['provider_access_token']);
+ }
+
+
+ /**
+ * 异步通讯录id转译
+ *
+ * @param string $authCorpId 授权企业corp_id
+ * @param array $mediaIdList 需要转译的文件的media_id列表,只支持后缀名为xls/xlsx,doc/docx,csv,txt的文件。
+ * 不超过20个文件,获取方式使用{@see \EasyWeChat\OpenWork\Media\Client::uploadFile() 上传需要转译的文件}
+ *
+ * @param string|null $outputFileName 转译完打包的文件名,不需带后缀。企业微信后台会打包成zip压缩文件,并自动拼接上.zip后缀。
+ * 若media_id_list中文件个数大于1,则该字段必填。若media_id_list中文件个数等于1,且未填该字段,则转译完不打包成压缩文件。支持id转译
+ *
+ * @param string|null $outputFileFormat 若不指定,则输出格式跟输入格式相同。若要转换输出格式,当前仅支持输出文件为pdf格式。
+ * 若$mediaIdList中文件存在相同前缀名的文件,则输出文件命名规则为:文件前缀名_ 文件格式后缀.pdf,例如:20200901_ xlsx.pdf
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function idTranslate(string $authCorpId, array $mediaIdList, string $outputFileName = null, string $outputFileFormat = null)
+ {
+ /** @noinspection SpellCheckingInspection */
+ return $this->httpPostJson('cgi-bin/service/contact/id_translate', [
+ 'auth_corpid' => $authCorpId,
+ 'media_id_list' => $mediaIdList,
+ 'output_file_name' => $outputFileName,
+ 'output_file_format' => $outputFileFormat
+ ]);
+ }
+
+ /**
+ * 获取异步任务结果
+ *
+ * @param string $jobId 异步任务id,最大长度为64字节
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function getResult(string $jobId)
+ {
+ /** @noinspection SpellCheckingInspection */
+ return $this->httpGet('cgi-bin/service/batch/getresult', [
+ 'jobid' => $jobId
+ ]);
+ }
+
+ /**
+ * 通讯录userid排序
+ *
+ * @param string $authCorpId 查询的企业corp_id
+ * @param array $userIdList 要排序的user_id列表,最多支持1000个
+ * @param int $sortType 排序方式 0:根据姓名拼音升序排列,返回用户userid列表 1:根据姓名拼音降序排列,返回用户userid列表
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function sort(string $authCorpId, array $userIdList, int $sortType = 0)
+ {
+ /** @noinspection SpellCheckingInspection */
+ return $this->httpPostJson('cgi-bin/service/contact/sort', [
+ 'auth_corpid' => $authCorpId,
+ 'sort_type' => $sortType,
+ 'useridlist' => $userIdList
+ ]);
+ }
+}
diff --git a/src/OpenWork/Contact/ServiceProvider.php b/src/OpenWork/Contact/ServiceProvider.php
new file mode 100644
index 0000000..f3acf56
--- /dev/null
+++ b/src/OpenWork/Contact/ServiceProvider.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenWork\Contact;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * ServiceProvider.
+ *
+ * @author moniang
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ !isset($app['contact']) && $app['contact'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OpenWork/Corp/Client.php b/src/OpenWork/Corp/Client.php
index 689f573..e32ffea 100644
--- a/src/OpenWork/Corp/Client.php
+++ b/src/OpenWork/Corp/Client.php
@@ -25,7 +25,7 @@ class Client extends BaseClient
* Client constructor.
* 三方接口有三个access_token,这里用的是suite_access_token.
*
- * @param \EasyWeChat\Kernel\ServiceContainer $app
+ * @param ServiceContainer $app
*/
public function __construct(ServiceContainer $app)
{
@@ -42,12 +42,14 @@ class Client extends BaseClient
* @return string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws \Exception
*/
public function getPreAuthorizationUrl(string $preAuthCode = '', string $redirectUri = '', string $state = '')
{
$redirectUri || $redirectUri = $this->app->config['redirect_uri_install'];
$preAuthCode || $preAuthCode = $this->getPreAuthCode()['pre_auth_code'];
- $state || $state = rand();
+ $state || $state = random_bytes(64);
$params = [
'suite_id' => $this->app['config']['suite_id'],
@@ -56,7 +58,7 @@ class Client extends BaseClient
'state' => $state,
];
- return 'https://open.work.weixin.qq.com/3rdapp/install?'.http_build_query($params);
+ return 'https://open.work.weixin.qq.com/3rdapp/install?' . http_build_query($params);
}
/**
@@ -65,6 +67,7 @@ class Client extends BaseClient
* @return mixed
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getPreAuthCode()
{
@@ -76,7 +79,7 @@ class Client extends BaseClient
* 该接口可对某次授权进行配置.
*
* @param string $preAuthCode
- * @param array $sessionInfo
+ * @param array $sessionInfo
*
* @return mixed
*
@@ -157,16 +160,17 @@ class Client extends BaseClient
/**
* 获取登录url.
*
- * @param string $redirectUri
- * @param string $scope
+ * @param string $redirectUri
+ * @param string $scope
* @param string|null $state
*
* @return string
+ * @throws \Exception
*/
public function getOAuthRedirectUrl(string $redirectUri = '', string $scope = 'snsapi_userinfo', string $state = null)
{
$redirectUri || $redirectUri = $this->app->config['redirect_uri_oauth'];
- $state || $state = rand();
+ $state || $state = random_bytes(64);
$params = [
'appid' => $this->app['config']['suite_id'],
'redirect_uri' => $redirectUri,
@@ -175,7 +179,7 @@ class Client extends BaseClient
'state' => $state,
];
- return 'https://open.weixin.qq.com/connect/oauth2/authorize?'.http_build_query($params).'#wechat_redirect';
+ return 'https://open.weixin.qq.com/connect/oauth2/authorize?' . http_build_query($params) . '#wechat_redirect';
}
/**
@@ -186,6 +190,7 @@ class Client extends BaseClient
* @return mixed
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getUserByCode(string $code)
{
@@ -214,4 +219,29 @@ class Client extends BaseClient
return $this->httpPostJson('cgi-bin/service/getuserdetail3rd', $params);
}
+
+ /**
+ * 第三方根据unionid查询external_userid
+ *
+ * @param string $unionid 微信用户的unionid
+ * @param string $openid 微信用户的openid
+ * @param string $corpid 需要换取的企业corpid,不填则拉取所有企业
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author SinyLi
+ */
+ public function unionidToExternalUserid(string $unionid, string $openid, string $corpid = '')
+ {
+ $params = [
+ 'unionid' => $unionid,
+ 'openid' => $openid,
+ 'corpid' => $corpid
+ ];
+
+ return $this->httpPostJson('cgi-bin/service/externalcontact/unionid_to_external_userid_3rd', $params);
+ }
}
diff --git a/src/OpenWork/Device/Client.php b/src/OpenWork/Device/Client.php
new file mode 100644
index 0000000..e3b9427
--- /dev/null
+++ b/src/OpenWork/Device/Client.php
@@ -0,0 +1,187 @@
+
+ */
+class Client extends BaseClient
+{
+ public function __construct(ServiceContainer $app)
+ {
+ parent::__construct($app, $app['provider_access_token']);
+ }
+
+
+ /**
+ * 添加设备实例
+ *
+ * 该API用于添加一个设备的实例
+ *
+ * @param string $modelId 设备的型号id,在服务商管理端添加设备型号之后,可以查看型号id
+ * @param string $deviceSn 硬件序列号,只能包含数字和大小写字母,长度最大为128字节,不可与之前已导入的相同
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function add(string $modelId, string $deviceSn)
+ {
+ return $this->httpPostJson('cgi-bin/service/add_device', [
+ 'model_id' => $modelId,
+ 'device_sn' => $deviceSn
+ ]);
+ }
+
+ /**
+ * 查询设备绑定信息
+ *
+ * 该API用于查询设备绑定的企业信息
+ *
+ * @param string $deviceSn 硬件序列号,只能包含数字和大小写字母,长度最大为128字节
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function get(string $deviceSn)
+ {
+ return $this->httpPostJson('cgi-bin/service/get_device_auth_info', [
+ 'device_sn' => $deviceSn
+ ]);
+ }
+
+ /**
+ * 重置设备SecretNo
+ *
+ * 该API用于重置所有类型设备的SecretNo,主要针对同一批次生成相同secretNo(seedSecretNo)的设备,
+ * 可将SecretNo的状态转换为未设置状态,使设备可以重新调用get_secret_no获取新的sercretNo,
+ * 如果对存量设备调用此接口,那么设备固件必须支持通过seed_secret_no获取secretNo。
+ *
+ * @param string $deviceSn 硬件序列号,只能包含数字和大小写字母,长度最大为128字节
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function reset(string $deviceSn)
+ {
+ return $this->httpPostJson('cgi-bin/service/reset_secret_no', [
+ 'device_sn' => $deviceSn
+ ]);
+ }
+
+ /**
+ * 获取设备列表
+ *
+ * 硬件服务商可以通过本接口获取已登记的设备信息
+ *
+ * @param int $offset 用于分页拉取数据,表示偏移量
+ * @param int $limit 用于分页拉取数据,表示请求的数据条数
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function list(int $offset, int $limit)
+ {
+ return $this->httpPostJson('cgi-bin/service/list_device', [
+ 'offset' => $offset,
+ 'limit' => $limit
+ ]);
+ }
+
+ /**
+ * 上传设备日志
+ *
+ * 该API用于异步拉取某个设备的日志文件
+ *
+ * @param string $deviceSn 硬件序列号,只能包含数字和大小写字母,长度最大为128字节
+ * @param string $hint 提示参数,企业微信后台会将此参数透传给设备,设备可根据此参数来决定要上传哪部分日志,服务商可根据实际业务需求来使用此参数,最长为128字节
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function uploadLog(string $deviceSn, string $hint)
+ {
+ return $this->httpPostJson('cgi-bin/service/fetch_device_log', [
+ 'device_sn' => $deviceSn,
+ 'hint' => $hint
+ ]);
+ }
+
+ /**
+ * 获取设备自定义参数
+ *
+ * @param string $deviceSn 硬件序列号,只能包含数字和大小写字母,长度最大为128字节
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function getFeature(string $deviceSn)
+ {
+ return $this->httpPostJson('cgi-bin/hardware/get_device_feature', [
+ 'device_sn' => $deviceSn
+ ]);
+ }
+
+ /**
+ * 删除设备实例
+ *
+ * 该API用于删除一个设备的实例
+ *
+ * @param string $deviceSn 硬件序列号,只能包含数字和大小写字母,长度最大为128字节
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function delete(string $deviceSn)
+ {
+ return $this->httpPostJson('cgi-bin/service/del_device', [
+ 'device_sn' => $deviceSn
+ ]);
+ }
+
+ /**
+ * 设置打印机支持状态
+ *
+ * 该API用于设置打印盒子是否支持打印机的信息
+ *
+ * @param string $deviceSn 硬件序列号,只能包含数字和大小写字母,长度最大为128字节
+ * @param bool $supported 是否支持打印机
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function setPrinterSupportState(string $deviceSn, bool $supported)
+ {
+ return $this->httpPostJson('cgi-bin/service/del_device', [
+ 'device_sn' => $deviceSn,
+ 'not_supported_printer' => (int)!$supported
+ ]);
+ }
+}
diff --git a/src/OpenWork/Device/ServiceProvider.php b/src/OpenWork/Device/ServiceProvider.php
new file mode 100644
index 0000000..510dca6
--- /dev/null
+++ b/src/OpenWork/Device/ServiceProvider.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenWork\Device;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * ServiceProvider.
+ *
+ * @author moniang
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ !isset($app['device']) && $app['device'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OpenWork/License/Account.php b/src/OpenWork/License/Account.php
new file mode 100644
index 0000000..772259c
--- /dev/null
+++ b/src/OpenWork/License/Account.php
@@ -0,0 +1,206 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenWork\License;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\ServiceContainer;
+
+/**
+ * License Account Client
+ *
+ * @author moniang
+ */
+class Account extends BaseClient
+{
+ public function __construct(ServiceContainer $app)
+ {
+ parent::__construct($app, $app['provider_access_token']);
+ }
+
+ /**
+ * 激活帐号
+ *
+ * >下单购买帐号并支付完成之后,先调用{@see Client::getAccountList() 获取订单中的帐号列表}接口获取到帐号激活码,
+ * 然后可以调用该接口将激活码绑定到某个企业员工,以对其激活相应的平台服务能力。
+ *
+ * **一个userid允许激活一个基础帐号以及一个互通帐号。**
+ *
+ * @param string $activeCode 帐号激活码
+ * @param string $corpId 待绑定激活的成员所属企业corpId,只支持加密的corpId
+ * @param string $userId 待绑定激活的企业成员userId 。只支持加密的userId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ * @noinspection SpellCheckingInspection
+ */
+ public function active(string $activeCode, string $corpId, string $userId)
+ {
+ return $this->httpPostJson('cgi-bin/license/active_account', [
+ 'active_code' => $activeCode,
+ 'corpid' => $corpId,
+ 'userid' => $userId
+ ]);
+ }
+
+ /**
+ * 批量激活帐号
+ *
+ * >可在一次请求里为一个企业的多个成员激活许可帐号,便于服务商批量化处理。
+ *
+ * **一个userid允许激活一个基础帐号以及一个互通帐号。单次激活的员工数量不超过1000**
+ *
+ * @param string $corpId 待绑定激活的成员所属企业corpid,只支持加密的corpid
+ * @param array $activeList 需要激活的帐号列表,每个数组包含active_code帐号激活码和userid待绑定激活的企业成员加密userid
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ * @noinspection SpellCheckingInspection
+ */
+ public function batchActive(string $corpId, array $activeList)
+ {
+ return $this->httpPostJson('cgi-bin/license/batch_active_account', [
+ 'corpid' => $corpId,
+ 'active_list' => $activeList
+ ]);
+ }
+
+ /**
+ * 获取激活码详情
+ *
+ * >查询某个帐号激活码的状态以及激活绑定情况。
+ *
+ * @param string $corpId
+ * @param string $activeCode
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ * @noinspection SpellCheckingInspection
+ */
+ public function getActiveCodeInfo(string $corpId, string $activeCode)
+ {
+ return $this->httpPostJson('cgi-bin/license/get_active_info_by_code', [
+ 'corpid' => $corpId,
+ 'active_code' => $activeCode
+ ]);
+ }
+
+ /**
+ * 批量获取激活码详情
+ *
+ * >批量查询帐号激活码的状态以及激活绑定情况。
+ *
+ * @param string $corpId 要查询的企业的corpid,只支持加密的corpid
+ * @param string[] $activeCodeList 激活码列表,最多不超过1000个
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ * @noinspection SpellCheckingInspection
+ */
+ public function batchGetActiveCodeInfo(string $corpId, array $activeCodeList)
+ {
+ return $this->httpPostJson('cgi-bin/license/batch_get_active_info_by_code', [
+ 'corpid' => $corpId,
+ 'active_code_list' => $activeCodeList
+ ]);
+ }
+
+ /**
+ * 获取企业的帐号列表
+ *
+ * >查询指定企业下的平台能力服务帐号列表。
+ *
+ * @param string $corpId 企业corpId ,只支持加密的corpId
+ * @param string|null $cursor 返回的最大记录数,整型,最大值1000,默认值500
+ * @param int $limit 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ * @noinspection SpellCheckingInspection
+ */
+ public function list(string $corpId, ?string $cursor = null, int $limit = 500)
+ {
+ return $this->httpPostJson('cgi-bin/license/list_actived_account', [
+ 'corpid' => $corpId,
+ 'limit' => $limit,
+ 'cursor' => $cursor
+ ]);
+ }
+
+ /**
+ * 获取成员的激活详情
+ *
+ * >查询某个企业成员的激活情况。
+ *
+ * @param string $corpId 企业corpId ,只支持加密的corpId
+ * @param string $userId 待查询员工的userid,只支持加密的userid
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ * @noinspection SpellCheckingInspection
+ */
+ public function getActiveAccountInfo(string $corpId, string $userId)
+ {
+ return $this->httpPostJson('cgi-bin/license/get_active_info_by_user', [
+ 'corpid' => $corpId,
+ 'userid' => $userId
+ ]);
+ }
+
+
+ /**
+ * 帐号继承
+ *
+ * >在企业员工离职或者工作范围的有变更时,允许将其许可帐号继承给其他员工。
+ *
+ * **调用限制:**
+ * - 转移成员和接收成员属于同一个企业
+ * - 转移成员的帐号已激活,且在有效期
+ * - 转移许可的成员为离职成员时,不限制下次转接的时间间隔
+ * - 转移许可的成员为在职成员时,转接后30天后才可进行下次转接
+ * - 接收成员许可不能与转移成员的许可重叠(同时拥有基础帐号或者互通帐号)
+ * - 单次转移的帐号数限制在1000以内
+ *
+ * @param string $corpId 待绑定激活的成员所属企业corpId,只支持加密的corpId
+ * @param array $transferList 待转移成员列表,每个数组包含handover_userid转移成员的userid和takeover_userid接收成员的userid
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ * @noinspection SpellCheckingInspection
+ */
+ public function batchTransfer(string $corpId, array $transferList)
+ {
+ return $this->httpPostJson('cgi-bin/license/batch_transfer_license', [
+ 'corpid' => $corpId,
+ 'transfer_list' => $transferList
+ ]);
+ }
+}
diff --git a/src/OpenWork/License/App.php b/src/OpenWork/License/App.php
new file mode 100644
index 0000000..12d8b28
--- /dev/null
+++ b/src/OpenWork/License/App.php
@@ -0,0 +1,51 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenWork\License;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\ServiceContainer;
+
+/**
+ * License App Client
+ *
+ * @author keller31
+ */
+class App extends BaseClient
+{
+ public function __construct(ServiceContainer $app)
+ {
+ parent::__construct($app, $app['provider_access_token']);
+ }
+
+ /**
+ * 获取应用的接口许可状态
+ * 服务商可获取某个授权企业的应用接口许可试用期,免费试用期为企业首次安装应用后的90天。
+ *
+ * @link https://developer.work.weixin.qq.com/document/path/95844
+ *
+ * @param string $corpid 企业id
+ * @param string $suite_id 套件id
+ * @param string $appid 旧的多应用套件中的应用id,新开发者请忽略
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function get(string $corpid, string $suite_id, string $appid = '')
+ {
+ return $this->httpPostJson('cgi-bin/license/get_app_license_info', [
+ 'corpid' => $corpid,
+ 'suite_id' => $suite_id,
+ 'appid' => $appid
+ ]);
+ }
+}
diff --git a/src/OpenWork/License/AutoActive.php b/src/OpenWork/License/AutoActive.php
new file mode 100644
index 0000000..f101e0c
--- /dev/null
+++ b/src/OpenWork/License/AutoActive.php
@@ -0,0 +1,69 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenWork\License;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\ServiceContainer;
+
+/**
+ * License Client
+ *
+ * @author keller31
+ */
+class AutoActive extends BaseClient
+{
+ public function __construct(ServiceContainer $app)
+ {
+ parent::__construct($app, $app['provider_access_token']);
+ }
+
+ /**
+ * 设置企业的许可自动激活状态
+ * 服务商可以调用该接口设置授权企业的许可自动激活状态。设置为自动激活后,对应授权企业的员工使用服务商应用时,接口许可表现为自动激活。
+ *
+ * @link https://developer.work.weixin.qq.com/document/path/95873
+ *
+ * @param string $corpid 企业ID
+ * @param integer $status 许可自动激活状态。0:关闭,1:打开
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function setStatus(string $corpid, int $status)
+ {
+ return $this->httpPostJson('cgi-bin/license/set_auto_active_status', [
+ 'corpid' => $corpid,
+ 'auto_active_status' => $status
+ ]);
+ }
+
+ /**
+ * 查询企业的许可自动激活状态
+ * 服务商可以调用该接口查询授权企业的许可自动激活状态。
+ *
+ * @link https://developer.work.weixin.qq.com/document/path/95874
+ *
+ * @param string $corpid 企业ID
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getStatus(string $corpid)
+ {
+ return $this->httpPostJson('cgi-bin/license/get_auto_active_status', [
+ 'corpid' => $corpid
+ ]);
+ }
+}
diff --git a/src/OpenWork/License/Client.php b/src/OpenWork/License/Client.php
new file mode 100644
index 0000000..97469f9
--- /dev/null
+++ b/src/OpenWork/License/Client.php
@@ -0,0 +1,175 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenWork\License;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\ServiceContainer;
+
+/**
+ * Order Client
+ *
+ * @author moniang
+ */
+class Client extends BaseClient
+{
+ public function __construct(ServiceContainer $app)
+ {
+ parent::__construct($app, $app['provider_access_token']);
+ }
+
+ /**
+ * 下单购买帐号
+ *
+ * 服务商下单为企业购买新的帐号,可以同时购买基础帐号与互通帐号。下单之后,需要到服务商管理端发起支付,支付完成之后,订单才能生效。
+ *
+ * @param string $corpId 企业id,只支持加密的corpid
+ * @param array $data
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection SpellCheckingInspection
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function create(string $corpId, array $data)
+ {
+ return $this->httpPostJson('cgi-bin/license/create_new_order', array_merge([
+ 'corpid' => $corpId
+ ], $data));
+ }
+
+ /**
+ * 创建续期任务
+ *
+ * 在同一个订单里,首次创建任务无须指定jobid,后续指定同一个jobid,表示往同一个订单任务追加续期的成员。
+ *
+ * @param string $corpId 企业id,只支持加密的corpid
+ * @param array $data
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection SpellCheckingInspection
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function renew(string $corpId, array $data)
+ {
+ return $this->httpPostJson('cgi-bin/license/create_renew_order_job', array_merge([
+ 'corpid' => $corpId
+ ], $data));
+ }
+
+ /**
+ * 提交续期订单
+ *
+ * 创建续期任务之后,需要调用该接口,以提交订单任务。注意,提交之后,需要到服务商管理端发起支付,支付完成之后,订单才能生效。
+ *
+ * @param string $jobId 任务id
+ * @param string $buyerUserId 下单人。服务商企业内成员userid。该userid必须登录过企业微信,并且企业微信已绑定微信
+ * @param int $accountDurationMonths 购买的月数,每个月按照31天计算。最多购买36个月。(若企业为服务商测试企业,每次续期只能续期1个月)
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection SpellCheckingInspection
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function submitJob(string $jobId, string $buyerUserId, int $accountDurationMonths)
+ {
+ return $this->httpPostJson('cgi-bin/license/submit_order_job', [
+ 'jobid' => $jobId,
+ 'buyer_userid' => $buyerUserId,
+ 'account_duration' => [
+ 'months' => $accountDurationMonths
+ ]
+ ]);
+ }
+
+ /**
+ * 获取订单列表
+ *
+ * 服务商查询自己某段时间内的平台能力服务订单列表
+ *
+ * @param string $corpId 企业id,只支持加密的corpid。若指定corpid且corpid为服务商测试企业,则返回的订单列表为测试订单列表。否则只返回正式订单列表
+ * @param int|null $startTime 开始时间,下单时间。可不填。但是不能单独指定该字段,startTime跟endTime必须同时指定。
+ * @param int|null $endTime 结束时间,下单时间。起始时间跟结束时间不能超过31天。可不填。但是不能单独指定该字段,startTime跟endTime必须同时指定。
+ * @param string|null $cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
+ * @param int $limit 返回的最大记录数,整型,最大值1000,默认值500
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection SpellCheckingInspection
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function list(string $corpId, ?int $startTime = null, ?int $endTime = null, ?string $cursor = null, int $limit = 500)
+ {
+ return $this->httpPostJson('cgi-bin/license/list_order', [
+ 'corpid' => $corpId,
+ 'start_time' => $startTime,
+ 'end_time' => $endTime,
+ 'cursor' => $cursor,
+ 'limit' => $limit
+ ]);
+ }
+
+ /**
+ * 获取订单详情
+ *
+ * 查询某个订单的详情,包括订单的状态、基础帐号个数、互通帐号个数、帐号购买时长等。
+ * 注意,该接口不返回订单中的帐号激活码列表或者续期的帐号成员列表,请调用{@see Client::getAccountList() 获取订单中的帐号列表}接口以获取帐号列表。
+ *
+ * @param string $orderId 订单id
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection SpellCheckingInspection
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function get(string $orderId)
+ {
+ return $this->httpPostJson('cgi-bin/license/get_order', [
+ 'order_id' => $orderId
+ ]);
+ }
+
+ /**
+ * 获取订单中的帐号列表
+ *
+ * 查询指定订单下的平台能力服务帐号列表。若为购买帐号的订单或者存量企业的版本付费迁移订单,则返回帐号激活码列表;
+ * 若为续期帐号的订单,则返回续期帐号的成员列表。
+ *
+ * 注意,若是购买帐号的订单,则仅订单支付完成时,系统才会生成帐号,故支付完成之前,该接口不会返回帐号激活码。
+ *
+ * @param string $orderId 订单号
+ * @param string|null $cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
+ * @param int $limit 返回的最大记录数,整型,最大值1000,默认值500
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection SpellCheckingInspection
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function getAccountList(string $orderId, ?string $cursor = null, int $limit = 500)
+ {
+ return $this->httpPostJson('cgi-bin/license/list_order_account', [
+ 'order_id' => $orderId,
+ 'limit' => $limit,
+ 'cursor' => $cursor
+ ]);
+ }
+}
diff --git a/src/OpenWork/License/ServiceProvider.php b/src/OpenWork/License/ServiceProvider.php
new file mode 100644
index 0000000..799f79f
--- /dev/null
+++ b/src/OpenWork/License/ServiceProvider.php
@@ -0,0 +1,45 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenWork\License;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * ServiceProvider.
+ *
+ * @author moniang
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ !isset($app['license_order']) && $app['license_order'] = function ($app) {
+ return new Client($app);
+ };
+
+ !isset($app['license_account']) && $app['license_account'] = function ($app) {
+ return new Account($app);
+ };
+
+ !isset($app['license_app']) && $app['license_app'] = function ($app) {
+ return new App($app);
+ };
+
+ !isset($app['license_auto_active']) && $app['license_app'] = function ($app) {
+ return new AutoActive($app);
+ };
+ }
+}
diff --git a/src/OpenWork/Media/Client.php b/src/OpenWork/Media/Client.php
new file mode 100644
index 0000000..549aa5d
--- /dev/null
+++ b/src/OpenWork/Media/Client.php
@@ -0,0 +1,105 @@
+
+ */
+class Client extends BaseClient
+{
+ public function __construct(ServiceContainer $app)
+ {
+ parent::__construct($app, $app['provider_access_token']);
+ }
+
+ /**
+ * 上传图片文件
+ *
+ * @param string $path
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function uploadImage(string $path)
+ {
+ return $this->upload('image', $path);
+ }
+
+ /**
+ * 上传语音文件
+ *
+ * @param string $path
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function uploadVoice(string $path)
+ {
+ return $this->upload('voice', $path);
+ }
+
+ /**
+ * 上传视频文件
+ *
+ * @param string $path
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function uploadVideo(string $path)
+ {
+ return $this->upload('video', $path);
+ }
+
+
+ /**
+ * 上传普通文件
+ *
+ * @param string $path
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function uploadFile(string $path)
+ {
+ return $this->upload('file', $path);
+ }
+
+
+ /**
+ * 上传文件
+ *
+ * @param string $type 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file)
+ * @param string $path
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function upload(string $type, string $path)
+ {
+ $files = [
+ 'media' => $path,
+ ];
+
+ return $this->httpUpload('cgi-bin/service/media/upload', $files, [], compact('type'));
+ }
+}
diff --git a/src/OpenWork/Media/ServiceProvider.php b/src/OpenWork/Media/ServiceProvider.php
new file mode 100644
index 0000000..9e50614
--- /dev/null
+++ b/src/OpenWork/Media/ServiceProvider.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\OpenWork\Media;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * ServiceProvider.
+ *
+ * @author moniang
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ !isset($app['media']) && $app['media'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/OpenWork/Provider/Client.php b/src/OpenWork/Provider/Client.php
index 690d988..fe80883 100644
--- a/src/OpenWork/Provider/Client.php
+++ b/src/OpenWork/Provider/Client.php
@@ -25,7 +25,7 @@ class Client extends BaseClient
* Client constructor.
*
*
- * @param ServiceContainer $app
+ * @param ServiceContainer $app
*/
public function __construct(ServiceContainer $app)
{
@@ -35,16 +35,16 @@ class Client extends BaseClient
/**
* 单点登录 - 获取登录的地址.
*
- * @param string $redirectUri
- * @param string $userType
- * @param string $state
+ * @param string $redirectUri
+ * @param string $userType
+ * @param string $state
*
* @return string
*/
public function getLoginUrl(string $redirectUri = '', string $userType = 'admin', string $state = '')
{
$redirectUri || $redirectUri = $this->app->config['redirect_uri_single'];
- $state || $state = rand();
+ $state || $state = random_bytes(64);
$params = [
'appid' => $this->app['config']['corp_id'],
'redirect_uri' => $redirectUri,
@@ -58,7 +58,7 @@ class Client extends BaseClient
/**
* 单点登录 - 获取登录用户信息.
*
- * @param string $authCode
+ * @param string $authCode
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
@@ -77,7 +77,7 @@ class Client extends BaseClient
/**
* 获取注册定制化URL.
*
- * @param string $registerCode
+ * @param string $registerCode
*
* @return string
*
@@ -102,10 +102,10 @@ class Client extends BaseClient
/**
* 获取注册码.
*
- * @param string $corpName
- * @param string $adminName
- * @param string $adminMobile
- * @param string $state
+ * @param string $corpName
+ * @param string $adminName
+ * @param string $adminMobile
+ * @param string $state
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
@@ -116,7 +116,8 @@ class Client extends BaseClient
string $corpName = '',
string $adminName = '',
string $adminMobile = '',
- string $state = ''
+ string $state = '',
+ string $templateId = ''
) {
$params = [];
$params['template_id'] = $this->app['config']['reg_template_id'];
@@ -124,6 +125,7 @@ class Client extends BaseClient
!empty($adminName) && $params['admin_name'] = $adminName;
!empty($adminMobile) && $params['admin_mobile'] = $adminMobile;
!empty($state) && $params['state'] = $state;
+ !empty($templateId) && $params['template_id'] = $templateId;
return $this->httpPostJson('cgi-bin/service/get_register_code', $params);
}
@@ -133,7 +135,7 @@ class Client extends BaseClient
*
* Desc:该API用于查询企业注册状态,企业注册成功返回注册信息.
*
- * @param string $registerCode
+ * @param string $registerCode
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
@@ -158,11 +160,11 @@ class Client extends BaseClient
* 该接口只能使用注册完成回调事件或者查询注册状态返回的access_token。
* 调用设置通讯录同步完成后或者access_token超过30分钟失效(即解除通讯录锁定状态)则不能继续调用该接口。
*
- * @param string $accessToken
- * @param string $agentId
- * @param array $allowUser
- * @param array $allowParty
- * @param array $allowTag
+ * @param string $accessToken
+ * @param string $agentId
+ * @param array $allowUser
+ * @param array $allowParty
+ * @param array $allowTag
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
@@ -191,7 +193,7 @@ class Client extends BaseClient
*
* Desc:该API用于设置通讯录同步完成,解除通讯录锁定状态,同时使通讯录迁移access_token失效。
*
- * @param string $accessToken
+ * @param string $accessToken
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
@@ -203,4 +205,55 @@ class Client extends BaseClient
return $this->httpGet('cgi-bin/sync/contact_sync_success', $params);
}
+
+ /**
+ * 通讯录单个搜索
+ *
+ * @param string $corpId
+ * @param string $queryWord
+ * @param int|string $agentId
+ * @param int $offset
+ * @param int $limit
+ * @param int $queryType
+ * @param null $fullMatchField
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function searchContact(
+ string $corpId,
+ string $queryWord,
+ $agentId,
+ int $offset = 0,
+ int $limit = 50,
+ int $queryType = 0,
+ $fullMatchField = null
+ ) {
+ $params = [];
+ $params['auth_corpid'] = $corpId;
+ $params['query_word'] = $queryWord;
+ $params['query_type'] = $queryType;
+ $params['agentid'] = $agentId;
+ $params['offset'] = $offset;
+ $params['limit'] = $limit;
+ !empty($fullMatchField) && $params['full_match_field'] = $fullMatchField;
+
+ return $this->httpPostJson('cgi-bin/service/contact/search', $params);
+ }
+
+ /**
+ * 自建应用代开发获取带参授权链接
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95436
+ *
+ * @param array $params 请求参数
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getCustomizedAuthUrl(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/service/get_customized_auth_url', $params);
+ }
}
diff --git a/src/OpenWork/Server/Handlers/EchoStrHandler.php b/src/OpenWork/Server/Handlers/EchoStrHandler.php
index 78af701..7843cc8 100644
--- a/src/OpenWork/Server/Handlers/EchoStrHandler.php
+++ b/src/OpenWork/Server/Handlers/EchoStrHandler.php
@@ -57,6 +57,10 @@ class EchoStrHandler implements EventHandlerInterface
//把SuiteTicket缓存起来
if (!empty($payload['SuiteTicket'])) {
$this->app['suite_ticket']->setTicket($payload['SuiteTicket']);
+
+ return new FinallyResult("success");
}
+
+ return null;
}
}
diff --git a/src/OpenWork/Work/Application.php b/src/OpenWork/Work/Application.php
index 676013d..c2f611a 100644
--- a/src/OpenWork/Work/Application.php
+++ b/src/OpenWork/Work/Application.php
@@ -32,7 +32,7 @@ class Application extends Work
*/
public function __construct(string $authCorpId, string $permanentCode, OpenWork $component, array $prepends = [])
{
- parent::__construct($component->getConfig(), $prepends + [
+ parent::__construct(\array_merge($component->getConfig(), ['corp_id' => $authCorpId]), $prepends + [
'access_token' => function ($app) use ($authCorpId, $permanentCode, $component) {
return new AccessToken($app, $authCorpId, $permanentCode, $component);
},
diff --git a/src/Payment/Contract/Client.php b/src/Payment/Contract/Client.php
index 695c658..22acebc 100644
--- a/src/Payment/Contract/Client.php
+++ b/src/Payment/Contract/Client.php
@@ -89,7 +89,7 @@ class Client extends BaseClient
{
$params['appid'] = $this->app['config']->app_id;
- return $this->safeRequest('papay/pappayapply', $params);
+ return $this->safeRequest('pay/pappayapply', $params);
}
/**
diff --git a/src/Payment/Jssdk/Client.php b/src/Payment/Jssdk/Client.php
index 37dc9d4..0780134 100644
--- a/src/Payment/Jssdk/Client.php
+++ b/src/Payment/Jssdk/Client.php
@@ -13,7 +13,6 @@ namespace EasyWeChat\Payment\Jssdk;
use EasyWeChat\BasicService\Jssdk\Client as JssdkClient;
use EasyWeChat\Kernel\Support;
-use Overtrue\Socialite\AccessTokenInterface;
/**
* Class Client.
@@ -99,17 +98,13 @@ class Client extends JssdkClient
/**
* Generate js config for share user address.
*
- * @param string|\Overtrue\Socialite\AccessTokenInterface $accessToken
+ * @param string $accessToken
* @param bool $json
*
* @return string|array
*/
- public function shareAddressConfig($accessToken, bool $json = true)
+ public function shareAddressConfig(string $accessToken, bool $json = true)
{
- if ($accessToken instanceof AccessTokenInterface) {
- $accessToken = $accessToken->getToken();
- }
-
$params = [
'appId' => $this->app['config']->app_id,
'scope' => 'jsapi_address',
@@ -149,4 +144,32 @@ class Client extends JssdkClient
return $params;
}
+
+ /**
+ * Generate js config for biz red packet of mini program.
+ *
+ * @param string $package
+ * @return array
+ */
+ public function miniprogramRedpackConfig(string $package): array
+ {
+ $param = [
+ 'appId' => $this->app['config']->app_id,
+ 'timeStamp' => '' . time(),
+ 'nonceStr' => uniqid(),
+ 'package' => urlencode($package),
+ ];
+ ksort($param);
+
+ $buff = '';
+ foreach ($param as $k => $v) {
+ $buff .= $k . "=" . $v . "&";
+ }
+
+ $param['paySign'] = md5($buff . 'key=' . $this->app['config']->key);
+ $param['signType'] = 'MD5';
+ unset($param['appId']);
+
+ return $param;
+ }
}
diff --git a/src/Payment/Kernel/BaseClient.php b/src/Payment/Kernel/BaseClient.php
index 74f3939..f564994 100644
--- a/src/Payment/Kernel/BaseClient.php
+++ b/src/Payment/Kernel/BaseClient.php
@@ -78,7 +78,7 @@ class BaseClient
'sub_appid' => $this->app['config']['sub_appid'],
];
- $params = array_filter(array_merge($base, $this->prepends(), $params), 'strlen');
+ $params = array_filter(array_filter(array_merge($base, $this->prepends(), $params)), 'strlen');
$secretKey = $this->app->getKey($endpoint);
diff --git a/src/Payment/Notify/Handler.php b/src/Payment/Notify/Handler.php
index 0629786..96a9956 100644
--- a/src/Payment/Notify/Handler.php
+++ b/src/Payment/Notify/Handler.php
@@ -20,8 +20,8 @@ use Symfony\Component\HttpFoundation\Response;
abstract class Handler
{
- const SUCCESS = 'SUCCESS';
- const FAIL = 'FAIL';
+ public const SUCCESS = 'SUCCESS';
+ public const FAIL = 'FAIL';
/**
* @var \EasyWeChat\Payment\Application
diff --git a/src/Payment/Redpack/Client.php b/src/Payment/Redpack/Client.php
index 63fe774..5b49ef5 100644
--- a/src/Payment/Redpack/Client.php
+++ b/src/Payment/Redpack/Client.php
@@ -58,6 +58,7 @@ class Client extends BaseClient
'total_num' => 1,
'client_ip' => $params['client_ip'] ?? Support\get_server_ip(),
'wxappid' => $this->app['config']->app_id,
+ 'notify_way' => 'MINI_PROGRAM_JSAPI',
];
return $this->safeRequest('mmpaymkttransfers/sendminiprogramhb', array_merge($base, $params));
diff --git a/src/Payment/Transfer/Client.php b/src/Payment/Transfer/Client.php
index b8a7c44..619cc0f 100644
--- a/src/Payment/Transfer/Client.php
+++ b/src/Payment/Transfer/Client.php
@@ -12,9 +12,9 @@
namespace EasyWeChat\Payment\Transfer;
use EasyWeChat\Kernel\Exceptions\RuntimeException;
+use EasyWeChat\Payment\Kernel\BaseClient;
use function EasyWeChat\Kernel\Support\get_server_ip;
use function EasyWeChat\Kernel\Support\rsa_public_encrypt;
-use EasyWeChat\Payment\Kernel\BaseClient;
/**
* Class Client.
diff --git a/src/Work/Agent/ServiceProvider.php b/src/Work/Agent/ServiceProvider.php
index b85a6f5..87f4384 100644
--- a/src/Work/Agent/ServiceProvider.php
+++ b/src/Work/Agent/ServiceProvider.php
@@ -29,5 +29,9 @@ class ServiceProvider implements ServiceProviderInterface
$app['agent'] = function ($app) {
return new Client($app);
};
+
+ $app['agent_workbench'] = function ($app) {
+ return new WorkbenchClient($app);
+ };
}
}
diff --git a/src/Work/Agent/WorkbenchClient.php b/src/Work/Agent/WorkbenchClient.php
new file mode 100644
index 0000000..2a4bf0b
--- /dev/null
+++ b/src/Work/Agent/WorkbenchClient.php
@@ -0,0 +1,74 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Agent;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * This is WeWork Agent WorkbenchClient.
+ *
+ * @author 读心印
+ */
+class WorkbenchClient extends BaseClient
+{
+ /**
+ * 设置应用在工作台展示的模版.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/92535#设置应用在工作台展示的模版
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function setWorkbenchTemplate(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/agent/set_workbench_template', $params);
+ }
+
+ /**
+ * 获取应用在工作台展示的模版.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/92535#获取应用在工作台展示的模版
+ *
+ * @param int $agentId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function getWorkbenchTemplate(int $agentId)
+ {
+ $params = [
+ 'agentid' => $agentId
+ ];
+
+ return $this->httpPostJson('cgi-bin/agent/get_workbench_template', $params);
+ }
+
+ /**
+ * 设置应用在用户工作台展示的数据.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/92535#设置应用在用户工作台展示的数据
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function setWorkbenchData(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/agent/set_workbench_data', $params);
+ }
+}
diff --git a/src/Work/Application.php b/src/Work/Application.php
index ebe9b70..6f0fa77 100644
--- a/src/Work/Application.php
+++ b/src/Work/Application.php
@@ -19,29 +19,42 @@ use EasyWeChat\Work\MiniProgram\Application as MiniProgram;
*
* @author mingyoung
*
- * @property \EasyWeChat\Work\OA\Client $oa
- * @property \EasyWeChat\Work\Auth\AccessToken $access_token
- * @property \EasyWeChat\Work\Agent\Client $agent
- * @property \EasyWeChat\Work\Department\Client $department
- * @property \EasyWeChat\Work\Media\Client $media
- * @property \EasyWeChat\Work\Menu\Client $menu
- * @property \EasyWeChat\Work\Message\Client $message
- * @property \EasyWeChat\Work\Message\Messenger $messenger
- * @property \EasyWeChat\Work\User\Client $user
- * @property \EasyWeChat\Work\User\TagClient $tag
- * @property \EasyWeChat\Work\Server\Guard $server
- * @property \EasyWeChat\Work\Jssdk\Client $jssdk
- * @property \Overtrue\Socialite\Providers\WeWorkProvider $oauth
- * @property \EasyWeChat\Work\Invoice\Client $invoice
- * @property \EasyWeChat\Work\Chat\Client $chat
- * @property \EasyWeChat\Work\ExternalContact\Client $external_contact
- * @property \EasyWeChat\Work\ExternalContact\ContactWayClient $contact_way
- * @property \EasyWeChat\Work\ExternalContact\StatisticsClient $external_contact_statistics
- * @property \EasyWeChat\Work\ExternalContact\MessageClient $external_contact_message
- * @property \EasyWeChat\Work\GroupRobot\Client $group_robot
- * @property \EasyWeChat\Work\GroupRobot\Messenger $group_robot_messenger
- * @property \EasyWeChat\Work\Calendar\Client $calendar
- * @property \EasyWeChat\Work\Schedule\Client $schedule
+ * @property \EasyWeChat\Work\OA\Client $oa
+ * @property \EasyWeChat\Work\Auth\AccessToken $access_token
+ * @property \EasyWeChat\Work\Agent\Client $agent
+ * @property \EasyWeChat\Work\Department\Client $department
+ * @property \EasyWeChat\Work\Media\Client $media
+ * @property \EasyWeChat\Work\Menu\Client $menu
+ * @property \EasyWeChat\Work\Message\Client $message
+ * @property \EasyWeChat\Work\Message\Messenger $messenger
+ * @property \EasyWeChat\Work\User\Client $user
+ * @property \EasyWeChat\Work\User\TagClient $tag
+ * @property \EasyWeChat\Work\Server\Guard $server
+ * @property \EasyWeChat\Work\Jssdk\Client $jssdk
+ * @property \Overtrue\Socialite\Providers\WeWork $oauth
+ * @property \EasyWeChat\Work\Invoice\Client $invoice
+ * @property \EasyWeChat\Work\Chat\Client $chat
+ * @property \EasyWeChat\Work\ExternalContact\Client $external_contact
+ * @property \EasyWeChat\Work\ExternalContact\ContactWayClient $contact_way
+ * @property \EasyWeChat\Work\ExternalContact\GroupChatWayClient $group_chat_way
+ * @property \EasyWeChat\Work\ExternalContact\StatisticsClient $external_contact_statistics
+ * @property \EasyWeChat\Work\ExternalContact\MessageClient $external_contact_message
+ * @property \EasyWeChat\Work\ExternalContact\InterceptClient $intercept
+ * @property \EasyWeChat\Work\ExternalContact\ProductClient $product
+ * @property \EasyWeChat\Work\GroupRobot\Client $group_robot
+ * @property \EasyWeChat\Work\GroupRobot\Messenger $group_robot_messenger
+ * @property \EasyWeChat\Work\Calendar\Client $calendar
+ * @property \EasyWeChat\Work\Schedule\Client $schedule
+ * @property \EasyWeChat\Work\MsgAudit\Client $msg_audit
+ * @property \EasyWeChat\Work\Live\Client $live
+ * @property \EasyWeChat\Work\CorpGroup\Client $corp_group
+ * @property \EasyWeChat\Work\ExternalContact\SchoolClient $school
+ * @property \EasyWeChat\Work\ExternalContact\MessageTemplateClient $external_contact_message_template
+ * @property \EasyWeChat\Work\Kf\AccountClient $kf_account
+ * @property \EasyWeChat\Work\Kf\ServicerClient $kf_servicer
+ * @property \EasyWeChat\Work\Kf\MessageClient $kf_message
+ * @property \EasyWeChat\Work\GroupWelcomeTemplate\Client $group_welcome_templage
+ * @property \EasyWeChat\Work\Wedrive\Wedrive $wedrive
*
* @method mixed getCallbackIp()
*/
@@ -69,6 +82,13 @@ class Application extends ServiceContainer
GroupRobot\ServiceProvider::class,
Calendar\ServiceProvider::class,
Schedule\ServiceProvider::class,
+ MsgAudit\ServiceProvider::class,
+ Live\ServiceProvider::class,
+ CorpGroup\ServiceProvider::class,
+ Mobile\ServiceProvider::class,
+ Kf\ServiceProvider::class,
+ GroupWelcomeTemplate\ServiceProvider::class,
+ Wedrive\ServiceProvider::class,
];
/**
diff --git a/src/Work/CorpGroup/Client.php b/src/Work/CorpGroup/Client.php
new file mode 100644
index 0000000..e1ecd42
--- /dev/null
+++ b/src/Work/CorpGroup/Client.php
@@ -0,0 +1,121 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\CorpGroup;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ *
+ * @author 读心印
+ */
+class Client extends BaseClient
+{
+ /**
+ * 获取应用共享信息.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93403
+ *
+ * @param int $agentId
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getAppShareInfo(int $agentId)
+ {
+ $params = [
+ 'agentid' => $agentId
+ ];
+
+ return $this->httpPostJson('cgi-bin/corpgroup/corp/list_app_share_info', $params);
+ }
+
+ /**
+ * 获取下级企业的access_token.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93359
+ *
+ * @param string $corpId
+ * @param int $agentId
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getToken(string $corpId, int $agentId)
+ {
+ $params = [
+ 'corpid' => $corpId,
+ 'agentid' => $agentId
+ ];
+
+ return $this->httpPostJson('cgi-bin/corpgroup/corp/gettoken', $params);
+ }
+
+ /**
+ * 获取下级企业的小程序session.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93355
+ *
+ * @param string $userId
+ * @param string $sessionKey
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getMiniProgramTransferSession(string $userId, string $sessionKey)
+ {
+ $params = [
+ 'userid' => $userId,
+ 'session_key' => $sessionKey
+ ];
+
+ return $this->httpPostJson('cgi-bin/miniprogram/transfer_session', $params);
+ }
+
+ /**
+ * 将明文corpid转换为第三方应用获取的corpid(仅限第三方服务商,转换已获授权企业的corpid)
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/95327#1.4%20corpid%E8%BD%AC%E6%8D%A2
+ *
+ * @param string $corpId 获取到的企业ID
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getOpenCorpid(string $corpId)
+ {
+ return $this->httpPostJson('cgi-bin/corp/to_open_corpid', ['corpid' => $corpId]);
+ }
+
+ /**
+ * 将自建应用获取的userid转换为第三方应用获取的userid(仅代开发自建应用或第三方应用可调用)
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/95327#2.4%20userid%E7%9A%84%E8%BD%AC%E6%8D%A2
+ *
+ * @param array $useridList 获取到的成员ID
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function batchUseridToOpenUserid(array $useridList)
+ {
+ return $this->httpPostJson('cgi-bin/batch/userid_to_openuserid', ['userid_list' => $useridList]);
+ }
+}
diff --git a/src/Work/CorpGroup/ServiceProvider.php b/src/Work/CorpGroup/ServiceProvider.php
new file mode 100644
index 0000000..0e558c3
--- /dev/null
+++ b/src/Work/CorpGroup/ServiceProvider.php
@@ -0,0 +1,35 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\CorpGroup;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * ServiceProvider.
+ *
+ * @author 读心印
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ protected $app;
+
+ /**
+ * @param Container $app
+ */
+ public function register(Container $app)
+ {
+ $app['corp_group'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/Work/Department/Client.php b/src/Work/Department/Client.php
index c34cc86..db80389 100644
--- a/src/Work/Department/Client.php
+++ b/src/Work/Department/Client.php
@@ -60,7 +60,7 @@ class Client extends BaseClient
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
*/
- public function delete($id)
+ public function delete(int $id)
{
return $this->httpGet('cgi-bin/department/delete', compact('id'));
}
@@ -74,8 +74,36 @@ class Client extends BaseClient
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
*/
- public function list($id = null)
+ public function list(?int $id = null)
{
return $this->httpGet('cgi-bin/department/list', compact('id'));
}
+
+ /**
+ * Get sub department lists.
+ *
+ * @param null|int $id
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function simpleList(?int $id = null)
+ {
+ return $this->httpGet('cgi-bin/department/simplelist', compact('id'));
+ }
+
+ /**
+ * Get department details.
+ *
+ * @param int $id
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function get(int $id)
+ {
+ return $this->httpGet('cgi-bin/department/get', compact('id'));
+ }
}
diff --git a/src/Work/ExternalContact/Client.php b/src/Work/ExternalContact/Client.php
index 477686f..4ccd589 100644
--- a/src/Work/ExternalContact/Client.php
+++ b/src/Work/ExternalContact/Client.php
@@ -27,7 +27,7 @@ class Client extends BaseClient
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
*/
public function getFollowUsers()
{
@@ -43,7 +43,7 @@ class Client extends BaseClient
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
*/
public function list(string $userId)
{
@@ -52,6 +52,28 @@ class Client extends BaseClient
]);
}
+ /**
+ * 批量获取客户详情.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92994
+ *
+ * @param array $userIdList
+ * @param string $cursor
+ * @param integer $limit
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function batchGet(array $userIdList, string $cursor = '', int $limit = 100)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/batch/get_by_user', [
+ 'userid_list' => $userIdList,
+ 'cursor' => $cursor,
+ 'limit' => $limit,
+ ]);
+ }
+
/**
* 获取外部联系人详情.
*
@@ -61,7 +83,7 @@ class Client extends BaseClient
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
*/
public function get(string $externalUserId)
{
@@ -70,25 +92,75 @@ class Client extends BaseClient
]);
}
+ /**
+ * 批量获取外部联系人详情.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90001/90143/93010
+ *
+ * @param array $userIdList
+ * @param string $cursor
+ * @param int $limit
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function batchGetByUser(array $userIdList, string $cursor, int $limit)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/batch/get_by_user', [
+ 'userid_list' => $userIdList,
+ 'cursor' => $cursor,
+ 'limit' => $limit
+ ]);
+ }
+
+
+ /**
+ * 修改客户备注信息.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92115
+ *
+ * @param array $data
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function remark(array $data)
+ {
+ return $this->httpPostJson(
+ 'cgi-bin/externalcontact/remark',
+ $data
+ );
+ }
+
+
/**
* 获取离职成员的客户列表.
*
- * @see https://work.weixin.qq.com/api/doc#90000/90135/91563
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92124
*
- * @param int $pageId
- * @param int $pageSize
+ * @param null|int $pageId
+ * @param null|int $pageSize
+ * @param string $cursor
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function getUnassigned(int $pageId = 0, int $pageSize = 1000)
+ public function getUnassigned(?int $pageId = null, ?int $pageSize = 1000, ?string $cursor = null)
{
- return $this->httpPostJson('cgi-bin/externalcontact/get_unassigned_list', [
+ $params = [
'page_id' => $pageId,
'page_size' => $pageSize,
- ]);
+ 'cursor' => $cursor,
+ ];
+ $writableParams = array_filter($params, function (string $key) use ($params) {
+ return !is_null($params[$key]);
+ }, ARRAY_FILTER_USE_KEY);
+ return $this->httpPostJson('cgi-bin/externalcontact/get_unassigned_list', $writableParams);
}
/**
@@ -99,20 +171,459 @@ class Client extends BaseClient
* @param string $externalUserId
* @param string $handoverUserId
* @param string $takeoverUserId
+ * @param string $transferSuccessMessage
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function transfer(string $externalUserId, string $handoverUserId, string $takeoverUserId)
+ public function transfer(string $externalUserId, string $handoverUserId, string $takeoverUserId, string $transferSuccessMessage)
{
$params = [
'external_userid' => $externalUserId,
'handover_userid' => $handoverUserId,
'takeover_userid' => $takeoverUserId,
+ 'transfer_success_msg' => $transferSuccessMessage
];
return $this->httpPostJson('cgi-bin/externalcontact/transfer', $params);
}
+
+ /**
+ * 分配在职成员的客户.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92125
+ *
+ * @param array $externalUserId
+ * @param string $handoverUserId
+ * @param string $takeoverUserId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function transferCustomer(array $externalUserId, string $handoverUserId, string $takeoverUserId, string $transferSuccessMessage)
+ {
+ $params = [
+ 'external_userid' => $externalUserId,
+ 'handover_userid' => $handoverUserId,
+ 'takeover_userid' => $takeoverUserId,
+ 'transfer_success_msg' => $transferSuccessMessage
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/transfer_customer', $params);
+ }
+
+ /**
+ * 分配离职成员的客户.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/94081
+ *
+ * @param array $externalUserId
+ * @param string $handoverUserId
+ * @param string $takeoverUserId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function resignedTransferCustomer(array $externalUserId, string $handoverUserId, string $takeoverUserId)
+ {
+ $params = [
+ 'external_userid' => $externalUserId,
+ 'handover_userid' => $handoverUserId,
+ 'takeover_userid' => $takeoverUserId,
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/resigned/transfer_customer', $params);
+ }
+
+ /**
+ * 离职成员的群再分配.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92127
+ *
+ * @param array $chatIds
+ * @param string $newOwner
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function transferGroupChat(array $chatIds, string $newOwner)
+ {
+ $params = [
+ 'chat_id_list' => $chatIds,
+ 'new_owner' => $newOwner
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/groupchat/transfer', $params);
+ }
+
+ /**
+ * 查询客户接替状态.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/94082
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @param string $handoverUserId
+ * @param string $takeoverUserId
+ * @param null|string $cursor
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function transferResult(string $handoverUserId, string $takeoverUserId, ?string $cursor = null)
+ {
+ $params = [
+ 'handover_userid' => $handoverUserId,
+ 'takeover_userid' => $takeoverUserId,
+ 'cursor' => $cursor,
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/resigned/transfer_result', $params);
+ }
+
+ /**
+ * 查询客户接替结果.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90001/90143/93009
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @param string $externalUserId
+ * @param string $handoverUserId
+ * @param string $takeoverUserId
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getTransferResult(string $externalUserId, string $handoverUserId, string $takeoverUserId)
+ {
+ $params = [
+ 'external_userid' => $externalUserId,
+ 'handover_userid' => $handoverUserId,
+ 'takeover_userid' => $takeoverUserId,
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/get_transfer_result', $params);
+ }
+
+ /**
+ * 获取客户群列表.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92120
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+
+ public function getGroupChats(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/groupchat/list', $params);
+ }
+
+ /**
+ * 获取客户群详情.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92122
+ *
+ * @param string $chatId
+ * @param int $needName
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+
+ public function getGroupChat(string $chatId, int $needName = 0)
+ {
+ $params = [
+ 'chat_id' => $chatId,
+ 'need_name' => $needName,
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/groupchat/get', $params);
+ }
+
+ /**
+ * 获取企业标签库.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92117#获取企业标签库
+ *
+ * @param array $tagIds
+ * @param array $groupIds
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+
+ public function getCorpTags(array $tagIds = [], array $groupIds = [])
+ {
+ $params = [
+ 'tag_id' => $tagIds,
+ 'group_id' => $groupIds
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/get_corp_tag_list', $params);
+ }
+
+
+ /**
+ * 添加企业客户标签.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92117#添加企业客户标签
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+
+ public function addCorpTag(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/add_corp_tag', $params);
+ }
+
+
+ /**
+ * 编辑企业客户标签.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92117#编辑企业客户标签
+ *
+ * @param string $id
+ * @param string|null $name
+ * @param int|null $order
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+
+ public function updateCorpTag(string $id, ?string $name = null, ?int $order = null)
+ {
+ $params = [
+ "id" => $id
+ ];
+
+ if (!\is_null($name)) {
+ $params['name'] = $name;
+ }
+
+ if (!\is_null($order)) {
+ $params['order'] = $order;
+ }
+
+ return $this->httpPostJson('cgi-bin/externalcontact/edit_corp_tag', $params);
+ }
+
+
+ /**
+ * 删除企业客户标签.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92117#删除企业客户标签
+ *
+ * @param array $tagId
+ * @param array $groupId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+
+ public function deleteCorpTag(array $tagId, array $groupId)
+ {
+ $params = [
+ "tag_id" => $tagId,
+ "group_id" => $groupId,
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/del_corp_tag', $params);
+ }
+
+
+ /**
+ * 编辑客户企业标签.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92118
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+
+ public function markTags(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/mark_tag', $params);
+ }
+
+ /**
+ * 外部联系人unionid转换.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90001/90143/93274
+ *
+ * @param string|null $unionid 微信客户的unionid
+ * @param string|null $openid 微信客户的openid
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function unionidToExternalUserid(?string $unionid = null, ?string $openid = null)
+ {
+ return $this->httpPostJson(
+ 'cgi-bin/externalcontact/unionid_to_external_userid',
+ [
+ 'unionid' => $unionid,
+ 'openid' => $openid,
+ ]
+ );
+ }
+
+ /**
+ * 代开发应用external_userid转换.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90001/90143/95195
+ *
+ * @param string $externalUserid 代开发自建应用获取到的外部联系人ID
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function toServiceExternalUserid(string $externalUserid)
+ {
+ return $this->httpPostJson(
+ 'cgi-bin/externalcontact/to_service_external_userid',
+ [
+ 'external_userid' => $externalUserid,
+ ]
+ );
+ }
+
+
+ /**
+ * 转换external_userid
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/95327
+ *
+ * @param array $externalUserIds
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author 读心印
+ */
+
+ public function getNewExternalUserid(array $externalUserIds)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/get_new_external_userid', ['external_userid_list' => $externalUserIds]);
+ }
+
+ /**
+ * 设置迁移完成
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/95327
+ *
+ * @param string $corpid
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author 读心印
+ */
+
+ public function finishExternalUseridMigration(string $corpid)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/finish_external_userid_migration', ['corpid' => $corpid]);
+ }
+
+ /**
+ * unionid查询external_userid
+ *
+ * @param string $unionid
+ * @param string $openid
+ * @param string $corpid
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @deprecated 使用新方法`\EasyWeChat\OpenWork\Corp\unionidToExternalUserid`
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/95327
+ *
+ * @author 读心印
+ */
+
+ public function unionidToexternalUserid3rd(string $unionid, string $openid, string $corpid = '')
+ {
+ $params = [
+ 'unionid' => $unionid,
+ 'openid' => $openid,
+ 'corpid' => $corpid
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/unionid_to_external_userid_3rd', $params);
+ }
+
+
+ /**
+ * 客户群opengid转换
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/94822
+ * @param string $opengid 小程序在微信获取到的群ID
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function opengidToChatid(string $opengid)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/opengid_to_chatid', compact('opengid'));
+ }
+
+
+ /**
+ * 上传附件资源
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/95098
+ * @param string $path 附件资源路径
+ * @param string $mediaType 媒体文件类型
+ * @param string $attachmentType 附件类型
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function uploadAttachment(string $path, string $mediaType, string $attachmentType)
+ {
+ $query = [
+ 'media_type' => $mediaType,
+ 'attachment_type' => $attachmentType,
+ ];
+
+ return $this->httpUpload('cgi-bin/media/upload_attachment', ['media' => $path], [], $query);
+ }
}
diff --git a/src/Work/ExternalContact/ContactWayClient.php b/src/Work/ExternalContact/ContactWayClient.php
index 7cfc2bb..21ed94f 100644
--- a/src/Work/ExternalContact/ContactWayClient.php
+++ b/src/Work/ExternalContact/ContactWayClient.php
@@ -95,4 +95,55 @@ class ContactWayClient extends BaseClient
'config_id' => $configId,
]);
}
+
+ /**
+ * 获取企业已配置的「联系我」列表,注意,该接口仅可获取2021年7月10日以后创建的「联系我」
+ *
+ * @param string $cursor 分页查询使用的游标,为上次请求返回的 next_cursor
+ * @param int $limit 每次查询的分页大小,默认为100条,最多支持1000条
+ * @param int|null $startTime 「联系我」创建起始时间戳, 不传默认为90天前
+ * @param int|null $endTime 「联系我」创建结束时间戳, 不传默认为当前时间
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function list(string $cursor = '', int $limit = 100, int $startTime = null, int $endTime = null)
+ {
+ $data = [
+ 'cursor' => $cursor,
+ 'limit' => $limit,
+ ];
+ if ($startTime) {
+ $data['start_time'] = $startTime;
+ }
+ if ($endTime) {
+ $data['end_time'] = $endTime;
+ }
+ return $this->httpPostJson('cgi-bin/externalcontact/list_contact_way', $data);
+ }
+
+ /**
+ * 结束临时会话
+ *
+ * 将指定的企业成员和客户之前的临时会话断开,断开前会自动下发已配置的结束语。
+ *
+ * 注意:请保证传入的企业成员和客户之间有仍然有效的临时会话, 通过其他方式的添加外部联系人无法通过此接口关闭会话。
+ * @param string $userId 企业成员的user_id
+ * @param string $externalUserId 客户的外部联系人user_id
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ */
+ public function closeTempChat(string $userId, string $externalUserId)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/close_temp_chat', [
+ 'userid' => $userId,
+ 'external_userid' => $externalUserId
+ ]);
+ }
}
diff --git a/src/Work/ExternalContact/GroupChatWayClient.php b/src/Work/ExternalContact/GroupChatWayClient.php
new file mode 100644
index 0000000..e77bbf6
--- /dev/null
+++ b/src/Work/ExternalContact/GroupChatWayClient.php
@@ -0,0 +1,94 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\ExternalContact;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class GroupChatWayClient.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/92229
+ *
+ * @author SinyLi
+ */
+class GroupChatWayClient extends BaseClient
+{
+ /**
+ * 配置客户群进群方式
+ *
+ * @param array $params 创建参数
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function create(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/groupchat/add_join_way', $params);
+ }
+
+ /**
+ * 获取客户群进群方式配置
+ *
+ * @param string $configId 联系方式的配置id
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function get(string $configId)
+ {
+ $params = [
+ 'config_id' => $configId
+ ];
+ return $this->httpPostJson('cgi-bin/externalcontact/groupchat/get_join_way', $params);
+ }
+
+ /**
+ * 更新客户群进群方式配置,注意:使用覆盖的方式更新
+ *
+ * @param string $configId 企业联系方式的配置id
+ * @param array $config 更新参数
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function update(string $configId, array $config = [])
+ {
+ $params = array_merge([
+ 'config_id' => $configId,
+ ], $config);
+ return $this->httpPostJson('cgi-bin/externalcontact/groupchat/update_join_way', $params);
+ }
+
+ /**
+ * 删除客户群进群方式配置
+ *
+ * @param string $configId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function delete(string $configId)
+ {
+ $params = [
+ 'config_id' => $configId
+ ];
+ return $this->httpPostJson('cgi-bin/externalcontact/groupchat/del_join_way', $params);
+ }
+}
diff --git a/src/Work/ExternalContact/InterceptClient.php b/src/Work/ExternalContact/InterceptClient.php
new file mode 100644
index 0000000..81dfdfe
--- /dev/null
+++ b/src/Work/ExternalContact/InterceptClient.php
@@ -0,0 +1,106 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\ExternalContact;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class InterceptClient.
+ *
+ * @package EasyWeChat\Work\ExternalContact
+ *
+ * @author 读心印
+ */
+class InterceptClient extends BaseClient
+{
+ /**
+ * 新建敏感词规则.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95097#新建敏感词规则
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @author 读心印
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function createInterceptRule(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/add_intercept_rule', $params);
+ }
+
+ /**
+ * 获取敏感词规则列表.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95097#获取敏感词规则列表
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @author 读心印
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getInterceptRules()
+ {
+ return $this->httpGet('cgi-bin/externalcontact/get_intercept_rule_list');
+ }
+
+ /**
+ * 获取敏感词规则详情.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95097#获取敏感词规则详情
+ *
+ * @param string $ruleId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @author 读心印
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getInterceptRuleDetails(string $ruleId)
+ {
+ $params = [
+ 'rule_id' => $ruleId
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/get_intercept_rule', $params);
+ }
+
+ /**
+ * 删除敏感词规则.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95097#删除敏感词规则
+ *
+ * @param string $ruleId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @author 读心印
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function deleteInterceptRule(string $ruleId)
+ {
+ $params = [
+ 'rule_id' => $ruleId
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/del_intercept_rule', $params);
+ }
+}
diff --git a/src/Work/ExternalContact/MessageClient.php b/src/Work/ExternalContact/MessageClient.php
index ce00f80..67fbe2c 100644
--- a/src/Work/ExternalContact/MessageClient.php
+++ b/src/Work/ExternalContact/MessageClient.php
@@ -26,14 +26,14 @@ class MessageClient extends BaseClient
*
* @var array
*/
- protected $required = ['content', 'media_id', 'title', 'url', 'pic_media_id', 'appid', 'page'];
+ protected $required = ['content', 'title', 'url', 'pic_media_id', 'appid', 'page'];
protected $textMessage = [
'content' => '',
];
protected $imageMessage = [
- 'media_id' => '',
+
];
protected $linkMessage = [
@@ -73,29 +73,129 @@ class MessageClient extends BaseClient
/**
* 获取企业群发消息发送结果.
*
- * @see https://work.weixin.qq.com/api/doc#90000/90135/91561
+ * @see https://developer.work.weixin.qq.com/document/16251
*
- * @param string $msgId
+ * @param string $msgId 群发消息的id,通过{@see MessageClient::submit() 添加企业群发消息模板}接口返回
+ * @param int $limit 返回的最大记录数,整型,最大值10000,默认值10000
+ * @param string|null $cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
+ * @noinspection PhpFullyQualifiedNameUsageInspection
+ * @noinspection SpellCheckingInspection
*/
- public function get(string $msgId)
+ public function get(string $msgId, int $limit = 10000, ?string $cursor = null)
{
return $this->httpPostJson('cgi-bin/externalcontact/get_group_msg_result', [
'msgid' => $msgId,
+ 'limit' => $limit,
+ 'cursor' => $cursor
]);
}
+ /**
+ * 获取群发记录列表.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93338#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%8F%91%E8%AE%B0%E5%BD%95%E5%88%97%E8%A1%A8
+ *
+ * @param string $chatType 群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群
+ * @param int $startTime 群发任务记录开始时间
+ * @param int $endTime 群发任务记录结束时间
+ * @param string|null $creator 群发任务创建人企业账号id
+ * @param int|null $filterType 创建人类型。0:企业发表 1:个人发表 2:所有,包括个人创建以及企业创建,默认情况下为所有类型
+ * @param int|null $limit 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取默认值
+ * @param string|null $cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getGroupmsgListV2(string $chatType, int $startTime, int $endTime, ?string $creator = null, ?int $filterType = null, ?int $limit = null, ?string $cursor = null)
+ {
+ $data = [
+ 'chat_type' => $chatType,
+ 'start_time' => $startTime,
+ 'end_time' => $endTime,
+ 'creator' => $creator,
+ 'filter_type' => $filterType,
+ 'limit' => $limit,
+ 'cursor' => $cursor,
+ ];
+ $writableData = array_filter($data, function (string $key) use ($data) {
+ return !is_null($data[$key]);
+ }, ARRAY_FILTER_USE_KEY);
+ return $this->httpPostJson('cgi-bin/externalcontact/get_groupmsg_list_v2', $writableData);
+ }
+
+ /**
+ * 获取群发成员发送任务列表.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93338#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%8F%91%E6%88%90%E5%91%98%E5%8F%91%E9%80%81%E4%BB%BB%E5%8A%A1%E5%88%97%E8%A1%A8
+ *
+ * @param string $msgId 群发消息的id,通过获取群发记录列表接口返回
+ * @param int|null $limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
+ * @param string|null $cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getGroupmsgTask(string $msgId, ?int $limit = null, ?string $cursor = null)
+ {
+ $data = [
+ 'msgid' => $msgId,
+ 'limit' => $limit,
+ 'cursor' => $cursor,
+ ];
+ $writableData = array_filter($data, function (string $key) use ($data) {
+ return !is_null($data[$key]);
+ }, ARRAY_FILTER_USE_KEY);
+ return $this->httpPostJson('cgi-bin/externalcontact/get_groupmsg_task', $writableData);
+ }
+
+ /**
+ * 获取企业群发成员执行结果.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93338#%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E7%BE%A4%E5%8F%91%E6%88%90%E5%91%98%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C
+ *
+ * @param string $msgId 群发消息的id,通过获取群发记录列表接口返回
+ * @param string $userid 发送成员userid,通过获取群发成员发送任务列表接口返回
+ * @param int|null $limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
+ * @param string|null $cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getGroupmsgSendResult(string $msgId, string $userid, ?int $limit = null, ?string $cursor = null)
+ {
+ $data = [
+ 'msgid' => $msgId,
+ 'userid' => $userid,
+ 'limit' => $limit,
+ 'cursor' => $cursor,
+ ];
+ $writableData = array_filter($data, function (string $key) use ($data) {
+ return !is_null($data[$key]);
+ }, ARRAY_FILTER_USE_KEY);
+ return $this->httpPostJson('cgi-bin/externalcontact/get_groupmsg_send_result', $writableData);
+ }
+
/**
* 发送新客户欢迎语.
*
* @see https://work.weixin.qq.com/api/doc#90000/90135/91688
*
* @param string $welcomeCode
- * @param array $msg
+ * @param array $msg
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
diff --git a/src/Work/ExternalContact/MessageTemplateClient.php b/src/Work/ExternalContact/MessageTemplateClient.php
new file mode 100644
index 0000000..92d34ca
--- /dev/null
+++ b/src/Work/ExternalContact/MessageTemplateClient.php
@@ -0,0 +1,166 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\ExternalContact;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
+
+/**
+ * Class MessageTemplateClient.
+ *
+ * @author ljyljy0211
+ */
+class MessageTemplateClient extends BaseClient
+{
+ /**
+ * Required attributes.
+ *
+ * @var array
+ */
+ protected $required = ['title', 'url', 'pic_media_id', 'appid', 'page'];
+
+ protected $textMessage = [
+ 'content' => '',
+ ];
+
+ protected $imageMessage = [
+ 'media_id' => '',
+ 'pic_url' => '',
+ ];
+
+ protected $linkMessage = [
+ 'title' => '',
+ 'picurl' => '',
+ 'desc' => '',
+ 'url' => '',
+ ];
+
+ protected $miniprogramMessage = [
+ 'title' => '',
+ 'pic_media_id' => '',
+ 'appid' => '',
+ 'page' => '',
+ ];
+
+ /**
+ * 添加入群欢迎语素材.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92366
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ */
+ public function create(array $msgTemplate)
+ {
+ $params = $this->formatMessage($msgTemplate);
+
+ return $this->httpPostJson('cgi-bin/externalcontact/group_welcome_template/add', $params);
+ }
+
+ /**
+ * 编辑入群欢迎语素材.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92366
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ */
+ public function update(string $templateId, array $msgTemplate)
+ {
+ $params = $this->formatMessage($msgTemplate);
+ $params = array_merge([
+ 'template_id' => $templateId,
+ ], $params);
+ return $this->httpPostJson('cgi-bin/externalcontact/group_welcome_template/edit', $params);
+ }
+
+ /**
+ * 获取入群欢迎语素材.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92366
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ */
+ public function get(string $templateId)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/group_welcome_template/get', [
+ 'template_id' => $templateId,
+ ]);
+ }
+
+ /**
+ * 删除入群欢迎语素材.
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92366
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ */
+ public function delete(string $templateId)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/group_welcome_template/del', [
+ 'template_id' => $templateId,
+ ]);
+ }
+
+ /**
+ * @throws InvalidArgumentException
+ * @return array
+ */
+ protected function formatMessage(array $data = [])
+ {
+ $params = $data;
+
+ if (!empty($params['text'])) {
+ $params['text'] = $this->formatFields($params['text'], $this->textMessage);
+ }
+
+ if (!empty($params['image'])) {
+ $params['image'] = $this->formatFields($params['image'], $this->imageMessage);
+ }
+
+ if (!empty($params['link'])) {
+ $params['link'] = $this->formatFields($params['link'], $this->linkMessage);
+ }
+
+ if (!empty($params['miniprogram'])) {
+ $params['miniprogram'] = $this->formatFields($params['miniprogram'], $this->miniprogramMessage);
+ }
+
+ return $params;
+ }
+
+ /**
+ * @throws InvalidArgumentException
+ * @return array
+ */
+ protected function formatFields(array $data = [], array $default = [])
+ {
+ $params = array_merge($default, $data);
+ foreach ($params as $key => $value) {
+ if (in_array($key, $this->required, true) && empty($value) && empty($default[$key])) {
+ throw new InvalidArgumentException(sprintf('Attribute "%s" can not be empty!', $key));
+ }
+
+ $params[$key] = empty($value) ? $default[$key] : $value;
+ }
+
+ return $params;
+ }
+}
diff --git a/src/Work/ExternalContact/MomentClient.php b/src/Work/ExternalContact/MomentClient.php
new file mode 100644
index 0000000..cf6db0b
--- /dev/null
+++ b/src/Work/ExternalContact/MomentClient.php
@@ -0,0 +1,166 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\ExternalContact;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class MomentClient.
+ *
+ * @author 读心印
+ */
+class MomentClient extends BaseClient
+{
+ /**
+ * 创建发表任务
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/95094#%E5%88%9B%E5%BB%BA%E5%8F%91%E8%A1%A8%E4%BB%BB%E5%8A%A1
+ * @param array $param
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function createTask(array $param)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/add_moment_task', $param);
+ }
+
+ /**
+ * 获取任务创建结果
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/95094#%E8%8E%B7%E5%8F%96%E4%BB%BB%E5%8A%A1%E5%88%9B%E5%BB%BA%E7%BB%93%E6%9E%9C
+ *
+ * @param string $jobId 异步任务id
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getTask(string $jobId)
+ {
+ return $this->httpGet('cgi-bin/externalcontact/get_moment_task_result', ['jobid' => $jobId]);
+ }
+
+
+ /**
+ * 获取企业全部的发表列表.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93333#获取企业全部的发表列表
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function list(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/get_moment_list', $params);
+ }
+
+ /**
+ * 获取客户朋友圈企业发表的列表.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93333#获取客户朋友圈企业发表的列表
+ *
+ * @param string $momentId
+ * @param string $cursor
+ * @param int $limit
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function getTasks(string $momentId, string $cursor = '', int $limit = 500)
+ {
+ $params = [
+ 'moment_id' => $momentId,
+ 'cursor' => $cursor,
+ 'limit' => $limit
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/get_moment_task', $params);
+ }
+
+ /**
+ * 获取客户朋友圈发表时选择的可见范围.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93333#获取客户朋友圈发表时选择的可见范围
+ *
+ * @param string $momentId
+ * @param string $userId
+ * @param string $cursor
+ * @param int $limit
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function getCustomers(string $momentId, string $userId, string $cursor, int $limit)
+ {
+ $params = [
+ 'moment_id' => $momentId,
+ 'userid' => $userId,
+ 'cursor' => $cursor,
+ 'limit' => $limit
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/get_moment_customer_list', $params);
+ }
+
+ /**
+ * 获取客户朋友圈发表后的可见客户列表.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93333#获取客户朋友圈发表后的可见客户列表
+ *
+ * @param string $momentId
+ * @param string $userId
+ * @param string $cursor
+ * @param int $limit
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function getSendResult(string $momentId, string $userId, string $cursor, int $limit)
+ {
+ $params = [
+ 'moment_id' => $momentId,
+ 'userid' => $userId,
+ 'cursor' => $cursor,
+ 'limit' => $limit
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/get_moment_send_result', $params);
+ }
+
+ /**
+ * 获取客户朋友圈的互动数据.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93333#获取客户朋友圈的互动数据
+ *
+ * @param string $momentId
+ * @param string $userId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function getComments(string $momentId, string $userId)
+ {
+ $params = [
+ 'moment_id' => $momentId,
+ 'userid' => $userId
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/get_moment_comments', $params);
+ }
+}
diff --git a/src/Work/ExternalContact/ProductClient.php b/src/Work/ExternalContact/ProductClient.php
new file mode 100644
index 0000000..a6301f8
--- /dev/null
+++ b/src/Work/ExternalContact/ProductClient.php
@@ -0,0 +1,133 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\ExternalContact;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class ProductClient.
+ *
+ * @package EasyWeChat\Work\ExternalContact
+ *
+ * @author 读心印
+ */
+class ProductClient extends BaseClient
+{
+ /**
+ * 创建商品图册.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95096
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @author 读心印
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function createProductAlbum(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/add_product_album', $params);
+ }
+
+ /**
+ * 获取商品图册.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95096
+ *
+ * @param string $productId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @author 读心印
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getProductAlbumDetails(string $productId)
+ {
+ $params = [
+ 'product_id' => $productId
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/get_product_album', $params);
+ }
+
+ /**
+ * 获取商品图册列表.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95096
+ *
+ * @param int $limit
+ * @param string $cursor
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @author 读心印
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getProductAlbums(int $limit, string $cursor)
+ {
+ $params = [
+ 'limit' => $limit,
+ 'cursor' => $cursor,
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/get_product_album_list', $params);
+ }
+
+ /**
+ * 编辑商品图册.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95096
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @author 读心印
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateProductAlbum(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/update_product_album', $params);
+ }
+
+ /**
+ * 删除商品图册.
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95096
+ *
+ * @param string $productId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @author 读心印
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function deleteProductAlbum(string $productId)
+ {
+ $params = [
+ 'product_id' => $productId
+ ];
+
+ return $this->httpPostJson('cgi-bin/externalcontact/delete_product_album', $params);
+ }
+}
diff --git a/src/Work/ExternalContact/SchoolClient.php b/src/Work/ExternalContact/SchoolClient.php
new file mode 100644
index 0000000..e0e1faf
--- /dev/null
+++ b/src/Work/ExternalContact/SchoolClient.php
@@ -0,0 +1,441 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\ExternalContact;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ *
+ * @author MillsGuo
+ */
+class SchoolClient extends BaseClient
+{
+ /**
+ * 创建部门
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92340
+ * @param string $name
+ * @param int $parentId
+ * @param int $type
+ * @param int $standardGrade
+ * @param int $registerYear
+ * @param int $order
+ * @param array $departmentAdmins [['userid':'139','type':1],['userid':'1399','type':2]]
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function createDepartment(string $name, int $parentId, int $type, int $standardGrade, int $registerYear, int $order, array $departmentAdmins)
+ {
+ $params = [
+ 'name' => $name,
+ 'parentid' => $parentId,
+ 'type' => $type,
+ 'standard_grade' => $standardGrade,
+ 'register_year' => $registerYear,
+ 'order' => $order,
+ 'department_admins' => $departmentAdmins
+ ];
+
+ return $this->httpPostJson('cgi-bin/school/department/create', $params);
+ }
+
+ /**
+ * 更新部门
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92341
+ * @param int $id
+ * @param string $name
+ * @param int $parentId
+ * @param int $type
+ * @param int $standardGrade
+ * @param int $registerYear
+ * @param int $order
+ * @param array $departmentAdmins [['op':0,'userid':'139','type':1],['op':1,'userid':'1399','type':2]] OP=0表示新增或更新,OP=1表示删除管理员
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateDepartment(int $id, string $name, int $parentId, int $type, int $standardGrade, int $registerYear, int $order, array $departmentAdmins)
+ {
+ $params = [
+ 'id' => $id,
+ 'name' => $name,
+ 'parentid' => $parentId,
+ 'type' => $type,
+ 'standard_grade' => $standardGrade,
+ 'register_year' => $registerYear,
+ 'order' => $order,
+ 'department_admins' => $departmentAdmins
+ ];
+ $params = $this->filterNullValue($params);
+
+ return $this->httpPostJson('cgi-bin/school/department/update', $params);
+ }
+
+ /**
+ * 删除部门
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92342
+ * @param int $id
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function deleteDepartment(int $id)
+ {
+ return $this->httpGet('cgi-bin/school/department/delete', [
+ 'id' => $id
+ ]);
+ }
+
+ /**
+ * 获取部门列表
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92343
+ * @param int $id 如果ID为0,则获取全量组织架构
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getDepartments(int $id)
+ {
+ if ($id > 0) {
+ $params = [
+ 'id' => $id
+ ];
+ } else {
+ $params = [];
+ }
+
+ return $this->httpGet('cgi-bin/school/department/list', $params);
+ }
+
+ /**
+ * 创建学生
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92325
+ * @param string $userId
+ * @param string $name
+ * @param array $department
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function createStudent(string $userId, string $name, array $department)
+ {
+ $params = [
+ 'student_userid' => $userId,
+ 'name' => $name,
+ 'department' => $department
+ ];
+
+ return $this->httpPostJson('cgi-bin/school/user/create_student', $params);
+ }
+
+ /**
+ * 删除学生
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92326
+ * @param string $userId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function deleteStudent(string $userId)
+ {
+ return $this->httpGet('cgi-bin/school/user/delete_student', [
+ 'userid' => $userId
+ ]);
+ }
+
+ /**
+ * 更新学生
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92327
+ * @param string $userId
+ * @param string $name
+ * @param string $newUserId
+ * @param array $department
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateStudent(string $userId, string $name, string $newUserId, array $department)
+ {
+ $params = [
+ 'student_userid' => $userId
+ ];
+ if (!empty($name)) {
+ $params['name'] = $name;
+ }
+ if (!empty($newUserId)) {
+ $params['new_student_userid'] = $newUserId;
+ }
+ if (!empty($department)) {
+ $params['department'] = $department;
+ }
+
+ return $this->httpPostJson('cgi-bin/school/user/update_student', $params);
+ }
+
+ /**
+ * 批量创建学生,学生最多100个
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92328
+ * @param array $students 学生格式:[[student_userid:'','name':'','department':[1,2]],['student_userid':'','name':'','department':[1,2]]]
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function batchCreateStudents(array $students)
+ {
+ $params = [
+ 'students' => $students
+ ];
+
+ return $this->httpPostJson('cgi-bin/school/user/batch_create_student', $params);
+ }
+
+ /**
+ * 批量删除学生,每次最多100个学生
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92329
+ * @param array $useridList 学生USERID,格式:['zhangsan','lisi']
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function batchDeleteStudents(array $useridList)
+ {
+ return $this->httpPostJson('cgi-bin/school/user/batch_delete_student', [
+ 'useridlist' => $useridList
+ ]);
+ }
+
+ /**
+ * 批量更新学生,每次最多100个
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92042
+ * @param array $students 格式:[['student_userid':'lisi','new_student_userid':'lisi2','name':'','department':[1,2]],.....]
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function batchUpdateStudents(array $students)
+ {
+ return $this->httpPostJson('cgi-bin/school/user/batch_update_student', [
+ 'students' => $students
+ ]);
+ }
+
+ /**
+ * 创建家长
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92077
+ * @param string $userId
+ * @param string $mobile
+ * @param bool $toInvite
+ * @param array $children
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function createParent(string $userId, string $mobile, bool $toInvite, array $children)
+ {
+ $params = [
+ 'parent_userid' => $userId,
+ 'mobile' => $mobile,
+ 'to_invite' => $toInvite,
+ 'children' => $children
+ ];
+
+ return $this->httpPostJson('cgi-bin/school/user/create_parent', $params);
+ }
+
+ /**
+ * 删除家长
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92079
+ * @param string $userId
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function deleteParent(string $userId)
+ {
+ return $this->httpPostJson('cgi-bin/school/user/delete_parent', [
+ 'userid' => $userId
+ ]);
+ }
+
+ /**
+ * 更新家长
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92081
+ * @param string $userId
+ * @param string $mobile
+ * @param string $newUserId
+ * @param array $children 格式:[['student_userid':'','relation':''],[]]
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function updateParent(string $userId, string $mobile, string $newUserId, array $children)
+ {
+ $params = [
+ 'parent_userid' => $userId
+ ];
+ if (!empty($newUserId)) {
+ $params['new_parent_userid'] = $newUserId;
+ }
+ if (!empty($mobile)) {
+ $params['mobile'] = $mobile;
+ }
+ if (!empty($children)) {
+ $params['children'] = $children;
+ }
+
+ return $this->httpPostJson('cgi-bin/school/user/update_parent', $params);
+ }
+
+ /**
+ * 批量创建家长 每次最多100个
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92078
+ * @param array $parents [['parent_userid':'','mobile':'','to_invite':true,'children':['student_userid':'','relation':'']],.....]
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function batchCreateParents(array $parents)
+ {
+ return $this->httpPostJson('cgi-bin/school/user/batch_create_parent', [
+ 'parents' => $parents
+ ]);
+ }
+
+ /**
+ * 批量删除家长,每次最多100个
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92080
+ * @param array $userIdList 格式:['chang','lisi']
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function batchDeleteParents(array $userIdList)
+ {
+ return $this->httpPostJson('cgi-bin/school/user/batch_delete_parent', [
+ 'useridlist' => $userIdList
+ ]);
+ }
+
+ /**
+ * 批量更新家长,每次最多100个
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92082
+ * @param array $parents 格式:[['parent_userid':'','new_parent_userid':'','mobile':'','children':[['student_userid':'','relation':''],...]],.....]
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function batchUpdateParents(array $parents)
+ {
+ return $this->httpPostJson('cgi-bin/school/user/batch_update_parent', [
+ 'parents' => $parents
+ ]);
+ }
+
+ /**
+ * 读取学生或家长
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92038
+ * @param string $userId 学生或家长的userid
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getUser(string $userId)
+ {
+ return $this->httpGet('cgi-bin/school/user/get', [
+ 'userid' => $userId
+ ]);
+ }
+
+ /**
+ * 获取部门成员详情
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92038
+ * @param int $departmentId
+ * @param bool $fetchChild
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getStudents(int $departmentId, bool $fetchChild)
+ {
+ $params = [
+ 'department_id' => $departmentId
+ ];
+ if ($fetchChild) {
+ $params['fetch_child'] = 1;
+ } else {
+ $params['fetch_child'] = 0;
+ }
+
+ return $this->httpGet('cgi-bin/school/user/list', $params);
+ }
+
+ /**
+ * 获取学校通知二维码
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92197
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getSubscribeQrCode()
+ {
+ return $this->httpGet('cgi-bin/externalcontact/get_subscribe_qr_code');
+ }
+
+ /**
+ * 设置关注学校通知的模式
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92290
+ * @param int $mode 关注模式,1可扫码填写资料加入,2禁止扫码填写资料加入
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function setSubscribeMode(int $mode)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/set_subscribe_mode', [
+ 'subscribe_mode' => $mode
+ ]);
+ }
+
+ /**
+ * 获取关注学校通知的模式
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92290
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getSubscribeMode()
+ {
+ return $this->httpGet('cgi-bin/externalcontact/get_subscribe_mode');
+ }
+
+ /**
+ * 设置【老师可查看班级】的模式
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92652
+ * @param int $mode
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function setTeacherViewMode(int $mode)
+ {
+ return $this->httpPostJson('cgi-bin/school/set_teacher_view_mode', [
+ 'view_mode' => $mode
+ ]);
+ }
+
+ /**
+ * 获取【老师可查看班级】的模式
+ * @see https://open.work.weixin.qq.com/api/doc/90001/90143/92652
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getTeacherViewMode()
+ {
+ return $this->httpGet('cgi-bin/school/get_teacher_view_mode');
+ }
+
+ /**
+ * 过滤数组中值为NULL的键
+ * @param array $data
+ * @return array
+ */
+ protected function filterNullValue(array $data)
+ {
+ $returnData = [];
+ foreach ($data as $key => $value) {
+ if ($value !== null) {
+ $returnData[$key] = trim($value);
+ }
+ }
+
+ return $returnData;
+ }
+}
diff --git a/src/Work/ExternalContact/ServiceProvider.php b/src/Work/ExternalContact/ServiceProvider.php
index b76630a..96a4b98 100644
--- a/src/Work/ExternalContact/ServiceProvider.php
+++ b/src/Work/ExternalContact/ServiceProvider.php
@@ -34,6 +34,10 @@ class ServiceProvider implements ServiceProviderInterface
return new ContactWayClient($app);
};
+ $app['group_chat_way'] = function ($app) {
+ return new GroupChatWayClient($app);
+ };
+
$app['external_contact_statistics'] = function ($app) {
return new StatisticsClient($app);
};
@@ -41,5 +45,25 @@ class ServiceProvider implements ServiceProviderInterface
$app['external_contact_message'] = function ($app) {
return new MessageClient($app);
};
+
+ $app['school'] = function ($app) {
+ return new SchoolClient($app);
+ };
+
+ $app['external_contact_moment'] = function ($app) {
+ return new MomentClient($app);
+ };
+
+ $app['external_contact_message_template'] = function ($app) {
+ return new MessageTemplateClient($app);
+ };
+
+ $app['product'] = function ($app) {
+ return new ProductClient($app);
+ };
+
+ $app['intercept'] = function ($app) {
+ return new InterceptClient($app);
+ };
}
}
diff --git a/src/Work/ExternalContact/StatisticsClient.php b/src/Work/ExternalContact/StatisticsClient.php
index c6922df..7cfa4d0 100644
--- a/src/Work/ExternalContact/StatisticsClient.php
+++ b/src/Work/ExternalContact/StatisticsClient.php
@@ -16,32 +16,81 @@ use EasyWeChat\Kernel\BaseClient;
/**
* Class StatisticsClient.
*
- * @author milkmeowo
+ * @author 读心印
*/
class StatisticsClient extends BaseClient
{
/**
- * 获取员工行为数据.
+ * 获取「联系客户统计」数据.
*
- * @see https://work.weixin.qq.com/api/doc#90000/90135/91580
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92132
*
* @param array $userIds
* @param string $from
* @param string $to
+ * @param array $partyIds
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function userBehavior(array $userIds, string $from, string $to)
+
+ public function userBehavior(array $userIds, string $from, string $to, array $partyIds = [])
{
$params = [
'userid' => $userIds,
+ 'partyid' => $partyIds,
'start_time' => $from,
'end_time' => $to,
];
-
return $this->httpPostJson('cgi-bin/externalcontact/get_user_behavior_data', $params);
}
+
+
+ /**
+ * 获取「群聊数据统计」数据. (按群主聚合的方式)
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92133
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+
+ public function groupChatStatistic(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/groupchat/statistic', $params);
+ }
+
+
+ /**
+ * 获取「群聊数据统计」数据. (按自然日聚合的方式)
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92133
+ *
+ * @param int $dayBeginTime
+ * @param int $dayEndTime
+ * @param array $userIds
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+
+ public function groupChatStatisticGroupByDay(int $dayBeginTime, int $dayEndTime, array $userIds = [])
+ {
+ $params = [
+ 'day_begin_time' => $dayBeginTime,
+ 'day_end_time' => $dayEndTime,
+ 'owner_filter' => [
+ 'userid_list' => $userIds
+ ]
+ ];
+ return $this->httpPostJson('cgi-bin/externalcontact/groupchat/statistic_group_by_day', $params);
+ }
}
diff --git a/src/Work/GroupWelcomeTemplate/Client.php b/src/Work/GroupWelcomeTemplate/Client.php
new file mode 100644
index 0000000..686ceb6
--- /dev/null
+++ b/src/Work/GroupWelcomeTemplate/Client.php
@@ -0,0 +1,84 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\GroupWelcomeTemplate;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * 入群欢迎语素材管理
+ *
+ * @package EasyWeChat\Work\GroupWelcomeTemplate\Client
+ * @author HaoLiang
+ */
+class Client extends BaseClient
+{
+ /**
+ * 添加入群欢迎语素材
+ *
+ * @description 企业可通过此API向企业的入群欢迎语素材库中添加素材。每个企业的入群欢迎语素材库中,最多容纳100个素材。
+ * @param array $data
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function add(array $data)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/group_welcome_template/add', $data);
+ }
+
+
+ /**
+ * 编辑入群欢迎语素材
+ *
+ * @description 企业可通过此API编辑入群欢迎语素材库中的素材,且仅能够编辑调用方自己创建的入群欢迎语素材。
+ * @param string $templateId 欢迎语素材id
+ * @param array $data
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function edit(string $templateId, array $data)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/group_welcome_template/edit', array_merge(
+ ['template_id' => $templateId],
+ $data
+ ));
+ }
+
+ /**
+ * 获取入群欢迎语素材
+ *
+ * @description 企业可通过此API获取入群欢迎语素材。
+ * @param string $templateId 欢迎语素材id
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function get(string $templateId)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/group_welcome_template/get', ['template_id' => $templateId]);
+ }
+
+ /**
+ * 删除入群欢迎语素材
+ *
+ * @description 企业可通过此API删除入群欢迎语素材,且仅能删除调用方自己创建的入群欢迎语素材。
+ * @param string $templateId 欢迎语素材id
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function del(string $templateId)
+ {
+ return $this->httpPostJson('cgi-bin/externalcontact/group_welcome_template/del', ['template_id' => $templateId]);
+ }
+}
diff --git a/src/Work/GroupWelcomeTemplate/ServiceProvider.php b/src/Work/GroupWelcomeTemplate/ServiceProvider.php
new file mode 100644
index 0000000..c609b55
--- /dev/null
+++ b/src/Work/GroupWelcomeTemplate/ServiceProvider.php
@@ -0,0 +1,34 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\GroupWelcomeTemplate;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * 入群欢迎语素材管理
+ *
+ * @package EasyWeChat\Work\GroupWelcomeTemplate\ServiceProvider
+ * @author HaoLiang
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['group_welcome_template'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/Work/Jssdk/Client.php b/src/Work/Jssdk/Client.php
index 40fc368..f146c3c 100644
--- a/src/Work/Jssdk/Client.php
+++ b/src/Work/Jssdk/Client.php
@@ -12,7 +12,10 @@
namespace EasyWeChat\Work\Jssdk;
use EasyWeChat\BasicService\Jssdk\Client as BaseClient;
+use EasyWeChat\Kernel\Contracts\AccessTokenInterface;
use EasyWeChat\Kernel\Exceptions\RuntimeException;
+use EasyWeChat\Kernel\ServiceContainer;
+use EasyWeChat\Kernel\Support;
/**
* Class Client.
@@ -21,7 +24,12 @@ use EasyWeChat\Kernel\Exceptions\RuntimeException;
*/
class Client extends BaseClient
{
- protected $ticketEndpoint = 'https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket';
+ public function __construct(ServiceContainer $app, AccessTokenInterface $accessToken = null)
+ {
+ parent::__construct($app, $accessToken);
+
+ $this->ticketEndpoint = \rtrim($app->config->get('http.base_uri'), '/').'/cgi-bin/get_jsapi_ticket';
+ }
/**
* @return string
@@ -32,18 +40,112 @@ class Client extends BaseClient
}
/**
- * @param bool $refresh
- * @param string $type
+ * Return jsapi agent config as a PHP array.
*
- * @return array|\EasyWeChat\Kernel\Support\Collection|mixed|object|\Psr\Http\Message\ResponseInterface|string
+ * @param array $apis
+ * @param int|string $agentId
+ * @param bool $debug
+ * @param bool $beta
+ * @param array $openTagList
+ * @param string|null $url
+ *
+ * @return array|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws \Psr\SimpleCache\InvalidArgumentException
+ */
+ public function getAgentConfigArray(
+ array $apis,
+ $agentId,
+ bool $debug = false,
+ bool $beta = false,
+ array $openTagList = [],
+ string $url = null
+ ) {
+ return $this->buildAgentConfig($apis, $agentId, $debug, $beta, false, $openTagList, $url);
+ }
+
+ /**
+ * Get agent config json for jsapi.
+ *
+ * @param array $jsApiList
+ * @param int|string $agentId
+ * @param bool $debug
+ * @param bool $beta
+ * @param bool $json
+ * @param array $openTagList
+ * @param string|null $url
+ *
+ * @return array|string
*
- * @throws RuntimeException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
- public function getAgentTicket(bool $refresh = false, string $type = 'agent_config')
+ public function buildAgentConfig(
+ array $jsApiList,
+ $agentId,
+ bool $debug = false,
+ bool $beta = false,
+ bool $json = true,
+ array $openTagList = [],
+ string $url = null
+ ) {
+ $config = array_merge(compact('debug', 'beta', 'jsApiList', 'openTagList'), $this->agentConfigSignature($agentId, $url));
+
+ return $json ? json_encode($config) : $config;
+ }
+
+ /**
+ * @param int|string $agentId
+ * @param string|null $url
+ * @param string|null $nonce
+ * @param null $timestamp
+ *
+ * @return array
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws \Psr\SimpleCache\InvalidArgumentException
+ */
+ protected function agentConfigSignature($agentId, string $url = null, string $nonce = null, $timestamp = null): array
+ {
+ $url = $url ?: $this->getUrl();
+ $nonce = $nonce ?: Support\Str::quickRandom(10);
+ $timestamp = $timestamp ?: time();
+
+ return [
+ 'corpid' => $this->getAppId(),
+ 'agentid' => $agentId,
+ 'nonceStr' => $nonce,
+ 'timestamp' => $timestamp,
+ 'url' => $url,
+ 'signature' => $this->getTicketSignature($this->getAgentTicket($agentId)['ticket'], $nonce, $timestamp, $url),
+ ];
+ }
+
+ /**
+ * Get js ticket.
+ *
+ * @param bool $refresh
+ * @param string $type
+ *
+ * @return array
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws \Psr\SimpleCache\InvalidArgumentException
+ */
+ public function getTicket(bool $refresh = false, string $type = 'config'): array
{
$cacheKey = sprintf('easywechat.work.jssdk.ticket.%s.%s', $type, $this->getAppId());
@@ -51,6 +153,42 @@ class Client extends BaseClient
return $this->getCache()->get($cacheKey);
}
+ /** @var array $result */
+ $result = $this->castResponseToType(
+ $this->requestRaw($this->ticketEndpoint, 'GET'),
+ 'array'
+ );
+
+ $this->getCache()->set($cacheKey, $result, $result['expires_in'] - 500);
+
+ if (!$this->getCache()->has($cacheKey)) {
+ throw new RuntimeException('Failed to cache jssdk ticket.');
+ }
+
+ return $result;
+ }
+
+ /**
+ * @param int $agentId
+ * @param bool $refresh
+ * @param string $type
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|mixed|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws \Psr\SimpleCache\InvalidArgumentException
+ */
+ public function getAgentTicket($agentId, bool $refresh = false, string $type = 'agent_config')
+ {
+ $cacheKey = sprintf('easywechat.work.jssdk.ticket.%s.%s.%s', $agentId, $type, $this->getAppId());
+
+ if (!$refresh && $this->getCache()->has($cacheKey)) {
+ return $this->getCache()->get($cacheKey);
+ }
+
/** @var array $result */
$result = $this->castResponseToType(
$this->requestRaw('cgi-bin/ticket/get', 'GET', ['query' => ['type' => $type]]),
diff --git a/src/Work/Kf/AccountClient.php b/src/Work/Kf/AccountClient.php
new file mode 100644
index 0000000..afee269
--- /dev/null
+++ b/src/Work/Kf/AccountClient.php
@@ -0,0 +1,131 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Kf;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class AccountClient.
+ *
+ * @package EasyWeChat\Work\Kf
+ *
+ * @author 读心印
+ */
+class AccountClient extends BaseClient
+{
+ /**
+ * 添加客服帐号.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94662
+ *
+ * @param string $name
+ * @param string $mediaId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function add(string $name, string $mediaId)
+ {
+ $params = [
+ 'name' => $name,
+ 'media_id' => $mediaId,
+ ];
+
+ return $this->httpPostJson('cgi-bin/kf/account/add', $params);
+ }
+
+ /**
+ * 修改客服帐号.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94664
+ *
+ * @param string $openKfId
+ * @param string $name
+ * @param string $mediaId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function update(string $openKfId, string $name, string $mediaId)
+ {
+ $params = [
+ 'open_kfid' => $openKfId,
+ 'name' => $name,
+ 'media_id' => $mediaId,
+ ];
+
+ return $this->httpPostJson('cgi-bin/kf/account/update', $params);
+ }
+
+ /**
+ * 删除客服帐号.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94663
+ *
+ * @param string $openKfId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function del(string $openKfId)
+ {
+ $params = [
+ 'open_kfid' => $openKfId
+ ];
+
+ return $this->httpPostJson('cgi-bin/kf/account/del', $params);
+ }
+
+ /**
+ * 获取客服帐号列表.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94661
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function list()
+ {
+ return $this->httpGet('cgi-bin/kf/account/list');
+ }
+
+ /**
+ * 获取客服帐号链接.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94665
+ *
+ * @param string $openKfId
+ * @param string $scene
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getAccountLink(string $openKfId, string $scene)
+ {
+ $params = [
+ 'open_kfid' => $openKfId,
+ 'scene' => $scene
+ ];
+
+ return $this->httpPostJson('cgi-bin/kf/add_contact_way', $params);
+ }
+}
diff --git a/src/Work/Kf/MessageClient.php b/src/Work/Kf/MessageClient.php
new file mode 100644
index 0000000..4246879
--- /dev/null
+++ b/src/Work/Kf/MessageClient.php
@@ -0,0 +1,133 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Kf;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class MessageClient.
+ *
+ * @package EasyWeChat\Work\Kf
+ *
+ * @author 读心印
+ */
+class MessageClient extends BaseClient
+{
+ /**
+ * 获取会话状态.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94669
+ *
+ * @param string $openKfId
+ * @param string $externalUserId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function state(string $openKfId, string $externalUserId)
+ {
+ $params = [
+ 'open_kfid' => $openKfId,
+ 'external_userid' => $externalUserId
+ ];
+
+ return $this->httpPostJson('cgi-bin/kf/service_state/get', $params);
+ }
+
+ /**
+ * 变更会话状态.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94669
+ *
+ * @param string $openKfId
+ * @param string $externalUserId
+ * @param int $serviceState
+ * @param string $serviceUserId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function updateState(string $openKfId, string $externalUserId, int $serviceState, string $serviceUserId)
+ {
+ $params = [
+ 'open_kfid' => $openKfId,
+ 'external_userid' => $externalUserId,
+ 'service_state' => $serviceState,
+ 'servicer_userid' => $serviceUserId
+ ];
+
+ return $this->httpPostJson('cgi-bin/kf/service_state/trans', $params);
+ }
+
+ /**
+ * 读取消息.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94670
+ *
+ * @param string $cursor
+ * @param string $token
+ * @param int $limit
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function sync(string $cursor, string $token, int $limit)
+ {
+ $params = [
+ 'cursor' => $cursor,
+ 'token' => $token,
+ 'limit' => $limit
+ ];
+
+ return $this->httpPostJson('cgi-bin/kf/sync_msg', $params);
+ }
+
+ /**
+ * 发送消息.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94677
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function send(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/kf/send_msg', $params);
+ }
+
+ /**
+ * 发送事件响应消息.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94677
+ *
+ * @param array $params
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function event(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/kf/send_msg_on_event', $params);
+ }
+}
diff --git a/src/Work/Kf/ServiceProvider.php b/src/Work/Kf/ServiceProvider.php
new file mode 100644
index 0000000..5bd3b9f
--- /dev/null
+++ b/src/Work/Kf/ServiceProvider.php
@@ -0,0 +1,43 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Kf;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider.
+ *
+ * @package EasyWeChat\Work\Kf
+ *
+ * @author 读心印
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['kf_account'] = function ($app) {
+ return new AccountClient($app);
+ };
+
+ $app['kf_servicer'] = function ($app) {
+ return new ServicerClient($app);
+ };
+
+ $app['kf_message'] = function ($app) {
+ return new MessageClient($app);
+ };
+ }
+}
diff --git a/src/Work/Kf/ServicerClient.php b/src/Work/Kf/ServicerClient.php
new file mode 100644
index 0000000..90cba0b
--- /dev/null
+++ b/src/Work/Kf/ServicerClient.php
@@ -0,0 +1,91 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Kf;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class ServicerClient.
+ *
+ * @package EasyWeChat\Work\Kf
+ *
+ * @author 读心印
+ */
+class ServicerClient extends BaseClient
+{
+ /**
+ * 添加接待人员.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94646
+ *
+ * @param string $openKfId
+ * @param array $userIds
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function add(string $openKfId, array $userIds)
+ {
+ $params = [
+ 'open_kfid' => $openKfId,
+ 'userid_list' => $userIds
+ ];
+
+ return $this->httpPostJson('cgi-bin/kf/servicer/add', $params);
+ }
+
+ /**
+ * 删除接待人员.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94647
+ *
+ * @param string $openKfId
+ * @param array $userIds
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function del(string $openKfId, array $userIds)
+ {
+ $params = [
+ 'open_kfid' => $openKfId,
+ 'userid_list' => $userIds
+ ];
+
+ return $this->httpPostJson('cgi-bin/kf/servicer/del', $params);
+ }
+
+ /**
+ * 获取接待人员列表.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/94645
+ *
+ * @param string $openKfId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function list(string $openKfId)
+ {
+ $params = [
+ 'open_kfid' => $openKfId
+ ];
+
+ return $this->httpGet('cgi-bin/kf/servicer/list', $params);
+ }
+}
diff --git a/src/Work/Live/Client.php b/src/Work/Live/Client.php
new file mode 100644
index 0000000..4861731
--- /dev/null
+++ b/src/Work/Live/Client.php
@@ -0,0 +1,84 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Live;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ *
+ * @author arthasking
+ */
+class Client extends BaseClient
+{
+ /**
+ * 获取成员直播ID列表
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92735
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getUserLivingId(string $userId, int $beginTime, int $endTime, string $nextKey = '0', int $limit = 100)
+ {
+ $params = [
+ 'userid' => $userId,
+ 'begin_time' => $beginTime,
+ 'end_time' => $endTime,
+ 'next_key' => $nextKey,
+ 'limit' => $limit
+ ];
+
+ return $this->httpPostJson('cgi-bin/living/get_user_livingid', $params);
+ }
+
+ /**
+ * 获取直播详情
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92734
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getLiving(string $livingId)
+ {
+ $params = [
+ 'livingid' => $livingId,
+ ];
+
+ return $this->httpGet('cgi-bin/living/get_living_info', $params);
+ }
+
+ /**
+ * 获取看直播统计
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/92736
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getWatchStat(string $livingId, string $nextKey = '0')
+ {
+ $params = [
+ 'livingid' => $livingId,
+ 'next_key' => $nextKey,
+ ];
+
+ return $this->httpPostJson('cgi-bin/living/get_watch_stat', $params);
+ }
+}
diff --git a/src/Work/Live/ServiceProvider.php b/src/Work/Live/ServiceProvider.php
new file mode 100644
index 0000000..bb12eb3
--- /dev/null
+++ b/src/Work/Live/ServiceProvider.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Live;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider.
+ *
+ * @author arthasking
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['live'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/Work/Media/Client.php b/src/Work/Media/Client.php
index 16e8a94..ba81e7f 100644
--- a/src/Work/Media/Client.php
+++ b/src/Work/Media/Client.php
@@ -33,65 +33,59 @@ class Client extends BaseClient
*/
public function get(string $mediaId)
{
- $response = $this->requestRaw('cgi-bin/media/get', 'GET', [
- 'query' => [
- 'media_id' => $mediaId,
- ],
- ]);
-
- if (false !== stripos($response->getHeaderLine('Content-Type'), 'text/plain')) {
- return $this->castResponseToType($response, $this->app['config']->get('response_type'));
- }
-
- return StreamResponse::buildFromPsrResponse($response);
+ return $this->getResources($mediaId, 'cgi-bin/media/get');
}
/**
* Upload Image.
*
* @param string $path
+ * @param array $form
*
* @return mixed
*/
- public function uploadImage(string $path)
+ public function uploadImage(string $path, array $form = [])
{
- return $this->upload('image', $path);
+ return $this->upload('image', $path, $form);
}
/**
* Upload Voice.
*
* @param string $path
+ * @param array $form
*
* @return mixed
*/
- public function uploadVoice(string $path)
+ public function uploadVoice(string $path, array $form = [])
{
- return $this->upload('voice', $path);
+ return $this->upload('voice', $path, $form);
}
/**
* Upload Video.
*
* @param string $path
+ * @param array $form
*
* @return mixed
*/
- public function uploadVideo(string $path)
+ public function uploadVideo(string $path, array $form = [])
{
- return $this->upload('video', $path);
+ return $this->upload('video', $path, $form);
}
/**
* Upload File.
*
* @param string $path
+ * @param array $form
*
* @return mixed
*/
- public function uploadFile(string $path)
+ public function uploadFile(string $path, array $form = [])
{
- return $this->upload('file', $path);
+ return $this->upload('file', $path, $form);
}
/**
@@ -99,18 +93,81 @@ class Client extends BaseClient
*
* @param string $type
* @param string $path
+ * @param array $form
*
* @return mixed
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
- public function upload(string $type, string $path)
+ public function upload(string $type, string $path, array $form = [])
+ {
+ $files = [
+ 'media' => $path,
+ ];
+
+ return $this->httpUpload('cgi-bin/media/upload', $files, $form, compact('type'));
+ }
+
+ /**
+ * Upload permanently valid images
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/90256
+ * @param string $path
+ * @param array $form
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function uploadImg(string $path, array $form = [])
{
$files = [
'media' => $path,
];
- return $this->httpUpload('cgi-bin/media/upload', $files, [], compact('type'));
+ return $this->httpUpload('cgi-bin/media/uploadimg', $files, $form);
+ }
+
+
+ /**
+ * Get HD voice material
+ *
+ * @see https://work.weixin.qq.com/api/doc/90000/90135/90255
+ * @param string $mediaId
+ *
+ * @return array|\EasyWeChat\Kernel\Http\Response|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getHdVoice(string $mediaId)
+ {
+ return $this->getResources($mediaId, 'cgi-bin/media/get/jssdk');
+ }
+
+ /**
+ * @param string $mediaId
+ * @param string $uri
+ *
+ * @return array|\EasyWeChat\Kernel\Http\Response|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ protected function getResources(string $mediaId, string $uri)
+ {
+ $response = $this->requestRaw($uri, 'GET', [
+ 'query' => [
+ 'media_id' => $mediaId,
+ ],
+ ]);
+
+ if (false !== stripos($response->getHeaderLine('Content-Type'), 'text/plain')) {
+ return $this->castResponseToType($response, $this->app['config']->get('response_type'));
+ }
+
+ return StreamResponse::buildFromPsrResponse($response);
}
}
diff --git a/src/Work/Message/Client.php b/src/Work/Message/Client.php
index 1497586..7cf7493 100644
--- a/src/Work/Message/Client.php
+++ b/src/Work/Message/Client.php
@@ -12,7 +12,6 @@
namespace EasyWeChat\Work\Message;
use EasyWeChat\Kernel\BaseClient;
-use EasyWeChat\Kernel\Messages\Message;
/**
* Class Client.
@@ -45,4 +44,32 @@ class Client extends BaseClient
{
return $this->httpPostJson('cgi-bin/message/send', $message);
}
+
+ /**
+ * 更新任务卡片消息状态
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/91579
+ *
+ * @param array $userids
+ * @param int $agentId
+ * @param string $taskId
+ * @param string $replaceName
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ */
+ public function updateTaskcard(array $userids, int $agentId, string $taskId, string $replaceName = '已收到')
+ {
+ $params = [
+ 'userids' => $userids,
+ 'agentid' => $agentId,
+ 'task_id' => $taskId,
+ 'replace_name' => $replaceName
+ ];
+
+ return $this->httpPostJson('cgi-bin/message/update_taskcard', $params);
+ }
}
diff --git a/src/Work/Message/Messenger.php b/src/Work/Message/Messenger.php
index 62bc62d..b5e21b4 100644
--- a/src/Work/Message/Messenger.php
+++ b/src/Work/Message/Messenger.php
@@ -15,6 +15,7 @@ use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\Exceptions\RuntimeException;
use EasyWeChat\Kernel\Messages\Message;
use EasyWeChat\Kernel\Messages\Text;
+use EasyWeChat\Kernel\Support\Arr;
/**
* Class MessageBuilder.
@@ -136,6 +137,16 @@ class Messenger
return $this;
}
+ /**
+ * verify recipient is '@all' or not
+ *
+ * @return bool
+ */
+ protected function isBroadcast(): bool
+ {
+ return Arr::get($this->to, 'touser') === '@all';
+ }
+
/**
* @param array|string $ids
* @param string $key
@@ -148,7 +159,7 @@ class Messenger
$ids = implode('|', $ids);
}
- $this->to = [$key => $ids];
+ $this->to = $this->isBroadcast() ? [$key => $ids] : array_merge($this->to, [$key => $ids]);
return $this;
}
diff --git a/src/Work/Message/ServiceProvider.php b/src/Work/Message/ServiceProvider.php
index 18193bd..ea14f9e 100644
--- a/src/Work/Message/ServiceProvider.php
+++ b/src/Work/Message/ServiceProvider.php
@@ -33,7 +33,7 @@ class ServiceProvider implements ServiceProviderInterface
$app['messenger'] = function ($app) {
$messenger = new Messenger($app['message']);
- if (is_int($app['config']['agent_id'])) {
+ if (is_numeric($app['config']['agent_id'])) {
$messenger->ofAgent($app['config']['agent_id']);
}
diff --git a/src/Work/Mobile/Auth/Client.php b/src/Work/Mobile/Auth/Client.php
new file mode 100644
index 0000000..357339b
--- /dev/null
+++ b/src/Work/Mobile/Auth/Client.php
@@ -0,0 +1,40 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Mobile\Auth;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ */
+class Client extends BaseClient
+{
+ /**
+ * 通过code获取用户信息.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90136/91193
+ *
+ * @param string $code
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function getUser(string $code)
+ {
+ $params = [
+ 'code' => $code,
+ ];
+
+ return $this->httpGet('cgi-bin/user/getuserinfo', $params);
+ }
+}
diff --git a/src/Work/Mobile/ServiceProvider.php b/src/Work/Mobile/ServiceProvider.php
new file mode 100644
index 0000000..eb26844
--- /dev/null
+++ b/src/Work/Mobile/ServiceProvider.php
@@ -0,0 +1,36 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Mobile;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+use EasyWeChat\Work\Mobile\Auth\Client;
+
+/**
+ * ServiceProvider.
+ *
+ * @author 读心印
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ protected $app;
+
+ /**
+ * @param Container $app
+ */
+ public function register(Container $app)
+ {
+ $app['mobile'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/Work/MsgAudit/Client.php b/src/Work/MsgAudit/Client.php
new file mode 100644
index 0000000..8192ab2
--- /dev/null
+++ b/src/Work/MsgAudit/Client.php
@@ -0,0 +1,85 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\MsgAudit;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ *
+ * @author ZengJJ
+ */
+class Client extends BaseClient
+{
+ /**
+ * @param string|null $type
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException|\GuzzleHttp\Exception\GuzzleException
+ */
+ public function getPermitUsers(string $type = null)
+ {
+ return $this->httpPostJson('cgi-bin/msgaudit/get_permit_user_list', (empty($type) ? [] : ['type' => $type]));
+ }
+
+ /**
+ * @param array $info 数组,格式: [[userid, exteranalopenid], [userid, exteranalopenid]]
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getSingleAgreeStatus(array $info)
+ {
+ $params = [
+ 'info' => $info
+ ];
+
+ return $this->httpPostJson('cgi-bin/msgaudit/check_single_agree', $params);
+ }
+
+ /**
+ * @param string $roomId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getRoomAgreeStatus(string $roomId)
+ {
+ $params = [
+ 'roomid' => $roomId
+ ];
+
+ return $this->httpPostJson('cgi-bin/msgaudit/check_room_agree', $params);
+ }
+
+ /**
+ * @param string $roomId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getRoom(string $roomId)
+ {
+ $params = [
+ 'roomid' => $roomId
+ ];
+
+ return $this->httpPostJson('cgi-bin/msgaudit/groupchat/get', $params);
+ }
+}
diff --git a/src/Work/MsgAudit/ServiceProvider.php b/src/Work/MsgAudit/ServiceProvider.php
new file mode 100644
index 0000000..e24c8b3
--- /dev/null
+++ b/src/Work/MsgAudit/ServiceProvider.php
@@ -0,0 +1,33 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\MsgAudit;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider.
+ *
+ * @author ZengJJ
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}.
+ */
+ public function register(Container $app)
+ {
+ $app['msg_audit'] = function ($app) {
+ return new Client($app);
+ };
+ }
+}
diff --git a/src/Work/OA/Client.php b/src/Work/OA/Client.php
index 483d892..1adc6ed 100644
--- a/src/Work/OA/Client.php
+++ b/src/Work/OA/Client.php
@@ -66,6 +66,148 @@ class Client extends BaseClient
return $this->httpPostJson('cgi-bin/checkin/getcheckinoption', $params);
}
+ /**
+ * 获取企业所有打卡规则.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93384
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author 读心印
+ */
+ public function corpCheckinRules()
+ {
+ return $this->httpPostJson('cgi-bin/checkin/getcorpcheckinoption');
+ }
+
+ /**
+ * 获取打卡日报数据.
+ *
+ * @sse https://open.work.weixin.qq.com/api/doc/90000/90135/93374
+ *
+ * @param int $startTime
+ * @param int $endTime
+ * @param array $userids
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author 读心印
+ */
+ public function checkinDayData(int $startTime, int $endTime, array $userids)
+ {
+ $params = [
+ 'starttime' => $startTime,
+ 'endtime' => $endTime,
+ 'useridlist' => $userids,
+ ];
+
+ return $this->httpPostJson('cgi-bin/checkin/getcheckin_daydata', $params);
+ }
+
+ /**
+ * 获取打卡日报数据.
+ *
+ * @sse https://open.work.weixin.qq.com/api/doc/90000/90135/93387
+ *
+ * @param int $startTime
+ * @param int $endTime
+ * @param array $userids
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author 读心印
+ */
+ public function checkinMonthData(int $startTime, int $endTime, array $userids)
+ {
+ $params = [
+ 'starttime' => $startTime,
+ 'endtime' => $endTime,
+ 'useridlist' => $userids,
+ ];
+
+ return $this->httpPostJson('cgi-bin/checkin/getcheckin_monthdata', $params);
+ }
+
+ /**
+ * 获取打卡人员排班信息.
+ *
+ * @sse https://open.work.weixin.qq.com/api/doc/90000/90135/93380
+ *
+ * @param int $startTime
+ * @param int $endTime
+ * @param array $userids
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author 读心印
+ */
+ public function checkinSchedus(int $startTime, int $endTime, array $userids)
+ {
+ $params = [
+ 'starttime' => $startTime,
+ 'endtime' => $endTime,
+ 'useridlist' => $userids,
+ ];
+
+ return $this->httpPostJson('cgi-bin/checkin/getcheckinschedulist', $params);
+ }
+
+ /**
+ * 为打卡人员排班.
+ *
+ * @sse https://open.work.weixin.qq.com/api/doc/90000/90135/93385
+ *
+ * @param array $params
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author 读心印
+ */
+ public function setCheckinSchedus(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/checkin/setcheckinschedulist', $params);
+ }
+
+ /**
+ * 录入打卡人员人脸信息.
+ *
+ * @sse https://open.work.weixin.qq.com/api/doc/90000/90135/93378
+ *
+ * @param string $userid
+ * @param string $userface
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @author 读心印
+ */
+ public function addCheckinUserface(string $userid, string $userface)
+ {
+ $params = [
+ 'userid' => $userid,
+ 'userface' => $userface
+ ];
+
+ return $this->httpPostJson('cgi-bin/checkin/addcheckinuserface', $params);
+ }
+
/**
* Get approval template details.
*
@@ -168,4 +310,30 @@ class Client extends BaseClient
return $this->httpPostJson('cgi-bin/corp/getapprovaldata', $params);
}
+
+
+ /**
+ * 获取公费电话拨打记录.
+ *
+ * @param int $startTime
+ * @param int $endTime
+ * @param int $offset
+ * @param int $limit
+ *
+ * @return mixed
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function dialRecords(int $startTime, int $endTime, int $offset = 0, $limit = 100)
+ {
+ $params = [
+ 'start_time' => $startTime,
+ 'end_time' => $endTime,
+ 'offset' => $offset,
+ 'limit' => $limit
+ ];
+
+ return $this->httpPostJson('cgi-bin/dial/get_dial_record', $params);
+ }
}
diff --git a/src/Work/OAuth/Manager.php b/src/Work/OAuth/Manager.php
new file mode 100644
index 0000000..e0d4b16
--- /dev/null
+++ b/src/Work/OAuth/Manager.php
@@ -0,0 +1,51 @@
+config = $config;
+ $this->app = $app;
+ }
+
+ public function redirect($redirect = null)
+ {
+ return new RedirectResponse($this->getProvider()->redirect($redirect));
+ }
+
+ public function user()
+ {
+ $this->getProvider()->withApiAccessToken($this->app['access_token']->getToken()['access_token']);
+
+ return $this->getProvider()->userFromCode($this->app->request->get('code'));
+ }
+
+ protected function getProvider(): ProviderInterface
+ {
+ return $this->provider ?? $this->provider = (new SocialiteManager($this->config))->create('wework');
+ }
+
+ public function __call($name, $arguments)
+ {
+ return \call_user_func_array([$this->getProvider(), $name], $arguments);
+ }
+}
diff --git a/src/Work/OAuth/ServiceProvider.php b/src/Work/OAuth/ServiceProvider.php
index b1fdfce..b46af8f 100644
--- a/src/Work/OAuth/ServiceProvider.php
+++ b/src/Work/OAuth/ServiceProvider.php
@@ -11,7 +11,6 @@
namespace EasyWeChat\Work\OAuth;
-use Overtrue\Socialite\SocialiteManager;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
@@ -20,13 +19,16 @@ class ServiceProvider implements ServiceProviderInterface
public function register(Container $app)
{
$app['oauth'] = function ($app) {
- $socialite = (new SocialiteManager([
+ $socialite = (new Manager([
'wework' => [
+ 'base_url' => $app['config']['http']['base_uri'],
'client_id' => $app['config']['corp_id'],
'client_secret' => null,
+ 'corp_id' => $app['config']['corp_id'],
+ 'corp_secret' => $app['config']['secret'],
'redirect' => $this->prepareCallbackUrl($app),
],
- ], $app['request']))->driver('wework');
+ ], $app));
$scopes = (array) $app['config']->get('oauth.scopes', ['snsapi_base']);
@@ -36,7 +38,7 @@ class ServiceProvider implements ServiceProviderInterface
$socialite->setAgentId($app['config']['agent_id']);
}
- return $socialite->setAccessToken(new AccessTokenDelegate($app));
+ return $socialite;
};
}
diff --git a/src/Work/Server/Handlers/EchoStrHandler.php b/src/Work/Server/Handlers/EchoStrHandler.php
index 64555ef..52bf8d3 100644
--- a/src/Work/Server/Handlers/EchoStrHandler.php
+++ b/src/Work/Server/Handlers/EchoStrHandler.php
@@ -54,5 +54,7 @@ class EchoStrHandler implements EventHandlerInterface
return new FinallyResult($str);
}
+
+ return null;
}
}
diff --git a/src/Work/User/BatchJobsClient.php b/src/Work/User/BatchJobsClient.php
new file mode 100644
index 0000000..d1e4716
--- /dev/null
+++ b/src/Work/User/BatchJobsClient.php
@@ -0,0 +1,94 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\User;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class BatchJobsClient.
+ *
+ * @author 读心印
+ */
+class BatchJobsClient extends BaseClient
+{
+ /**
+ * 增量更新成员.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/90980
+ *
+ * @param array $params
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function batchUpdateUsers(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/batch/syncuser', $params);
+ }
+
+ /**
+ * 全量覆盖成员.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/90981
+ *
+ * @param array $params
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function batchReplaceUsers(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/batch/replaceuser', $params);
+ }
+
+ /**
+ * 全量覆盖部门.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/90982
+ *
+ * @param array $params
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function batchReplaceDepartments(array $params)
+ {
+ return $this->httpPostJson('cgi-bin/batch/replaceparty', $params);
+ }
+
+ /**
+ * 获取异步任务结果.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93169
+ *
+ * @param string $jobId
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getJobStatus(string $jobId)
+ {
+ $params = [
+ 'jobid' => $jobId
+ ];
+
+ return $this->httpGet('cgi-bin/batch/getresult', $params);
+ }
+}
diff --git a/src/Work/User/Client.php b/src/Work/User/Client.php
index 8c07ec6..9923efd 100644
--- a/src/Work/User/Client.php
+++ b/src/Work/User/Client.php
@@ -248,4 +248,68 @@ class Client extends BaseClient
return $this->httpGet('cgi-bin/corp/get_join_qrcode', ['size_type' => $sizeType]);
}
+
+ /**
+ * @param string|null $cursor
+ * @param int $limit
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getMemberAuthList(?string $cursor = null, int $limit = 1000)
+ {
+ return $this->httpPostJson('cgi-bin/user/list_member_auth', [
+ 'cursor' => $cursor,
+ 'limit' => $limit
+ ]);
+ }
+
+ /**
+ * @param string $openUserId
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function checkMemberAuth(string $openUserId)
+ {
+ return $this->httpPostJson('cgi-bin/user/check_member_auth', [
+ 'open_userid' => $openUserId
+ ]);
+ }
+
+ /**
+ * @param string $selectedTicket
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getSelectedTicketUserList(string $selectedTicket)
+ {
+ return $this->httpPostJson('cgi-bin/user/list_selected_ticket_user', [
+ 'selected_ticket' => $selectedTicket
+ ]);
+ }
+
+ /**
+ * userid转换为open_userid
+ *
+ * @param array $user_ids
+ *
+ * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function userIdToOpenUserId(array $user_ids)
+ {
+ return $this->httpPostJson('cgi-bin/batch/userid_to_openuserid', [
+ 'userid_list' => $user_ids
+ ]);
+ }
}
diff --git a/src/Work/User/LinkedCorpClient.php b/src/Work/User/LinkedCorpClient.php
new file mode 100644
index 0000000..b8595be
--- /dev/null
+++ b/src/Work/User/LinkedCorpClient.php
@@ -0,0 +1,125 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\User;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client.
+ *
+ * @author 读心印
+ */
+class LinkedCorpClient extends BaseClient
+{
+ /**
+ * 获取应用的可见范围.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93172
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getAgentPermissions()
+ {
+ return $this->httpPostJson('cgi-bin/linkedcorp/agent/get_perm_list');
+ }
+
+ /**
+ * 获取互联企业成员详细信息.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93171
+ *
+ * @param string $userId
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getUser(string $userId)
+ {
+ $params = [
+ 'userid' => $userId
+ ];
+
+ return $this->httpPostJson('cgi-bin/linkedcorp/user/get', $params);
+ }
+
+ /**
+ * 获取互联企业部门成员.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93168
+ *
+ * @param string $departmentId
+ * @param bool $fetchChild
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getUsers(string $departmentId, bool $fetchChild = true)
+ {
+ $params = [
+ 'department_id' => $departmentId,
+ 'fetch_child' => $fetchChild
+ ];
+
+ return $this->httpPostJson('cgi-bin/linkedcorp/user/simplelist', $params);
+ }
+
+ /**
+ * 获取互联企业部门成员详情.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93169
+ *
+ * @param string $departmentId
+ * @param bool $fetchChild
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getDetailedUsers(string $departmentId, bool $fetchChild = true)
+ {
+ $params = [
+ 'department_id' => $departmentId,
+ 'fetch_child' => $fetchChild
+ ];
+
+ return $this->httpPostJson('cgi-bin/linkedcorp/user/list', $params);
+ }
+
+ /**
+ * 获取互联企业部门列表.
+ *
+ * @see https://open.work.weixin.qq.com/api/doc/90000/90135/93170
+ *
+ * @param string $departmentId
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getDepartments(string $departmentId)
+ {
+ $params = [
+ 'department_id' => $departmentId,
+ ];
+
+ return $this->httpPostJson('cgi-bin/linkedcorp/department/list', $params);
+ }
+}
diff --git a/src/Work/User/ServiceProvider.php b/src/Work/User/ServiceProvider.php
index fcb5f10..f5cdbc7 100644
--- a/src/Work/User/ServiceProvider.php
+++ b/src/Work/User/ServiceProvider.php
@@ -33,5 +33,13 @@ class ServiceProvider implements ServiceProviderInterface
$app['tag'] = function ($app) {
return new TagClient($app);
};
+
+ $app['linked_corp'] = function ($app) {
+ return new LinkedCorpClient($app);
+ };
+
+ $app['batch_jobs'] = function ($app) {
+ return new BatchJobsClient($app);
+ };
}
}
diff --git a/src/Work/Wedrive/Client.php b/src/Work/Wedrive/Client.php
new file mode 100644
index 0000000..317b753
--- /dev/null
+++ b/src/Work/Wedrive/Client.php
@@ -0,0 +1,54 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Wedrive;
+
+use EasyWeChat\Kernel\BaseClient;
+
+/**
+ * Class Client
+ *
+ * @author lio990527
+ */
+class Client extends BaseClient
+{
+
+ /**
+ * 获取盘专业版信息
+ *
+ * @param string $userid
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95856#%E8%8E%B7%E5%8F%96%E7%9B%98%E4%B8%93%E4%B8%9A%E7%89%88%E4%BF%A1%E6%81%AF
+ */
+ public function proInfo($userid)
+ {
+ return $this->httpPostJson('cgi-bin/wedrive/mng_pro_info', compact('userid'));
+ }
+
+ /**
+ * 获取盘容量信息
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/95856#%E8%8E%B7%E5%8F%96%E7%9B%98%E5%AE%B9%E9%87%8F%E4%BF%A1%E6%81%AF
+ */
+ public function capacity()
+ {
+ return $this->httpPostJson('cgi-bin/wedrive/mng_capacity');
+ }
+}
diff --git a/src/Work/Wedrive/FileClient.php b/src/Work/Wedrive/FileClient.php
new file mode 100644
index 0000000..965fb58
--- /dev/null
+++ b/src/Work/Wedrive/FileClient.php
@@ -0,0 +1,324 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Wedrive;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Support\Arr;
+use GuzzleHttp\Cookie\CookieJar;
+
+/**
+ * Class FileClient
+ *
+ * @author lio990527
+ */
+class FileClient extends BaseClient
+{
+ /**
+ * 新建文件/文档
+ *
+ * @param string $userid 操作者userid
+ * @param string $spaceid 空间spaceid
+ * @param string $fatherid 父目录fileid, 在根目录时为空间spaceid
+ * @param int $fileType 文件类型, 1:文件夹 3:文档(文档) 4:文档(表格) 6:文档(幻灯片)
+ * @param string $fileName 文件名字
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93657#%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E6%96%87%E6%A1%A3
+ */
+ public function create($userid, $spaceid, $fatherid, $fileType, $fileName)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'spaceid' => $spaceid,
+ 'fatherid' => $fatherid,
+ 'file_type' => $fileType,
+ 'file_name' => $fileName
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/file_create', $data);
+ }
+
+ /**
+ * 重命名文件
+ *
+ * @param string $userid 操作人userid
+ * @param string $fileid 文件id
+ * @param string $name 新文件名
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93657#%E9%87%8D%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6
+ */
+ public function rename($userid, $fileid, $name)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'fileid' => $fileid,
+ 'new_name' => $name
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/file_rename', $data);
+ }
+
+ /**
+ * 移动文件
+ *
+ * @param string $userid
+ * @param string|array $fileid 文件fileid
+ * @param string $fatherid 目标目录的fileid
+ * @param boolean $replace 重名时,是否覆盖 false:重名文件进行冲突重命名处理(移动后文件名格式如xxx(1).txt xxx(1).doc等)
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93657#%E7%A7%BB%E5%8A%A8%E6%96%87%E4%BB%B6
+ */
+ public function move($userid, $fileid, $fatherid, $replace = false)
+ {
+ $fileid = (array) $fileid;
+
+ return $this->httpPostJson('cgi-bin/wedrive/file_move', compact('userid', 'fatherid', 'replace', 'fileid'));
+ }
+
+ /**
+ * 删除文件
+ *
+ * @param string $userid
+ * @param string|array $fileid
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93657#%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6
+ */
+ public function delete($userid, $fileid)
+ {
+ $fileid = (array) $fileid;
+
+ return $this->httpPostJson('cgi-bin/wedrive/file_delete', compact('userid', 'fileid'));
+ }
+
+ /**
+ * 获取文件列表
+ *
+ * @param string $userid
+ * @param string $spaceid 空间id
+ * @param string $fatherid 目录id
+ * @param integer $start 查询游标 首次填0, 后续填上一次请求返回的next_start
+ * @param integer $limit 拉取条数 最大1000
+ * @param integer $sort 列表排序方式 1:名字升序;2:名字降序;3:大小升序;4:大小降序;5:修改时间升序;6:修改时间降序
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93657#%E8%8E%B7%E5%8F%96%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8
+ */
+ public function list($userid, $spaceid, $fatherid = null, $start = 0, $limit = 1000, $sort = 1)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'spaceid' => $spaceid,
+ 'fatherid' => $fatherid ?: $spaceid,
+ 'start' => $start,
+ 'limit' => min($limit, 1000),
+ 'sort_type' => $sort
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/file_list', $data);
+ }
+
+ /**
+ * 文件信息
+ *
+ * @param string $userid
+ * @param string $fileid
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93657#%E6%96%87%E4%BB%B6%E4%BF%A1%E6%81%AF
+ */
+ public function info($userid, $fileid)
+ {
+ return $this->httpPostJson('cgi-bin/wedrive/file_info', compact('userid', 'fileid'));
+ }
+
+ /**
+ * 上传文件
+ *
+ * @param string $userid
+ * @param string $spaceid 空间id
+ * @param string $fatherid 目录id
+ * @param string $fileName 文件名
+ * @param string $fileContent 文件内容
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93657#%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6
+ */
+ public function upload($userid, $spaceid, $fatherid, $fileName, $fileContent)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'spaceid' => $spaceid,
+ 'fatherid' => $fatherid,
+ 'file_name' => $fileName,
+ 'file_base64_content' => base64_encode($fileContent)
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/file_upload', $data);
+ }
+
+ /**
+ * 文件下载
+ *
+ * @param string $userid
+ * @param string $fileid
+ * @param boolean $download 是否直接下载
+ *
+ * @return \EasyWeChat\Kernel\Http\StreamResponse|\Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93657#%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6
+ */
+ public function download($userid, $fileid, $download = false)
+ {
+ $response = $this->httpPostJson('cgi-bin/wedrive/file_download', compact('userid', 'fileid'));
+
+ if (!$download || 0 <> $response['errcode']) {
+ return $response;
+ }
+
+ return $this->getHttpClient()->request('GET', $response['download_url'], [
+ 'cookies' => CookieJar::fromArray([
+ $response['cookie_name'] => $response['cookie_value'],
+ ], parse_url($response['download_url'])['host'] ?? 'qq.com'),
+ ]);
+ }
+
+ /**
+ * 获取分享链接
+ *
+ * @param string $userid
+ * @param string $fileid
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93658#%E8%8E%B7%E5%8F%96%E5%88%86%E4%BA%AB%E9%93%BE%E6%8E%A5
+ */
+ public function share($userid, $fileid)
+ {
+ return $this->httpPostJson('cgi-bin/wedrive/file_share', compact('userid', 'fileid'));
+ }
+
+ /**
+ * 分享设置
+ *
+ * @param string $userid
+ * @param string $fileid
+ * @param int $authScope 权限范围:1:指定人 2:企业内 3:企业外
+ * @param int $auth 权限信息 权限信息
+ * 普通文档: 1:仅浏览(可下载) 4:仅预览(仅专业版企业可设置);如果不填充此字段为保持原有状态
+ * 微文档: 1:仅浏览(可下载) 2:可编辑;如果不填充此字段为保持原有状态
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93658#%E5%88%86%E4%BA%AB%E8%AE%BE%E7%BD%AE
+ */
+ public function setting($userid, $fileid, $authScope, $auth = null)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'fileid' => $fileid,
+ 'auth_scope' => $authScope,
+ 'auth' => $auth
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/file_setting', array_filter($data));
+ }
+
+ /**
+ * 新增成员
+ *
+ * @param string $userid
+ * @param string $fileid
+ * @param array $authInfo 添加成员的信息
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93658#%E6%96%B0%E5%A2%9E%E6%88%90%E5%91%98
+ */
+ public function aclAdd($userid, $fileid, $authInfo)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'fileid' => $fileid,
+ 'auth_info' => Arr::isAssoc($authInfo) ? [$authInfo] : $authInfo
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/file_acl_add', $data);
+ }
+
+ /**
+ * 删除成员
+ *
+ * @param string $userid
+ * @param string $fileid
+ * @param array $authInfo 删除成员的信息
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93658#%E5%88%A0%E9%99%A4%E6%88%90%E5%91%98
+ */
+ public function aclDel($userid, $fileid, $authInfo)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'fileid' => $fileid,
+ 'auth_info' => Arr::isAssoc($authInfo) ? [$authInfo] : $authInfo
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/file_acl_del', $data);
+ }
+}
diff --git a/src/Work/Wedrive/ServiceProvider.php b/src/Work/Wedrive/ServiceProvider.php
new file mode 100644
index 0000000..822d42d
--- /dev/null
+++ b/src/Work/Wedrive/ServiceProvider.php
@@ -0,0 +1,37 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Wedrive;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+
+/**
+ * Class ServiceProvider
+ *
+ * @author lio990527
+ */
+class ServiceProvider implements ServiceProviderInterface
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function register(Container $app)
+ {
+ $app['wedrive'] = function ($app) {
+ return new Wedrive([
+ 'base' => new Client($app),
+ 'space' => new SpaceClient($app),
+ 'file' => new FileClient($app),
+ ]);
+ };
+ }
+}
diff --git a/src/Work/Wedrive/SpaceClient.php b/src/Work/Wedrive/SpaceClient.php
new file mode 100644
index 0000000..6824bd7
--- /dev/null
+++ b/src/Work/Wedrive/SpaceClient.php
@@ -0,0 +1,201 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Wedrive;
+
+use EasyWeChat\Kernel\BaseClient;
+use EasyWeChat\Kernel\Support\Arr;
+
+/**
+ * Class SpaceClient
+ *
+ * @author lio990527
+ */
+class SpaceClient extends BaseClient
+{
+
+ /**
+ * 新建空间
+ *
+ * @param string $userid 操作者userid
+ * @param string $spaceName 空间名称
+ * @param array $authInfo 空间成员权限信息
+ * @param integer $spaceSubType 空间类型, 0:普通 1:相册
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93656#%E6%96%B0%E5%BB%BA%E7%A9%BA%E9%97%B4
+ */
+ public function create($userid, $spaceName, $authInfo = [], $spaceSubType = 0)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'space_name' => $spaceName,
+ 'auth_info' => Arr::isAssoc($authInfo) ? [$authInfo] : $authInfo,
+ 'space_sub_type' => $spaceSubType,
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/space_create', $data);
+ }
+
+ /**
+ * 重命名空间
+ *
+ * @param string $userid
+ * @param string $spaceid
+ * @param string $spaceName 重命名后的空间名
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93656#%E9%87%8D%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4
+ */
+ public function rename($userid, $spaceid, $spaceName)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'spaceid' => $spaceid,
+ 'space_name' => $spaceName
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/space_rename', $data);
+ }
+
+ /**
+ * 解散空间
+ *
+ * @param string $userid
+ * @param string $spaceid
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93656#%E8%A7%A3%E6%95%A3%E7%A9%BA%E9%97%B4
+ */
+ public function dismiss($userid, $spaceid)
+ {
+ return $this->httpPostJson('cgi-bin/wedrive/space_dismiss', compact('userid', 'spaceid'));
+ }
+
+ /**
+ * 获取空间/相册信息
+ *
+ * @param string $userid
+ * @param string $spaceid
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93656#%E8%8E%B7%E5%8F%96%E7%A9%BA%E9%97%B4%E7%9B%B8%E5%86%8C%E4%BF%A1%E6%81%AF
+ */
+ public function info($userid, $spaceid)
+ {
+ return $this->httpPostJson('cgi-bin/wedrive/space_info', compact('userid', 'spaceid'));
+ }
+
+ /**
+ * 获取邀请链接
+ *
+ * @param string $userid
+ * @param string $spaceid
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93656#%E8%8E%B7%E5%8F%96%E9%82%80%E8%AF%B7%E9%93%BE%E6%8E%A5
+ */
+ public function share($userid, $spaceid)
+ {
+ return $this->httpPostJson('cgi-bin/wedrive/space_share', compact('userid', 'spaceid'));
+ }
+
+ /**
+ * 安全设置
+ *
+ * @param string $userid
+ * @param string $spaceid
+ * @param array $settings 设置
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93656#%E5%AE%89%E5%85%A8%E8%AE%BE%E7%BD%AE
+ */
+ public function setting($userid, $spaceid, $settings)
+ {
+ $data = array_merge(compact('userid', 'spaceid'), $settings);
+
+ return $this->httpPostJson('cgi-bin/wedrive/space_setting', $data);
+ }
+
+ /**
+ * 添加成员/部门
+ *
+ * @param string $userid
+ * @param string $spaceid
+ * @param array $authInfo 被添加的空间成员信息
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93656#%E6%B7%BB%E5%8A%A0%E6%88%90%E5%91%98%E9%83%A8%E9%97%A8
+ */
+ public function aclAdd($userid, $spaceid, $authInfo)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'spaceid' => $spaceid,
+ 'auth_info' => Arr::isAssoc($authInfo) ? [$authInfo] : $authInfo
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/space_acl_add', $data);
+ }
+
+ /**
+ * 移除成员/部门
+ *
+ * @param string $userid
+ * @param string $spaceid
+ * @param array $authInfo 被移除的空间成员信息
+ *
+ * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
+ *
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ *
+ * @see https://developer.work.weixin.qq.com/document/path/93656#%E6%B7%BB%E5%8A%A0%E6%88%90%E5%91%98%E9%83%A8%E9%97%A8
+ */
+ public function aclDel($userid, $spaceid, $authInfo)
+ {
+ $data = [
+ 'userid' => $userid,
+ 'spaceid' => $spaceid,
+ 'auth_info' => Arr::isAssoc($authInfo) ? [$authInfo] : $authInfo
+ ];
+
+ return $this->httpPostJson('cgi-bin/wedrive/space_acl_del', $data);
+ }
+}
diff --git a/src/Work/Wedrive/Wedrive.php b/src/Work/Wedrive/Wedrive.php
new file mode 100644
index 0000000..bb01931
--- /dev/null
+++ b/src/Work/Wedrive/Wedrive.php
@@ -0,0 +1,32 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace EasyWeChat\Work\Wedrive;
+
+use Pimple\Container;
+
+/**
+ * Class Wedrive
+ *
+ * @property \EasyWeChat\Work\Wedrive\Client $base
+ * @property \EasyWeChat\Work\Wedrive\SpaceClient $space
+ * @property \EasyWeChat\Work\Wedrive\FileClient $file
+ *
+ * @author lio990527
+ */
+class Wedrive extends Container
+{
+
+ public function __get($key)
+ {
+ return $this->offsetGet($key);
+ }
+}