Browse Source

更新接口

master v1.0.1
wuliangbo 2 years ago
parent
commit
f85f55bd77
  1. 3
      .gitignore
  2. 13
      composer.json
  3. 19
      src/BasicService/ContentSecurity/Client.php
  4. 50
      src/BasicService/Jssdk/Client.php
  5. 13
      src/BasicService/Media/Client.php
  6. 21
      src/BasicService/QrCode/Client.php
  7. 5
      src/BasicService/Url/Client.php
  8. 11
      src/Kernel/AccessToken.php
  9. 67
      src/Kernel/BaseClient.php
  10. 13
      src/Kernel/Clauses/Clause.php
  11. 30
      src/Kernel/Encryptor.php
  12. 2
      src/Kernel/Http/Response.php
  13. 74
      src/Kernel/Log/LogManager.php
  14. 49
      src/Kernel/Messages/InteractiveTaskCard.php
  15. 34
      src/Kernel/Messages/Message.php
  16. 13
      src/Kernel/Messages/MiniprogramNotice.php
  17. 60
      src/Kernel/Messages/ReplyInteractiveTaskCard.php
  18. 2
      src/Kernel/Messages/Text.php
  19. 2
      src/Kernel/Providers/ConfigServiceProvider.php
  20. 2
      src/Kernel/Providers/EventDispatcherServiceProvider.php
  21. 2
      src/Kernel/Providers/ExtensionServiceProvider.php
  22. 2
      src/Kernel/Providers/HttpClientServiceProvider.php
  23. 38
      src/Kernel/Providers/LogServiceProvider.php
  24. 2
      src/Kernel/Providers/RequestServiceProvider.php
  25. 4
      src/Kernel/ServerGuard.php
  26. 4
      src/Kernel/ServiceContainer.php
  27. 2
      src/Kernel/Support/Arr.php
  28. 23
      src/Kernel/Support/Collection.php
  29. 4
      src/Kernel/Support/XML.php
  30. 6
      src/Kernel/Traits/Observable.php
  31. 2
      src/MicroMerchant/Kernel/BaseClient.php
  32. 33
      src/MiniProgram/Application.php
  33. 2
      src/MiniProgram/Auth/AccessToken.php
  34. 333
      src/MiniProgram/Broadcast/Client.php
  35. 149
      src/MiniProgram/Business/Client.php
  36. 179
      src/MiniProgram/Business/Messenger.php
  37. 29
      src/MiniProgram/Business/ServiceProvider.php
  38. 29
      src/MiniProgram/DataCube/Client.php
  39. 64
      src/MiniProgram/Express/Client.php
  40. 9
      src/MiniProgram/OpenData/Client.php
  41. 47
      src/MiniProgram/PhoneNumber/Client.php
  42. 28
      src/MiniProgram/PhoneNumber/ServiceProvider.php
  43. 126
      src/MiniProgram/QrCode/Client.php
  44. 33
      src/MiniProgram/QrCode/ServiceProvider.php
  45. 32
      src/MiniProgram/RiskControl/Client.php
  46. 25
      src/MiniProgram/RiskControl/ServiceProvider.php
  47. 67
      src/MiniProgram/Shop/Account/Client.php
  48. 25
      src/MiniProgram/Shop/Account/ServiceProvider.php
  49. 54
      src/MiniProgram/Shop/Aftersale/Client.php
  50. 25
      src/MiniProgram/Shop/Aftersale/ServiceProvider.php
  51. 110
      src/MiniProgram/Shop/Basic/Client.php
  52. 25
      src/MiniProgram/Shop/Basic/ServiceProvider.php
  53. 52
      src/MiniProgram/Shop/Delivery/Client.php
  54. 25
      src/MiniProgram/Shop/Delivery/ServiceProvider.php
  55. 157
      src/MiniProgram/Shop/Order/Client.php
  56. 25
      src/MiniProgram/Shop/Order/ServiceProvider.php
  57. 76
      src/MiniProgram/Shop/Register/Client.php
  58. 33
      src/MiniProgram/Shop/Register/ServiceProvider.php
  59. 132
      src/MiniProgram/Shop/Spu/Client.php
  60. 25
      src/MiniProgram/Shop/Spu/ServiceProvider.php
  61. 42
      src/MiniProgram/ShortLink/Client.php
  62. 19
      src/MiniProgram/ShortLink/ServiceProvider.php
  63. 3
      src/MiniProgram/SubscribeMessage/Client.php
  64. 2
      src/MiniProgram/TemplateMessage/Client.php
  65. 2
      src/MiniProgram/UniformMessage/Client.php
  66. 228
      src/MiniProgram/Union/Client.php
  67. 33
      src/MiniProgram/Union/ServiceProvider.php
  68. 32
      src/MiniProgram/UrlLink/Client.php
  69. 19
      src/MiniProgram/UrlLink/ServiceProvider.php
  70. 32
      src/MiniProgram/UrlScheme/Client.php
  71. 19
      src/MiniProgram/UrlScheme/ServiceProvider.php
  72. 11
      src/OfficialAccount/Application.php
  73. 2
      src/OfficialAccount/Auth/AccessToken.php
  74. 19
      src/OfficialAccount/Base/Client.php
  75. 4
      src/OfficialAccount/Broadcasting/Client.php
  76. 2
      src/OfficialAccount/Card/Client.php
  77. 78
      src/OfficialAccount/Card/InvoiceClient.php
  78. 108
      src/OfficialAccount/Draft/Client.php
  79. 35
      src/OfficialAccount/Draft/ServiceProvider.php
  80. 90
      src/OfficialAccount/FreePublish/Client.php
  81. 35
      src/OfficialAccount/FreePublish/ServiceProvider.php
  82. 991
      src/OfficialAccount/Guide/Client.php
  83. 33
      src/OfficialAccount/Guide/ServiceProvider.php
  84. 17
      src/OfficialAccount/OAuth/ServiceProvider.php
  85. 75
      src/OfficialAccount/OCR/Client.php
  86. 2
      src/OfficialAccount/Server/Handlers/EchoStrHandler.php
  87. 1
      src/OfficialAccount/ShakeAround/ShakeAround.php
  88. 2
      src/OfficialAccount/Store/Client.php
  89. 189
      src/OfficialAccount/SubscribeMessage/Client.php
  90. 27
      src/OfficialAccount/SubscribeMessage/ServiceProvider.php
  91. 4
      src/OfficialAccount/TemplateMessage/Client.php
  92. 169
      src/OpenPlatform/Application.php
  93. 21
      src/OpenPlatform/Authorizer/MiniProgram/Account/Client.php
  94. 14
      src/OpenPlatform/Authorizer/MiniProgram/Application.php
  95. 10
      src/OpenPlatform/Authorizer/MiniProgram/Code/Client.php
  96. 51
      src/OpenPlatform/Authorizer/MiniProgram/Material/Client.php
  97. 44
      src/OpenPlatform/Authorizer/MiniProgram/Material/ServiceProvider.php
  98. 66
      src/OpenPlatform/Authorizer/MiniProgram/Privacy/Client.php
  99. 25
      src/OpenPlatform/Authorizer/MiniProgram/Privacy/ServiceProvider.php
  100. 45
      src/OpenPlatform/Authorizer/MiniProgram/Security/Client.php
  101. Some files were not shown because too many files have changed in this diff Show More

3
.gitignore vendored

@ -3,4 +3,5 @@ @@ -3,4 +3,5 @@
/vendor
*.log
.env
composer.lock
composer.lock
.git

13
composer.json

@ -20,15 +20,16 @@ @@ -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": {

19
src/BasicService/ContentSecurity/Client.php

@ -21,28 +21,21 @@ use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; @@ -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 @@ -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 @@ -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);
}
/**

50
src/BasicService/Jssdk/Client.php

@ -28,7 +28,7 @@ class Client extends BaseClient @@ -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 @@ -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 @@ -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 @@ -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 @@ -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');
}
}

13
src/BasicService/Media/Client.php

@ -22,11 +22,6 @@ use EasyWeChat\Kernel\Http\StreamResponse; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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,
],

21
src/BasicService/QrCode/Client.php

@ -20,18 +20,13 @@ use EasyWeChat\Kernel\BaseClient; @@ -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 @@ -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);
}
}

5
src/BasicService/Url/Client.php

@ -20,11 +20,6 @@ use EasyWeChat\Kernel\BaseClient; @@ -20,11 +20,6 @@ use EasyWeChat\Kernel\BaseClient;
*/
class Client extends BaseClient
{
/**
* @var string
*/
protected $baseUri = 'https://api.weixin.qq.com/';
/**
* Shorten the url.
*

11
src/Kernel/AccessToken.php

@ -75,6 +75,11 @@ abstract class AccessToken implements AccessTokenInterface @@ -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 @@ -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 @@ -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;

67
src/Kernel/BaseClient.php

@ -27,18 +27,18 @@ use Psr\Log\LogLevel; @@ -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 @@ -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 @@ -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 @@ -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));
}
);
}
}

13
src/Kernel/Clauses/Clause.php

@ -56,9 +56,20 @@ class Clause @@ -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;
}
}

30
src/Kernel/Encryptor.php

@ -13,9 +13,9 @@ namespace EasyWeChat\Kernel; @@ -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; @@ -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 @@ -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 @@ -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));

2
src/Kernel/Http/Response.php

@ -116,6 +116,6 @@ class Response extends GuzzleResponse @@ -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'));
}
}

74
src/Kernel/Log/LogManager.php

@ -271,9 +271,10 @@ class LogManager implements LoggerInterface @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -597,8 +585,6 @@ class LogManager implements LoggerInterface
* @param string $method
* @param array $parameters
*
* @return mixed
*
* @throws \Exception
*/
public function __call($method, $parameters)

49
src/Kernel/Messages/InteractiveTaskCard.php

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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',
];
}

34
src/Kernel/Messages/Message.php

@ -23,22 +23,24 @@ abstract class Message implements MessageInterface @@ -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

13
src/Kernel/Messages/MiniprogramNotice.php

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
<?php
namespace EasyWeChat\Kernel\Messages;
class MiniprogramNotice extends Message
{
protected $type = 'miniprogram_notice';
protected $properties = [
'appid',
'title',
];
}

60
src/Kernel/Messages/ReplyInteractiveTaskCard.php

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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'),
],
];
}
}

2
src/Kernel/Messages/Text.php

@ -37,7 +37,7 @@ class Text extends Message @@ -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'));
}

2
src/Kernel/Providers/ConfigServiceProvider.php

@ -32,7 +32,7 @@ class ConfigServiceProvider implements ServiceProviderInterface @@ -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());
};
}

2
src/Kernel/Providers/EventDispatcherServiceProvider.php

@ -32,7 +32,7 @@ class EventDispatcherServiceProvider implements ServiceProviderInterface @@ -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) {

2
src/Kernel/Providers/ExtensionServiceProvider.php

@ -32,7 +32,7 @@ class ExtensionServiceProvider implements ServiceProviderInterface @@ -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);
};
}

2
src/Kernel/Providers/HttpClientServiceProvider.php

@ -32,7 +32,7 @@ class HttpClientServiceProvider implements ServiceProviderInterface @@ -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', []));
};
}

38
src/Kernel/Providers/LogServiceProvider.php

@ -32,8 +32,8 @@ class LogServiceProvider implements ServiceProviderInterface @@ -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 @@ -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'];
}
}

2
src/Kernel/Providers/RequestServiceProvider.php

@ -32,7 +32,7 @@ class RequestServiceProvider implements ServiceProviderInterface @@ -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();
};
}

4
src/Kernel/ServerGuard.php

@ -45,12 +45,12 @@ class ServerGuard @@ -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,

4
src/Kernel/ServiceContainer.php

@ -64,11 +64,11 @@ class ServiceContainer extends Container @@ -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;

2
src/Kernel/Support/Arr.php

@ -181,7 +181,7 @@ class Arr @@ -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;

23
src/Kernel/Support/Collection.php

@ -229,11 +229,17 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria @@ -229,11 +229,17 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @return mixed data which can be serialized by <b>json_encode</b>,
* 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 &gt;= 5.1.0)<br/>
* String representation of object.
@ -256,6 +262,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria @@ -256,6 +262,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* @return \ArrayIterator An instance of an object implementing <b>Iterator</b> or
* <b>Traversable</b>
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->items);
@ -272,11 +279,17 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria @@ -272,11 +279,17 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* <p>
* 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 &gt;= 5.1.0)<br/>
* Constructs the object.
@ -342,11 +355,13 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria @@ -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 @@ -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 @@ -377,6 +393,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* The offset to unset.
* </p>
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
@ -396,6 +413,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria @@ -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 @@ -414,6 +432,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* The value to set.
* </p>
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->set($offset, $value);

4
src/Kernel/Support/XML.php

@ -27,11 +27,11 @@ class XML @@ -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;
}

6
src/Kernel/Traits/Observable.php

@ -56,10 +56,10 @@ trait Observable @@ -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 @@ -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;
}

2
src/MicroMerchant/Kernel/BaseClient.php

@ -204,7 +204,7 @@ class BaseClient extends PaymentBaseClient @@ -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);

33
src/MiniProgram/Application.php

@ -31,7 +31,7 @@ use EasyWeChat\Kernel\ServiceContainer; @@ -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; @@ -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 @@ -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 @@ -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,
];
/**

2
src/MiniProgram/Auth/AccessToken.php

@ -23,7 +23,7 @@ class AccessToken extends BaseAccessToken @@ -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}

333
src/MiniProgram/Broadcast/Client.php

@ -135,7 +135,7 @@ class Client extends BaseClient @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);
}
}

149
src/MiniProgram/Business/Client.php

@ -0,0 +1,149 @@ @@ -0,0 +1,149 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
*/
namespace EasyWeChat\MiniProgram\Business;
use EasyWeChat\Kernel\BaseClient;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
/**
* Class Client.
*
* @author wangdongzhao <elim051@163.com>
*/
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);
}
}

179
src/MiniProgram/Business/Messenger.php

@ -0,0 +1,179 @@ @@ -0,0 +1,179 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
*/
namespace EasyWeChat\MiniProgram\Business;
use EasyWeChat\Kernel\Exceptions\RuntimeException;
use EasyWeChat\Kernel\Messages\Message;
use EasyWeChat\Kernel\Messages\Raw as RawMessage;
use EasyWeChat\Kernel\Messages\Text;
/**
* Class MessageBuilder.
*
* @author wangdongzhao <elim051@163.com>
*/
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;
}
}

29
src/MiniProgram/Business/ServiceProvider.php

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
*/
namespace EasyWeChat\MiniProgram\Business;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
/**
* Class ServiceProvider.
*
* @author wangdongzhao <elim051@163.com>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}.
*/
public function register(Container $app)
{
$app['business'] = function ($app) {
return new Client($app);
};
}
}

29
src/MiniProgram/DataCube/Client.php

@ -150,6 +150,35 @@ class Client extends BaseClient @@ -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.
*

64
src/MiniProgram/Express/Client.php

@ -12,6 +12,7 @@ @@ -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; @@ -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 @@ -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 @@ -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
]);
}
}

9
src/MiniProgram/OpenData/Client.php

@ -20,11 +20,6 @@ use EasyWeChat\Kernel\BaseClient; @@ -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 @@ -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 @@ -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);
}
/**

47
src/MiniProgram/PhoneNumber/Client.php

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 读心印 <aa24615@qq.com>
*/
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 读心印 <aa24615@qq.com>
*/
public function getUserPhoneNumber(string $code)
{
$params = [
'code' => $code
];
return $this->httpPostJson('wxa/business/getuserphonenumber', $params);
}
}

28
src/MiniProgram/PhoneNumber/ServiceProvider.php

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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);
};
}
}

126
src/MiniProgram/QrCode/Client.php

@ -0,0 +1,126 @@ @@ -0,0 +1,126 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <dysodengs@gmail.com>
*/
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);
}
}

33
src/MiniProgram/QrCode/ServiceProvider.php

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <dysodengs@gmail.com>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}.
*/
public function register(Container $pimple)
{
$pimple['qr_code'] = function ($app) {
return new Client($app);
};
}
}

32
src/MiniProgram/RiskControl/Client.php

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
<?php
namespace EasyWeChat\MiniProgram\RiskControl;
use EasyWeChat\Kernel\BaseClient;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use EasyWeChat\Kernel\Support\Collection;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
/**
* 安全风控
*
* Class Client
* @package EasyWeChat\MiniProgram\RiskControl
*/
class Client extends BaseClient
{
/**
* 获取用户的安全等级
*
* @param array $params
* @return array|Collection|object|ResponseInterface|string
*
* @throws InvalidConfigException
* @throws GuzzleException
*/
public function getUserRiskRank(array $params)
{
return $this->httpPostJson('wxa/getuserriskrank', $params);
}
}

25
src/MiniProgram/RiskControl/ServiceProvider.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
namespace EasyWeChat\MiniProgram\RiskControl;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
/**
* 安全风控
*
* Class ServiceProvider
* @package EasyWeChat\MiniProgram\RiskControl
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* @inheritDoc
*/
public function register(Container $app)
{
$app['risk_control'] = function ($app) {
return new Client($app);
};
}
}

67
src/MiniProgram/Shop/Account/Client.php

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Account;
use EasyWeChat\Kernel\BaseClient;
/**
* 自定义版交易组件及开放接口 - 商家入驻接口
*
* @package EasyWeChat\MiniProgram\Shop\Account
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
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');
}
}

25
src/MiniProgram/Shop/Account/ServiceProvider.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Account;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
/**
* 自定义版交易组件及开放接口 - 商家入驻接口
*
* @package EasyWeChat\MiniProgram\Shop\Account
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
$app['shop_account'] = function ($app) {
return new Client($app);
};
}
}

54
src/MiniProgram/Shop/Aftersale/Client.php

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Aftersale;
use EasyWeChat\Kernel\BaseClient;
/**
* 自定义版交易组件及开放接口 - 售后接口
*
* @package EasyWeChat\MiniProgram\Shop\Aftersale
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
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));
}
}

25
src/MiniProgram/Shop/Aftersale/ServiceProvider.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Aftersale;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
/**
* 自定义版交易组件及开放接口 - 售后接口
*
* @package EasyWeChat\MiniProgram\Shop\Aftersale
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* @inheritDoc
*/
public function register(Container $app)
{
$app['shop_aftersale'] = function ($app) {
return new Client($app);
};
}
}

110
src/MiniProgram/Shop/Basic/Client.php

@ -0,0 +1,110 @@ @@ -0,0 +1,110 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Basic;
use EasyWeChat\Kernel\BaseClient;
/**
* 自定义版交易组件及开放接口 - 接入商品前必需接口
*
* @package EasyWeChat\MiniProgram\Shop\Basic
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
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
]);
}
}

25
src/MiniProgram/Shop/Basic/ServiceProvider.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Basic;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
/**
* 自定义版交易组件及开放接口 - 接入商品前必需接口
*
* @package EasyWeChat\MiniProgram\Shop\Basic
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* @inheritDoc
*/
public function register(Container $app)
{
$app['shop_basic'] = function ($app) {
return new Client($app);
};
}
}

52
src/MiniProgram/Shop/Delivery/Client.php

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Delivery;
use EasyWeChat\Kernel\BaseClient;
/**
* 自定义版交易组件及开放接口 - 物流接口
*
* @package EasyWeChat\MiniProgram\Shop\Delivery
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
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);
}
}

25
src/MiniProgram/Shop/Delivery/ServiceProvider.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Delivery;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
/**
* 自定义版交易组件及开放接口 - 物流接口
*
* @package EasyWeChat\MiniProgram\Shop\Delivery
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* @inheritDoc
*/
public function register(Container $app)
{
$app['shop_delivery'] = function ($app) {
return new Client($app);
};
}
}

157
src/MiniProgram/Shop/Order/Client.php

@ -0,0 +1,157 @@ @@ -0,0 +1,157 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Order;
use EasyWeChat\Kernel\BaseClient;
/**
* 自定义版交易组件及开放接口 - 订单接口
*
* @package EasyWeChat\MiniProgram\Shop\Order
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
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);
}
}

25
src/MiniProgram/Shop/Order/ServiceProvider.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Order;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
/**
* 自定义版交易组件及开放接口 - 订单接口
*
* @package EasyWeChat\MiniProgram\Shop\Order
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* @inheritDoc
*/
public function register(Container $app)
{
$app['shop_order'] = function ($app) {
return new Client($app);
};
}
}

76
src/MiniProgram/Shop/Register/Client.php

@ -0,0 +1,76 @@ @@ -0,0 +1,76 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <hxhsoft@foxmail.com>
*/
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
]);
}
}

33
src/MiniProgram/Shop/Register/ServiceProvider.php

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <hxhsoft@foxmail.com>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
$app['shop_register'] = function ($app) {
return new Client($app);
};
}
}

132
src/MiniProgram/Shop/Spu/Client.php

@ -0,0 +1,132 @@ @@ -0,0 +1,132 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Spu;
use EasyWeChat\Kernel\BaseClient;
/**
* 自定义版交易组件及开放接口 - SPU接口
*
* @package EasyWeChat\MiniProgram\Shop\Spu
* @author HaoLiang <haoliang@qiyuankeji.cn>
*/
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);
}
}

25
src/MiniProgram/Shop/Spu/ServiceProvider.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
namespace EasyWeChat\MiniProgram\Shop\Spu;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
/**
* 自定义版交易组件及开放接口 - SPU接口
*
* @author HaoLiang <haoliang@qiyuankeji.cn>
* @package EasyWeChat\MiniProgram\Shop\Spu
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}
*/
public function register(Container $app)
{
$app['shop_spu'] = function ($app) {
return new Client($app);
};
}
}

42
src/MiniProgram/ShortLink/Client.php

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
<?php
namespace EasyWeChat\MiniProgram\ShortLink;
use EasyWeChat\Kernel\BaseClient;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use EasyWeChat\Kernel\Support\Collection;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
/**
* Class Client.
*
* @package EasyWeChat\MiniProgram\ShortLink
*
* @author 读心印 <aa24615@qq.com>
*/
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);
}
}

19
src/MiniProgram/ShortLink/ServiceProvider.php

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
<?php
namespace EasyWeChat\MiniProgram\ShortLink;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
class ServiceProvider implements ServiceProviderInterface
{
/**
* @inheritDoc
*/
public function register(Container $app)
{
$app['short_link'] = function ($app) {
return new Client($app);
};
}
}

3
src/MiniProgram/SubscribeMessage/Client.php

@ -30,6 +30,7 @@ class Client extends BaseClient @@ -30,6 +30,7 @@ class Client extends BaseClient
'template_id' => '',
'page' => '',
'data' => [],
'miniprogram_state' => 'formal',
];
/**
@ -78,7 +79,7 @@ class Client extends BaseClient @@ -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;

2
src/MiniProgram/TemplateMessage/Client.php

@ -20,7 +20,7 @@ use EasyWeChat\OfficialAccount\TemplateMessage\Client as BaseClient; @@ -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}.

2
src/MiniProgram/UniformMessage/Client.php

@ -16,7 +16,7 @@ use EasyWeChat\OfficialAccount\TemplateMessage\Client as BaseClient; @@ -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}.

228
src/MiniProgram/Union/Client.php

@ -0,0 +1,228 @@ @@ -0,0 +1,228 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <uctoo@foxmail.com>
*/
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);
}
}

33
src/MiniProgram/Union/ServiceProvider.php

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <uctoo@foxmail.com>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}.
*/
public function register(Container $app)
{
$app['union'] = function ($app) {
return new Client($app);
};
}
}

32
src/MiniProgram/UrlLink/Client.php

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
<?php
namespace EasyWeChat\MiniProgram\UrlLink;
use EasyWeChat\Kernel\BaseClient;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use EasyWeChat\Kernel\Support\Collection;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
/**
* Url Scheme
*
* Class Client
* @package EasyWeChat\MiniProgram\UrlLink
*/
class Client extends BaseClient
{
/**
* 获取小程序 URL Link
*
* @param array $param
* @return array|Collection|object|ResponseInterface|string
*
* @throws GuzzleException
* @throws InvalidConfigException
*/
public function generate(array $param = [])
{
return $this->httpPostJson('wxa/generate_urllink', $param);
}
}

19
src/MiniProgram/UrlLink/ServiceProvider.php

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
<?php
namespace EasyWeChat\MiniProgram\UrlLink;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
class ServiceProvider implements ServiceProviderInterface
{
/**
* @inheritDoc
*/
public function register(Container $app)
{
$app['url_link'] = function ($app) {
return new Client($app);
};
}
}

32
src/MiniProgram/UrlScheme/Client.php

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
<?php
namespace EasyWeChat\MiniProgram\UrlScheme;
use EasyWeChat\Kernel\BaseClient;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use EasyWeChat\Kernel\Support\Collection;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
/**
* Url Scheme
*
* Class Client
* @package EasyWeChat\MiniProgram\UrlScheme
*/
class Client extends BaseClient
{
/**
* 获取小程序scheme码
*
* @param array $param
* @return array|Collection|object|ResponseInterface|string
*
* @throws GuzzleException
* @throws InvalidConfigException
*/
public function generate(array $param = [])
{
return $this->httpPostJson('wxa/generatescheme', $param);
}
}

19
src/MiniProgram/UrlScheme/ServiceProvider.php

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
<?php
namespace EasyWeChat\MiniProgram\UrlScheme;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
class ServiceProvider implements ServiceProviderInterface
{
/**
* @inheritDoc
*/
public function register(Container $app)
{
$app['url_scheme'] = function ($app) {
return new Client($app);
};
}
}

11
src/OfficialAccount/Application.php

@ -29,6 +29,7 @@ use EasyWeChat\Kernel\ServiceContainer; @@ -29,6 +29,7 @@ use EasyWeChat\Kernel\ServiceContainer;
* @property \EasyWeChat\OfficialAccount\User\TagClient $user_tag
* @property \EasyWeChat\OfficialAccount\Menu\Client $menu
* @property \EasyWeChat\OfficialAccount\TemplateMessage\Client $template_message
* @property \EasyWeChat\OfficialAccount\SubscribeMessage\Client $subscribe_message
* @property \EasyWeChat\OfficialAccount\Material\Client $material
* @property \EasyWeChat\OfficialAccount\CustomerService\Client $customer_service
* @property \EasyWeChat\OfficialAccount\CustomerService\SessionClient $customer_service_session
@ -45,11 +46,14 @@ use EasyWeChat\Kernel\ServiceContainer; @@ -45,11 +46,14 @@ use EasyWeChat\Kernel\ServiceContainer;
* @property \EasyWeChat\OfficialAccount\Comment\Client $comment
* @property \EasyWeChat\OfficialAccount\OCR\Client $ocr
* @property \EasyWeChat\OfficialAccount\Goods\Client $goods
* @property \Overtrue\Socialite\Providers\WeChatProvider $oauth
* @property \Overtrue\Socialite\Providers\WeChat $oauth
* @property \EasyWeChat\OfficialAccount\WiFi\Client $wifi
* @property \EasyWeChat\OfficialAccount\WiFi\CardClient $wifi_card
* @property \EasyWeChat\OfficialAccount\WiFi\DeviceClient $wifi_device
* @property \EasyWeChat\OfficialAccount\WiFi\ShopClient $wifi_shop
* @property \EasyWeChat\OfficialAccount\Guide\Client $guide
* @property \EasyWeChat\OfficialAccount\Draft\Client $draft
* @property \EasyWeChat\OfficialAccount\FreePublish\Client $free_publish
*/
class Application extends ServiceContainer
{
@ -63,6 +67,7 @@ class Application extends ServiceContainer @@ -63,6 +67,7 @@ class Application extends ServiceContainer
OAuth\ServiceProvider::class,
Menu\ServiceProvider::class,
TemplateMessage\ServiceProvider::class,
SubscribeMessage\ServiceProvider::class,
Material\ServiceProvider::class,
CustomerService\ServiceProvider::class,
Semantic\ServiceProvider::class,
@ -79,10 +84,14 @@ class Application extends ServiceContainer @@ -79,10 +84,14 @@ class Application extends ServiceContainer
OCR\ServiceProvider::class,
Goods\ServiceProvider::class,
WiFi\ServiceProvider::class,
Draft\ServiceProvider::class,
FreePublish\ServiceProvider::class,
// Base services
BasicService\QrCode\ServiceProvider::class,
BasicService\Media\ServiceProvider::class,
BasicService\Url\ServiceProvider::class,
BasicService\Jssdk\ServiceProvider::class,
// Append Guide Interface
Guide\ServiceProvider::class,
];
}

2
src/OfficialAccount/Auth/AccessToken.php

@ -23,7 +23,7 @@ class AccessToken extends BaseAccessToken @@ -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';
/**
* @return array

19
src/OfficialAccount/Base/Client.php

@ -21,6 +21,25 @@ use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; @@ -21,6 +21,25 @@ use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
*/
class Client extends BaseClient
{
/**
* Get api quota.
*
* @param string $cgiPath api cgi_path
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getQuota(string $cgiPath)
{
$params = [
'cgi_path' => $cgiPath,
];
return $this->httpPostJson('cgi-bin/openapi/quota/get', $params);
}
/**
* Clear quota.
*

4
src/OfficialAccount/Broadcasting/Client.php

@ -34,8 +34,8 @@ use EasyWeChat\Kernel\Support\Arr; @@ -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.

2
src/OfficialAccount/Card/Client.php

@ -77,7 +77,7 @@ class Client extends BaseClient @@ -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' => [

78
src/OfficialAccount/Card/InvoiceClient.php

@ -98,6 +98,84 @@ class InvoiceClient extends BaseClient @@ -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

108
src/OfficialAccount/Draft/Client.php

@ -0,0 +1,108 @@ @@ -0,0 +1,108 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <elim051@163.com>
*/
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]);
}
}

35
src/OfficialAccount/Draft/ServiceProvider.php

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
<?php
/**
* ServiceProvider.php.
*
* This file is part of the wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <elim051@163.com>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}.
*/
public function register(Container $app)
{
$app['draft'] = function ($app) {
return new Client($app);
};
}
}

90
src/OfficialAccount/FreePublish/Client.php

@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <elim051@163.com>
*/
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]);
}
}

35
src/OfficialAccount/FreePublish/ServiceProvider.php

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
<?php
/**
* ServiceProvider.php.
*
* This file is part of the wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <elim051@163.com>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}.
*/
public function register(Container $app)
{
$app['free_publish'] = function ($app) {
return new Client($app);
};
}
}

991
src/OfficialAccount/Guide/Client.php

@ -0,0 +1,991 @@ @@ -0,0 +1,991 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <millsguo@gmail.com>
*/
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);
}
}

33
src/OfficialAccount/Guide/ServiceProvider.php

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <millsguo@gmail.com>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}.
*/
public function register(Container $app)
{
$app['guide'] = function ($app) {
return new Client($app);
};
}
}

17
src/OfficialAccount/OAuth/ServiceProvider.php

@ -28,15 +28,24 @@ class ServiceProvider implements ServiceProviderInterface @@ -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 @@ -61,6 +70,6 @@ class ServiceProvider implements ServiceProviderInterface
}
$baseUrl = $app['request']->getSchemeAndHttpHost();
return $baseUrl.'/'.ltrim($callback, '/');
return $baseUrl . '/' . ltrim($callback, '/');
}
}

75
src/OfficialAccount/OCR/Client.php

@ -38,7 +38,6 @@ class Client extends BaseClient @@ -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 @@ -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 @@ -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 @@ -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,
]);
}

2
src/OfficialAccount/Server/Handlers/EchoStrHandler.php

@ -47,5 +47,7 @@ class EchoStrHandler implements EventHandlerInterface @@ -47,5 +47,7 @@ class EchoStrHandler implements EventHandlerInterface
if ($str = $this->app['request']->get('echostr')) {
return new FinallyResult($str);
}
return null;
}
}

1
src/OfficialAccount/ShakeAround/ShakeAround.php

@ -23,6 +23,7 @@ use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; @@ -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
{

2
src/OfficialAccount/Store/Client.php

@ -75,7 +75,7 @@ class Client extends BaseClient @@ -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');
}
/**

189
src/OfficialAccount/SubscribeMessage/Client.php

@ -0,0 +1,189 @@ @@ -0,0 +1,189 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <teg1c@foxmail.com>
*/
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'];
}
}

27
src/OfficialAccount/SubscribeMessage/ServiceProvider.php

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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);
};
}
}

4
src/OfficialAccount/TemplateMessage/Client.php

@ -22,7 +22,7 @@ use ReflectionClass; @@ -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 @@ -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;

169
src/OpenPlatform/Application.php

@ -1,29 +1,20 @@ @@ -1,29 +1,20 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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
*/

21
src/OpenPlatform/Authorizer/MiniProgram/Account/Client.php

@ -32,10 +32,10 @@ class Client extends BaseClient @@ -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 @@ -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);

14
src/OpenPlatform/Authorizer/MiniProgram/Application.php

@ -19,11 +19,12 @@ use EasyWeChat\OpenPlatform\Authorizer\Aggregate\AggregateServiceProvider; @@ -19,11 +19,12 @@ use EasyWeChat\OpenPlatform\Authorizer\Aggregate\AggregateServiceProvider;
*
* @author mingyoung <mingyoungcheung@gmail.com>
*
* @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 @@ -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) {

10
src/OpenPlatform/Authorizer/MiniProgram/Code/Client.php

@ -77,7 +77,7 @@ class Client extends BaseClient @@ -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 @@ -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,
]);

51
src/OpenPlatform/Authorizer/MiniProgram/Material/Client.php

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <i@overtrue.me>
*/
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'));
}
}

44
src/OpenPlatform/Authorizer/MiniProgram/Material/ServiceProvider.php

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <i@overtrue.me>
*
* 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 <i@overtrue.me>
*/
class ServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}.
*/
public function register(Container $app)
{
$app['material'] = function ($app) {
return new Client($app);
};
}
}

66
src/OpenPlatform/Authorizer/MiniProgram/Privacy/Client.php

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <lujunyi@shopex.cn>
*/
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]);
}
}

25
src/OpenPlatform/Authorizer/MiniProgram/Privacy/ServiceProvider.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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);
};
}
}

45
src/OpenPlatform/Authorizer/MiniProgram/Security/Client.php

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* 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 <lujunyi@shopex.cn>
*/
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);
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save