fix:更新已知bug,优化代码

This commit is contained in:
Ying
2022-11-28 19:11:12 +08:00
parent f6aee95cfc
commit 9445b206a2
1378 changed files with 53759 additions and 20789 deletions

View File

@@ -1,22 +1,29 @@
<img align="right" width="100" src="https://user-images.githubusercontent.com/1472352/49656357-1e874080-fa78-11e8-80ea-69e2103345cf.png" alt="EasyWeChat Logo"/>
<h1 align="left"><a href="https://www.easywechat.com">EasyWeChat</a></h1>
📦 It is probably the best SDK in the world for developing Wechat App.
📦 一个 PHP 微信开发 SDK。
[![Test Status](https://github.com/overtrue/wechat/workflows/Test/badge.svg)](https://github.com/overtrue/wechat/actions)
[![Lint Status](https://github.com/overtrue/wechat/workflows/Lint/badge.svg)](https://github.com/overtrue/wechat/actions)
[![Latest Stable Version](https://poser.pugx.org/overtrue/wechat/v/stable.svg)](https://packagist.org/packages/overtrue/wechat)
[![Latest Unstable Version](https://poser.pugx.org/overtrue/wechat/v/unstable.svg)](https://packagist.org/packages/overtrue/wechat)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/overtrue/wechat/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/overtrue/wechat/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/overtrue/wechat/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/overtrue/wechat/?branch=master)
[![Total Downloads](https://poser.pugx.org/overtrue/wechat/downloads)](https://packagist.org/packages/overtrue/wechat)
[![License](https://poser.pugx.org/overtrue/wechat/license)](https://packagist.org/packages/overtrue/wechat)
[![Test Status](https://github.com/w7corp/easywechat/workflows/Test/badge.svg)](https://github.com/w7corp/easywechat/actions)
[![Lint Status](https://github.com/w7corp/easywechat/workflows/Lint/badge.svg)](https://github.com/w7corp/easywechat/actions)
[![Latest Stable Version](https://poser.pugx.org/w7corp/easywechat/v/stable.svg)](https://packagist.org/packages/w7corp/easywechat)
[![Latest Unstable Version](https://poser.pugx.org/w7corp/easywechat/v/unstable.svg)](https://packagist.org/packages/w7corp/easywechat)
[![Total Downloads](https://poser.pugx.org/w7corp/easywechat/downloads)](https://packagist.org/packages/w7corp/easywechat)
[![License](https://poser.pugx.org/w7corp/easywechat/license)](https://packagist.org/packages/w7corp/easywechat)
[![huntr](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev)
> 📣 **公告**
>
> 为了更好的推进项目发展保障项目更新迭代速度EasyWeChat 正式并入微擎旗下,加上微擎团队的助力,将会为大家提供更强大更稳固更多元化的开源项目。
>
> - 微擎与 EasyWeChat 结合,基于微擎技术资源方面的优势,将积极发展 EasyWeChat 的开源社区,将为 EasyWeChat 开源项目注入巨大活力。
> - EasyWeChat 原作者 overtrue 将继续担任开源项目的核心开发者,继续参与项目的发展规划,共同打造更强大的开源生态社区。
> - 项目从 6.0 版本开始将修改包名为 `w7corp/easywechat`5.x 及以下版本不受影响。
> 🚨 注意:请 PR 时往 5.x 提交,感谢您的贡献!
## Requirement
1. PHP >= 7.2
1. PHP >= 7.4
2. **[Composer](https://getcomposer.org/)**
3. openssl 拓展
4. fileinfo 拓展(素材管理模块需要用到)
@@ -24,7 +31,7 @@
## Installation
```shell
$ composer require "overtrue/wechat:^4.2" -vvv
$ composer require "overtrue/wechat:^5.0" -vvv
```
## Usage
@@ -65,7 +72,7 @@ $server->serve()->send();
## Documentation
[官网](https://www.easywechat.com) · [教程](https://www.easywechat.com/tutorials) · [讨论](https://yike.io/) · [微信公众平台](https://mp.weixin.qq.com/wiki) · [WeChat Official](http://admin.wechat.com/wiki)
[官网](https://www.easywechat.com) · [教程](https://www.aliyundrive.com/s/6CwgtkiBqFV) · [讨论](https://github.com/w7corp/easywechat/discussions) · [微信公众平台](https://mp.weixin.qq.com/wiki) · [WeChat Official](http://admin.wechat.com/wiki)
## Integration

21
vendor/overtrue/wechat/SECURITY.md vendored Normal file
View File

@@ -0,0 +1,21 @@
# 更新策略
从最初的稳定版本开始EasyWeChat 的每个发行分支都会得到两年的全面支持。在这期间,被报告的错误和安全问题会被修复并发布。
在这两年的积极支持期之后,每个分支再被支持一年,只针对关键安全问题。在此期间的发布是根据需要进行的:根据报告的数量,可能有多个版本发布,也可能没有。
## 当前支持版本情况
| 版本 | 发布日期 | 积极维护更新 | 安全性修复 |
| ------- | ---------------- | -------------------- | ------------------------- |
| 6.x | 2022.02.02 | 2024.02.02 | 2025.02.02 |
| 5.x | 2020.07.27 | 2022.07.27 | 2023.07.27 |
| 4.x | 2017.12.12 | 2019.12.12 | 2020.12.12 |
| 3.x | 2016.02.19 | 2018.02.19 | 2019.02.19 |
| 2.x | 2015.05.06 | 2017.05.06 | 2018.05.06 |
| 1.x | 2015.02.13 | 2017.02.13 | 2017.02.13 |
## 报告安全问题
如果您发现 EasyWeChat 有安全漏洞,请发送电子邮件至 anzhengchao@gmail.com。所有的安全漏洞都会得到及时的解决。

View File

@@ -16,27 +16,30 @@
}
],
"require": {
"php": ">=7.2",
"php": ">=7.4",
"ext-fileinfo": "*",
"ext-openssl": "*",
"ext-simplexml": "*",
"easywechat-composer/easywechat-composer": "^1.1",
"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",
"symfony/psr-http-message-bridge": "^0.3 || ^1.0 || ^2.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",
"ext-libxml": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.15",
"friendsofphp/php-cs-fixer": "^3.5.0",
"brainmaestro/composer-git-hooks": "^2.7",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.2.3",
"phpstan/phpstan": "^0.12.0",
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": "^9.3",
"dms/phpunit-arraysubset-asserts": "^0.2.0"
},
"autoload": {
"psr-4": {
@@ -52,11 +55,35 @@
"EasyWeChat\\Tests\\": "tests/"
}
},
"extra": {
"hooks": {
"pre-commit": [
"composer test",
"composer fix-style"
],
"pre-push": [
"composer test",
"composer fix-style"
]
}
},
"scripts": {
"phpcs": "vendor/bin/php-cs-fixer fix",
"post-update-cmd": [
"cghooks update"
],
"post-merge": "composer install",
"post-install-cmd": [
"cghooks add --ignore-lock",
"cghooks update"
],
"phpstan": "vendor/bin/phpstan analyse",
"check-style": "php-cs-fixer fix --using-cache=no --diff --config=.php_cs --dry-run --ansi",
"fix-style": "php-cs-fixer fix --using-cache=no --config=.php_cs --ansi",
"test": "vendor/bin/phpunit --colors=always"
"check-style": "vendor/bin/php-cs-fixer fix --using-cache=no --diff --config=.php-cs-fixer.dist.php --dry-run --ansi",
"fix-style": "vendor/bin/php-cs-fixer fix --using-cache=no --config=.php-cs-fixer.dist.php --ansi",
"test": "vendor/bin/phpunit --colors=always --testdox"
},
"config": {
"allow-plugins": {
"easywechat-composer/easywechat-composer": true
}
}
}

View File

@@ -24,23 +24,25 @@ class Client extends BaseClient
/**
* 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('/wxa/msg_sec_check', $params);
return $this->httpPostJson('wxa/msg_sec_check', $params);
}
/**
* Image security check.
*
* @param string $path
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -48,12 +50,15 @@ class Client extends BaseClient
*/
public function checkImage(string $path)
{
return $this->httpUpload('/wxa/img_sec_check', ['media' => $path]);
return $this->httpUpload('wxa/img_sec_check', ['media' => $path]);
}
/**
* Media security check.
*
* @param string $mediaUrl
* @param int $mediaType
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -76,12 +81,14 @@ class Client extends BaseClient
'media_type' => $mediaType,
];
return $this->httpPostJson('/wxa/media_check_async', $params);
return $this->httpPostJson('wxa/media_check_async', $params);
}
/**
* Image security check async.
*
* @param string $mediaUrl
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -95,6 +102,8 @@ class Client extends BaseClient
/**
* Audio security check async.
*
* @param string $mediaUrl
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

@@ -28,7 +28,7 @@ class Client extends BaseClient
/**
* @var string
*/
protected $ticketEndpoint = '/cgi-bin/ticket/getticket';
protected $ticketEndpoint = 'cgi-bin/ticket/getticket';
/**
* Current URI.
@@ -40,19 +40,20 @@ class Client extends BaseClient
/**
* Get config json for jsapi.
*
* @param array $jsApiList
* @param bool $debug
* @param bool $beta
* @param bool $json
* @param array $openTagList
* @param string $url
* @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, array $openTagList = [], string $url = null)
{
@@ -64,18 +65,18 @@ class Client extends BaseClient
/**
* Return jsapi config as a PHP array.
*
* @param array $apis
* @param bool $debug
* @param bool $beta
* @param array $openTagList
* @param string $url
*
* @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, array $openTagList = [], string $url = null)
{
@@ -85,6 +86,11 @@ class Client extends BaseClient
/**
* Get js ticket.
*
* @param bool $refresh
* @param string $type
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
@@ -117,11 +123,16 @@ class Client extends BaseClient
/**
* Build signature.
*
* @param int|null $timestamp
* @param string|null $url
* @param string|null $nonce
* @param null $timestamp
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
protected function configSignature(string $url = null, string $nonce = null, $timestamp = null): array
@@ -146,6 +157,8 @@ class Client extends BaseClient
* @param string $nonce
* @param int $timestamp
* @param string $url
*
* @return string
*/
public function getTicketSignature($ticket, $nonce, $timestamp, $url): string
{
@@ -167,6 +180,8 @@ class Client extends BaseClient
/**
* Set current url.
*
* @param string $url
*
* @return $this
*/
public function setUrl(string $url)
@@ -178,6 +193,8 @@ class Client extends BaseClient
/**
* Get current url.
*
* @return string
*/
public function getUrl(): string
{
@@ -195,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');
}
}

View File

@@ -92,6 +92,9 @@ class Client extends BaseClient
/**
* Upload temporary material.
*
* @param string $type
* @param string $path
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -108,10 +111,14 @@ class Client extends BaseClient
throw new InvalidArgumentException(sprintf("Unsupported media type: '%s'", $type));
}
return $this->httpUpload('/cgi-bin/media/upload', ['media' => $path], ['type' => $type]);
return $this->httpUpload('cgi-bin/media/upload', ['media' => $path], ['type' => $type]);
}
/**
* @param string $path
* @param string $title
* @param string $description
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -132,6 +139,10 @@ class Client extends BaseClient
}
/**
* @param string $mediaId
* @param string $title
* @param string $description
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -139,7 +150,7 @@ class Client extends BaseClient
*/
public function createVideoForBroadcasting(string $mediaId, string $title, string $description)
{
return $this->httpPostJson('/cgi-bin/media/uploadvideo', [
return $this->httpPostJson('cgi-bin/media/uploadvideo', [
'media_id' => $mediaId,
'title' => $title,
'description' => $description,
@@ -149,6 +160,8 @@ class Client extends BaseClient
/**
* Fetch item from WeChat server.
*
* @param string $mediaId
*
* @return \EasyWeChat\Kernel\Http\StreamResponse|\Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -156,7 +169,7 @@ class Client extends BaseClient
*/
public function get(string $mediaId)
{
$response = $this->requestRaw('/cgi-bin/media/get', 'GET', [
$response = $this->requestRaw('cgi-bin/media/get', 'GET', [
'query' => [
'media_id' => $mediaId,
],
@@ -170,6 +183,8 @@ class Client extends BaseClient
}
/**
* @param string $mediaId
*
* @return array|\EasyWeChat\Kernel\Http\Response|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -177,7 +192,7 @@ class Client extends BaseClient
*/
public function getJssdkMedia(string $mediaId)
{
$response = $this->requestRaw('/cgi-bin/media/get/jssdk', 'GET', [
$response = $this->requestRaw('cgi-bin/media/get/jssdk', 'GET', [
'query' => [
'media_id' => $mediaId,
],

View File

@@ -110,6 +110,6 @@ class Client extends BaseClient
$params['expire_seconds'] = min($expireSeconds, 30 * self::DAY);
}
return $this->httpPostJson('/cgi-bin/qrcode/create', $params);
return $this->httpPostJson('cgi-bin/qrcode/create', $params);
}
}

View File

@@ -23,6 +23,8 @@ class Client extends BaseClient
/**
* Shorten the url.
*
* @param string $url
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

@@ -27,6 +27,7 @@ class Factory
{
/**
* @param string $name
* @param array $config
*
* @return \EasyWeChat\Kernel\ServiceContainer
*/

View File

@@ -81,6 +81,8 @@ abstract class AccessToken implements AccessTokenInterface
}
/**
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\HttpException
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -93,6 +95,10 @@ abstract class AccessToken implements AccessTokenInterface
}
/**
* @param bool $refresh
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\HttpException
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -121,6 +127,11 @@ abstract class AccessToken implements AccessTokenInterface
}
/**
* @param string $token
* @param int $lifetime
*
* @return \EasyWeChat\Kernel\Contracts\AccessTokenInterface
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
* @throws \Psr\SimpleCache\InvalidArgumentException
@@ -140,6 +151,8 @@ abstract class AccessToken implements AccessTokenInterface
}
/**
* @return \EasyWeChat\Kernel\Contracts\AccessTokenInterface
*
* @throws \EasyWeChat\Kernel\Exceptions\HttpException
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -154,7 +167,8 @@ abstract class AccessToken implements AccessTokenInterface
}
/**
* @param bool $toArray
* @param array $credentials
* @param bool $toArray
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
@@ -176,6 +190,11 @@ abstract class AccessToken implements AccessTokenInterface
}
/**
* @param \Psr\Http\Message\RequestInterface $request
* @param array $requestOptions
*
* @return \Psr\Http\Message\RequestInterface
*
* @throws \EasyWeChat\Kernel\Exceptions\HttpException
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -194,6 +213,10 @@ abstract class AccessToken implements AccessTokenInterface
/**
* Send http request.
*
* @param array $credentials
*
* @return ResponseInterface
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
@@ -217,6 +240,8 @@ abstract class AccessToken implements AccessTokenInterface
/**
* The request query will be used to add to the request.
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\HttpException
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -229,6 +254,8 @@ abstract class AccessToken implements AccessTokenInterface
}
/**
* @return string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public function getEndpoint(): string
@@ -250,6 +277,8 @@ abstract class AccessToken implements AccessTokenInterface
/**
* Credential for get token.
*
* @return array
*/
abstract protected function getCredentials(): array;
}

View File

@@ -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
*/
@@ -47,7 +47,8 @@ class BaseClient
/**
* BaseClient constructor.
*
* @param \EasyWeChat\Kernel\ServiceContainer $app
* @param \EasyWeChat\Kernel\ServiceContainer $app
* @param \EasyWeChat\Kernel\Contracts\AccessTokenInterface|null $accessToken
*/
public function __construct(ServiceContainer $app, AccessTokenInterface $accessToken = null)
{
@@ -58,6 +59,9 @@ class BaseClient
/**
* GET request.
*
* @param string $url
* @param array $query
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -71,6 +75,9 @@ class BaseClient
/**
* POST request.
*
* @param string $url
* @param array $data
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -84,6 +91,10 @@ class BaseClient
/**
* JSON request.
*
* @param string $url
* @param array $data
* @param array $query
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -97,6 +108,11 @@ class BaseClient
/**
* Upload file.
*
* @param string $url
* @param array $files
* @param array $form
* @param array $query
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -105,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
];
}
@@ -117,15 +141,24 @@ 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]
);
}
/**
* @return AccessTokenInterface
*/
public function getAccessToken(): AccessTokenInterface
{
return $this->accessToken;
}
/**
* @param \EasyWeChat\Kernel\Contracts\AccessTokenInterface $accessToken
*
* @return $this
*/
public function setAccessToken(AccessTokenInterface $accessToken)
@@ -136,7 +169,10 @@ class BaseClient
}
/**
* @param bool $returnRaw
* @param string $url
* @param string $method
* @param array $options
* @param bool $returnRaw
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
@@ -157,6 +193,10 @@ class BaseClient
}
/**
* @param string $url
* @param string $method
* @param array $options
*
* @return \EasyWeChat\Kernel\Http\Response
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -217,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);
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.');
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 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));
}
);
}
}

View File

@@ -56,6 +56,7 @@ class Clause
{
foreach ($this->clauses['where'] as $item) {
list($key, $value) = $item;
if (!isset($payload[$key])) {
continue;
}
@@ -68,6 +69,7 @@ class Clause
return true;
}
}
return false;
}
}

View File

@@ -20,6 +20,9 @@ use Psr\Http\Message\RequestInterface;
*/
interface AccessTokenInterface
{
/**
* @return array
*/
public function getToken(): array;
/**
@@ -27,5 +30,11 @@ interface AccessTokenInterface
*/
public function refresh(): self;
/**
* @param \Psr\Http\Message\RequestInterface $request
* @param array $requestOptions
*
* @return \Psr\Http\Message\RequestInterface
*/
public function applyToRequest(RequestInterface $request, array $requestOptions = []): RequestInterface;
}

View File

@@ -18,5 +18,8 @@ namespace EasyWeChat\Kernel\Contracts;
*/
interface MediaInterface extends MessageInterface
{
/**
* @return string
*/
public function getMediaId(): string;
}

View File

@@ -18,9 +18,18 @@ namespace EasyWeChat\Kernel\Contracts;
*/
interface MessageInterface
{
/**
* @return string
*/
public function getType(): string;
/**
* @return array
*/
public function transformForJsonRequest(): array;
/**
* @return string
*/
public function transformToXml(): string;
}

View File

@@ -65,6 +65,10 @@ class Encryptor
/**
* Constructor.
*
* @param string $appId
* @param string|null $token
* @param string|null $aesKey
*/
public function __construct(string $appId, string $token = null, string $aesKey = null)
{
@@ -75,6 +79,8 @@ class Encryptor
/**
* Get the app token.
*
* @return string
*/
public function getToken(): string
{
@@ -88,6 +94,8 @@ class Encryptor
* @param string $nonce
* @param int $timestamp
*
* @return string
*
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
*/
public function encrypt($xml, $nonce = null, $timestamp = null): string
@@ -99,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) {
@@ -129,6 +137,8 @@ class Encryptor
* @param string $nonce
* @param string $timestamp
*
* @return string
*
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
*/
public function decrypt($content, $msgSignature, $nonce, $timestamp): string
@@ -143,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));
@@ -158,6 +168,8 @@ class Encryptor
/**
* Get SHA1.
*
* @return string
*/
public function signature(): string
{
@@ -170,6 +182,11 @@ class Encryptor
/**
* PKCS#7 pad.
*
* @param string $text
* @param int $blockSize
*
* @return string
*
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
*/
public function pkcs7Pad(string $text, int $blockSize): string
@@ -185,6 +202,10 @@ class Encryptor
/**
* PKCS#7 unpad.
*
* @param string $text
*
* @return string
*/
public function pkcs7Unpad(string $text): string
{

View File

@@ -25,6 +25,9 @@ class AccessTokenRefreshed
*/
public $accessToken;
/**
* @param \EasyWeChat\Kernel\AccessToken $accessToken
*/
public function __construct(AccessToken $accessToken)
{
$this->accessToken = $accessToken;

View File

@@ -25,6 +25,9 @@ class ApplicationInitialized
*/
public $app;
/**
* @param \EasyWeChat\Kernel\ServiceContainer $app
*/
public function __construct(ServiceContainer $app)
{
$this->app = $app;

View File

@@ -25,6 +25,9 @@ class HttpResponseCreated
*/
public $response;
/**
* @param \Psr\Http\Message\ResponseInterface $response
*/
public function __construct(ResponseInterface $response)
{
$this->response = $response;

View File

@@ -25,6 +25,9 @@ class ServerGuardResponseCreated
*/
public $response;
/**
* @param \Symfony\Component\HttpFoundation\Response $response
*/
public function __construct(Response $response)
{
$this->response = $response;

View File

@@ -33,9 +33,10 @@ class HttpException extends Exception
/**
* HttpException constructor.
*
* @param string $message
* @param null $formattedResponse
* @param int|null $code
* @param string $message
* @param \Psr\Http\Message\ResponseInterface|null $response
* @param null $formattedResponse
* @param int|null $code
*/
public function __construct($message, ResponseInterface $response = null, $formattedResponse = null, $code = null)
{

View File

@@ -36,6 +36,8 @@ class Response extends GuzzleResponse
}
/**
* @param \Psr\Http\Message\ResponseInterface $response
*
* @return \EasyWeChat\Kernel\Http\Response
*/
public static function buildFromPsrResponse(ResponseInterface $response)
@@ -108,10 +110,12 @@ class Response extends GuzzleResponse
}
/**
* @param string $content
*
* @return string
*/
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'));
}
}

View File

@@ -23,6 +23,10 @@ use EasyWeChat\Kernel\Support\File;
class StreamResponse extends Response
{
/**
* @param string $directory
* @param string $filename
* @param bool $appendSuffix
*
* @return bool|int
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -66,6 +70,10 @@ class StreamResponse extends Response
}
/**
* @param string $directory
* @param string $filename
* @param bool $appendSuffix
*
* @return bool|int
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException

View File

@@ -17,7 +17,6 @@ use Monolog\Formatter\LineFormatter;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Handler\FormattableHandlerInterface;
use Monolog\Handler\HandlerInterface;
use Monolog\Handler\NullHandler;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\SlackWebhookHandler;
use Monolog\Handler\StreamHandler;
@@ -70,6 +69,8 @@ class LogManager implements LoggerInterface
/**
* LogManager constructor.
*
* @param \EasyWeChat\Kernel\ServiceContainer $app
*/
public function __construct(ServiceContainer $app)
{
@@ -79,8 +80,8 @@ class LogManager implements LoggerInterface
/**
* Create a new, on-demand aggregate logger instance.
*
* @param array $channels
* @param string|null $channel
* @param array $channels
* @param string|null $channel
*
* @return \Psr\Log\LoggerInterface
*
@@ -173,16 +174,6 @@ class LogManager implements LoggerInterface
throw new InvalidArgumentException(\sprintf('Driver [%s] is not supported.', $config['driver']));
}
/**
* Call a custom driver creator.
*
* @return mixed
*/
protected function callCustomCreator(array $config)
{
return $this->customCreators[$config['driver']]($this->app, $config);
}
/**
* Create an emergency log handler to avoid white screens of death.
*
@@ -198,9 +189,23 @@ class LogManager implements LoggerInterface
)]));
}
/**
* Call a custom driver creator.
*
* @param array $config
*
* @return mixed
*/
protected function callCustomCreator(array $config)
{
return $this->customCreators[$config['driver']]($this->app, $config);
}
/**
* Create an aggregate log driver instance.
*
* @param array $config
*
* @return \Monolog\Logger
*
* @throws \Exception
@@ -223,6 +228,8 @@ class LogManager implements LoggerInterface
/**
* Create an instance of the single file log driver.
*
* @param array $config
*
* @return \Psr\Log\LoggerInterface
*
* @throws \Exception
@@ -243,6 +250,8 @@ class LogManager implements LoggerInterface
/**
* Create an instance of the daily file log driver.
*
* @param array $config
*
* @return \Psr\Log\LoggerInterface
*/
protected function createDailyDriver(array $config)
@@ -262,7 +271,10 @@ class LogManager implements LoggerInterface
/**
* Create an instance of the Slack log driver.
*
* @param array $config
*
* @return \Psr\Log\LoggerInterface
* @throws \Monolog\Handler\MissingExtensionException
*/
protected function createSlackDriver(array $config)
{
@@ -285,6 +297,8 @@ class LogManager implements LoggerInterface
/**
* Create an instance of the syslog log driver.
*
* @param array $config
*
* @return \Psr\Log\LoggerInterface
*/
protected function createSyslogDriver(array $config)
@@ -301,6 +315,8 @@ class LogManager implements LoggerInterface
/**
* Create an instance of the "error log" log driver.
*
* @param array $config
*
* @return \Psr\Log\LoggerInterface
*/
protected function createErrorlogDriver(array $config)
@@ -315,17 +331,14 @@ class LogManager implements LoggerInterface
]);
}
protected function createNullDriver()
{
return new Monolog('EasyWeChat', [new NullHandler()]);
}
/**
* Prepare the handlers for usage by Monolog.
*
* @param array $handlers
*
* @return array
*/
protected function prepareHandlers(array $handlers)
protected function prepareHandlers(array $handlers): array
{
foreach ($handlers as $key => $handler) {
$handlers[$key] = $this->prepareHandler($handler);
@@ -337,6 +350,9 @@ class LogManager implements LoggerInterface
/**
* Prepare the handler for usage by Monolog.
*
* @param \Monolog\Handler\HandlerInterface $handler
* @param array $config
*
* @return \Monolog\Handler\HandlerInterface
*/
protected function prepareHandler(HandlerInterface $handler, array $config = [])
@@ -366,9 +382,11 @@ class LogManager implements LoggerInterface
/**
* Extract the log channel from the given configuration.
*
* @param array $config
*
* @return string
*/
protected function parseChannel(array $config)
protected function parseChannel(array $config): string
{
return $config['name'] ?? 'EasyWeChat';
}
@@ -376,11 +394,13 @@ class LogManager implements LoggerInterface
/**
* Parse the string level into a Monolog constant.
*
* @param array $config
*
* @return int
*
* @throws InvalidArgumentException
*/
protected function level(array $config)
protected function level(array $config): int
{
$level = $config['level'] ?? 'debug';
@@ -396,7 +416,7 @@ class LogManager implements LoggerInterface
*
* @return string
*/
public function getDefaultDriver()
public function getDefaultDriver(): ?string
{
return $this->app['config']['log.default'];
}
@@ -414,11 +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);
@@ -429,14 +450,15 @@ class LogManager implements LoggerInterface
* System is unusable.
*
* @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);
}
/**
@@ -446,14 +468,15 @@ class LogManager implements LoggerInterface
* trigger the SMS alerts and wake you up.
*
* @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);
}
/**
@@ -462,14 +485,13 @@ class LogManager implements LoggerInterface
* Example: Application component unavailable, unexpected exception.
*
* @param string $message
*
* @return mixed
* @param array $context
*
* @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);
}
/**
@@ -477,14 +499,13 @@ class LogManager implements LoggerInterface
* be logged and monitored.
*
* @param string $message
*
* @return mixed
* @param array $context
*
* @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);
}
/**
@@ -494,28 +515,26 @@ class LogManager implements LoggerInterface
* that are not necessarily wrong.
*
* @param string $message
*
* @return mixed
* @param array $context
*
* @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);
}
/**
* Normal but significant events.
*
* @param string $message
*
* @return mixed
* @param array $context
*
* @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);
}
/**
@@ -524,28 +543,26 @@ class LogManager implements LoggerInterface
* Example: User logs in, SQL logs.
*
* @param string $message
*
* @return mixed
* @param array $context
*
* @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);
}
/**
* Detailed debug information.
*
* @param string $message
*
* @return mixed
* @param array $context
*
* @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);
}
/**
@@ -553,14 +570,13 @@ class LogManager implements LoggerInterface
*
* @param mixed $level
* @param string $message
*
* @return mixed
* @param array $context
*
* @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);
}
/**
@@ -569,8 +585,6 @@ class LogManager implements LoggerInterface
* @param string $method
* @param array $parameters
*
* @return mixed
*
* @throws \Exception
*/
public function __call($method, $parameters)

View File

@@ -42,6 +42,8 @@ class Card extends Message
/**
* Media constructor.
*
* @param string $cardId
*/
public function __construct(string $cardId)
{

View File

@@ -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',
];
}

View File

@@ -36,7 +36,9 @@ class Media extends Message implements MediaInterface
/**
* MaterialClient constructor.
*
* @param string $mediaId
* @param string $type
* @param array $attributes
*/
public function __construct(string $mediaId, $type = null, array $attributes = [])
{
@@ -46,6 +48,8 @@ class Media extends Message implements MediaInterface
}
/**
* @return string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public function getMediaId(): string

View File

@@ -74,6 +74,8 @@ abstract class Message implements MessageInterface
/**
* Message constructor.
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
@@ -82,12 +84,17 @@ abstract class Message implements MessageInterface
/**
* Return type name message.
*
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
@@ -129,6 +136,8 @@ abstract class Message implements MessageInterface
}
/**
* @param array $appends
*
* @return array
*/
public function transformForJsonRequestWithoutType(array $appends = [])
@@ -137,7 +146,10 @@ abstract class Message implements MessageInterface
}
/**
* @param bool $withType
* @param array $appends
* @param bool $withType
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
@@ -154,6 +166,12 @@ abstract class Message implements MessageInterface
return $data;
}
/**
* @param array $appends
* @param bool $returnAsArray
*
* @return string
*/
public function transformToXml(array $appends = [], bool $returnAsArray = false): string
{
$data = array_merge(['MsgType' => $this->getType()], $this->toXmlArray(), $appends);
@@ -162,6 +180,11 @@ abstract class Message implements MessageInterface
}
/**
* @param array $data
* @param array $aliases
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
protected function propertiesToArray(array $data, array $aliases = []): array

View File

@@ -1,14 +1,5 @@
<?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 MiniprogramNotice extends Message

View File

@@ -32,12 +32,20 @@ class News extends Message
/**
* News constructor.
*
* @param array $items
*/
public function __construct(array $items = [])
{
parent::__construct(compact('items'));
}
/**
* @param array $data
* @param array $aliases
*
* @return array
*/
public function propertiesToArray(array $data, array $aliases = []): array
{
return ['articles' => array_map(function ($item) {

View File

@@ -30,6 +30,8 @@ class Raw extends Message
/**
* Constructor.
*
* @param string $content
*/
public function __construct(string $content)
{
@@ -37,7 +39,10 @@ class Raw extends Message
}
/**
* @param bool $withType
* @param array $appends
* @param bool $withType
*
* @return array
*/
public function transformForJsonRequest(array $appends = [], $withType = true): array
{

View File

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

View File

@@ -34,8 +34,10 @@ class Text extends Message
/**
* Text constructor.
*
* @param string $content
*/
public function __construct(string $content)
public function __construct(string $content = '')
{
parent::__construct(compact('content'));
}

View File

@@ -37,6 +37,8 @@ class Transfer extends Message
/**
* Transfer constructor.
*
* @param string|null $account
*/
public function __construct(string $account = null)
{

View File

@@ -43,6 +43,9 @@ class Video extends Media
/**
* Video constructor.
*
* @param string $mediaId
* @param array $attributes
*/
public function __construct(string $mediaId, array $attributes = [])
{

View File

@@ -33,7 +33,7 @@ class LogServiceProvider implements ServiceProviderInterface
public function register(Container $pimple)
{
!isset($pimple['log']) && $pimple['log'] = function ($app) {
$config = $this->formatLogConfig($app);
$config = $app['config']->get('log');
if (!empty($config)) {
$app->rebind('config', $app['config']->merge($config));
@@ -44,37 +44,4 @@ class LogServiceProvider implements ServiceProviderInterface
!isset($pimple['logger']) && $pimple['logger'] = $pimple['log'];
}
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' => 'null',
'channels' => [
'null' => [
'driver' => 'null',
],
],
],
];
}
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'),
],
],
],
];
}
}

View File

@@ -89,6 +89,8 @@ class ServerGuard
/**
* Handle and return response.
*
* @return Response
*
* @throws BadRequestException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -179,6 +181,8 @@ class ServerGuard
/**
* Resolve server request and return the response.
*
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \EasyWeChat\Kernel\Exceptions\BadRequestException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -211,6 +215,8 @@ class ServerGuard
}
/**
* @param string $to
* @param string $from
* @param \EasyWeChat\Kernel\Contracts\MessageInterface|string|int $message
*
* @return string
@@ -245,6 +251,8 @@ class ServerGuard
/**
* Handle request.
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\BadRequestException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -266,6 +274,12 @@ class ServerGuard
/**
* Build reply XML.
*
* @param string $to
* @param string $from
* @param \EasyWeChat\Kernel\Contracts\MessageInterface $message
*
* @return string
*/
protected function buildReply(string $to, string $from, MessageInterface $message): string
{
@@ -287,6 +301,8 @@ class ServerGuard
}
/**
* @param array $params
*
* @return string
*/
protected function signature(array $params)
@@ -326,18 +342,25 @@ class ServerGuard
/**
* Check the request message safe mode.
*
* @return bool
*/
protected function isSafeMode(): bool
{
return $this->app['request']->get('signature') && 'aes' === $this->app['request']->get('encrypt_type');
}
/**
* @return bool
*/
protected function shouldReturnRawResponse(): bool
{
return false;
}
/**
* @param array $message
*
* @return mixed
*/
protected function decryptMessage(array $message)

View File

@@ -57,6 +57,10 @@ class ServiceContainer extends Container
/**
* Constructor.
*
* @param array $config
* @param array $prepends
* @param string|null $id
*/
public function __construct(array $config = [], array $prepends = [], string $id = null)
{
@@ -64,10 +68,10 @@ class ServiceContainer extends Container
parent::__construct($prepends);
$this->id = $id;
$this->registerProviders($this->getProviders());
$this->id = $id;
$this->aggregate();
$this->events->dispatch(new Events\ApplicationInitialized($this));
@@ -151,6 +155,9 @@ class ServiceContainer extends Container
$this->offsetSet($id, $value);
}
/**
* @param array $providers
*/
public function registerProviders(array $providers)
{
foreach ($providers as $provider) {

View File

@@ -18,6 +18,14 @@ namespace EasyWeChat\Kernel\Support;
*/
class AES
{
/**
* @param string $text
* @param string $key
* @param string $iv
* @param int $option
*
* @return string
*/
public static function encrypt(string $text, string $key, string $iv, int $option = OPENSSL_RAW_DATA): string
{
self::validateKey($key);
@@ -27,7 +35,13 @@ class AES
}
/**
* @param string $cipherText
* @param string $key
* @param string $iv
* @param int $option
* @param string|null $method
*
* @return string
*/
public static function decrypt(string $cipherText, string $key, string $iv, int $option = OPENSSL_RAW_DATA, $method = null): string
{
@@ -47,6 +61,9 @@ class AES
return 'aes-'.(8 * strlen($key)).'-cbc';
}
/**
* @param string $key
*/
public static function validateKey(string $key)
{
if (!in_array(strlen($key), [16, 24, 32], true)) {
@@ -55,6 +72,8 @@ class AES
}
/**
* @param string $iv
*
* @throws \InvalidArgumentException
*/
public static function validateIv(string $iv)

View File

@@ -19,6 +19,7 @@ class Arr
/**
* Add an element to an array using "dot" notation if it doesn't exist.
*
* @param array $array
* @param string $key
* @param mixed $value
*
@@ -64,6 +65,8 @@ class Arr
/**
* Divide an array into two arrays. One with keys and the other with values.
*
* @param array $array
*
* @return array
*/
public static function divide(array $array)
@@ -74,6 +77,7 @@ class Arr
/**
* Flatten a multi-dimensional associative array with dots.
*
* @param array $array
* @param string $prepend
*
* @return array
@@ -96,6 +100,7 @@ class Arr
/**
* Get all of the given array except for a specified array of items.
*
* @param array $array
* @param array|string $keys
*
* @return array
@@ -110,6 +115,7 @@ class Arr
/**
* Determine if the given key exists in the provided array.
*
* @param array $array
* @param string|int $key
*
* @return bool
@@ -122,7 +128,9 @@ class Arr
/**
* Return the first element in an array passing a given truth test.
*
* @param mixed $default
* @param array $array
* @param callable|null $callback
* @param mixed $default
*
* @return mixed
*/
@@ -150,7 +158,9 @@ class Arr
/**
* Return the last element in an array passing a given truth test.
*
* @param mixed $default
* @param array $array
* @param callable|null $callback
* @param mixed $default
*
* @return mixed
*/
@@ -166,11 +176,12 @@ class Arr
/**
* Flatten a multi-dimensional array into a single level.
*
* @param int $depth
* @param array $array
* @param int $depth
*
* @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;
@@ -188,6 +199,7 @@ class Arr
/**
* Remove one or many array items from a given array using "dot" notation.
*
* @param array $array
* @param array|string $keys
*/
public static function forget(array &$array, $keys)
@@ -230,6 +242,7 @@ class Arr
/**
* Get an item from an array using "dot" notation.
*
* @param array $array
* @param string $key
* @param mixed $default
*
@@ -259,6 +272,7 @@ class Arr
/**
* Check if an item or items exist in an array using "dot" notation.
*
* @param array $array
* @param string|array $keys
*
* @return bool
@@ -303,6 +317,8 @@ class Arr
*
* An array is "associative" if it doesn't have sequential numerical keys beginning with zero.
*
* @param array $array
*
* @return bool
*/
public static function isAssoc(array $array)
@@ -315,6 +331,7 @@ class Arr
/**
* Get a subset of the items from the given array.
*
* @param array $array
* @param array|string $keys
*
* @return array
@@ -327,6 +344,7 @@ class Arr
/**
* Push an item onto the beginning of an array.
*
* @param array $array
* @param mixed $value
* @param mixed $key
*
@@ -346,6 +364,7 @@ class Arr
/**
* Get a value from the array, and remove it.
*
* @param array $array
* @param string $key
* @param mixed $default
*
@@ -363,6 +382,9 @@ class Arr
/**
* Get a 1 value from an array.
*
* @param array $array
* @param int|null $amount
*
* @return mixed
*
* @throws \InvalidArgumentException
@@ -389,7 +411,9 @@ class Arr
*
* If no key is given to the method, the entire array will be replaced.
*
* @param mixed $value
* @param array $array
* @param string $key
* @param mixed $value
*
* @return array
*/
@@ -418,6 +442,9 @@ class Arr
/**
* Filter the array using the given callback.
*
* @param array $array
* @param callable $callback
*
* @return array
*/
public static function where(array $array, callable $callback)

View File

@@ -33,6 +33,8 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
/**
* set data.
*
* @param array $items
*/
public function __construct(array $items = [])
{
@@ -54,6 +56,8 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
/**
* Return specific items.
*
* @param array $keys
*
* @return \EasyWeChat\Kernel\Support\Collection
*/
public function only(array $keys)
@@ -225,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.
@@ -252,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);
@@ -268,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.
@@ -338,6 +355,8 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
/**
* var_export.
*
* @param array $properties
*
* @return array
*/
public static function __set_state(array $properties)
@@ -358,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);
@@ -373,6 +393,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
* The offset to unset.
* </p>
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
if ($this->offsetExists($offset)) {
@@ -392,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;
@@ -410,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);

View File

@@ -20,6 +20,7 @@ namespace EasyWeChat\Kernel\Support;
/**
* Generate a signature.
*
* @param array $attributes
* @param string $key
* @param string $encryptMethod
*
@@ -35,6 +36,9 @@ function generate_sign(array $attributes, $key, $encryptMethod = 'md5')
}
/**
* @param string $signType
* @param string $secretKey
*
* @return \Closure|string
*/
function get_encrypt_method(string $signType, string $secretKey = '')

View File

@@ -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;
}
@@ -88,6 +88,7 @@ class XML
/**
* Object to array.
*
*
* @param SimpleXMLElement $obj
*
* @return array

View File

@@ -33,6 +33,8 @@ trait HasAttributes
/**
* Set Attributes.
*
* @param array $attributes
*
* @return $this
*/
public function setAttributes(array $attributes = [])
@@ -134,6 +136,8 @@ trait HasAttributes
}
/**
* @param string $key
*
* @return bool
*/
public function has(string $key)
@@ -142,6 +146,8 @@ trait HasAttributes
}
/**
* @param array $attributes
*
* @return $this
*/
public function merge(array $attributes)

View File

@@ -61,6 +61,8 @@ trait HasHttpRequests
/**
* Return current guzzle default settings.
*
* @return array
*/
public static function getDefaultOptions(): array
{
@@ -70,6 +72,8 @@ trait HasHttpRequests
/**
* Set GuzzleHttp\Client.
*
* @param \GuzzleHttp\ClientInterface $httpClient
*
* @return $this
*/
public function setHttpClient(ClientInterface $httpClient)
@@ -81,6 +85,8 @@ trait HasHttpRequests
/**
* Return GuzzleHttp\ClientInterface instance.
*
* @return ClientInterface
*/
public function getHttpClient(): ClientInterface
{
@@ -98,7 +104,8 @@ trait HasHttpRequests
/**
* Add a middleware.
*
* @param string $name
* @param callable $middleware
* @param string $name
*
* @return $this
*/
@@ -115,6 +122,8 @@ trait HasHttpRequests
/**
* Return all middlewares.
*
* @return array
*/
public function getMiddlewares(): array
{
@@ -128,6 +137,8 @@ trait HasHttpRequests
* @param string $method
* @param array $options
*
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function request($url, $method = 'GET', $options = []): ResponseInterface
@@ -149,6 +160,8 @@ trait HasHttpRequests
}
/**
* @param \GuzzleHttp\HandlerStack $handlerStack
*
* @return $this
*/
public function setHandlerStack(HandlerStack $handlerStack)
@@ -160,6 +173,8 @@ trait HasHttpRequests
/**
* Build a handler stack.
*
* @return \GuzzleHttp\HandlerStack
*/
public function getHandlerStack(): HandlerStack
{
@@ -176,6 +191,11 @@ trait HasHttpRequests
return $this->handlerStack;
}
/**
* @param array $options
*
* @return array
*/
protected function fixJsonIssue(array $options): array
{
if (isset($options['json']) && is_array($options['json'])) {

View File

@@ -95,6 +95,9 @@ trait InteractsWithCache
return new FilesystemCache();
}
/**
* @return bool
*/
protected function isSymfony43OrHigher(): bool
{
return \class_exists('Symfony\Component\Cache\Psr16Cache');

View File

@@ -58,6 +58,8 @@ trait Observable
}
/**
* @param array $handlers
*
* @return $this
*/
public function setHandlers(array $handlers = [])
@@ -155,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;
}
@@ -176,6 +178,8 @@ trait Observable
/**
* @param mixed $handler
*
* @return \EasyWeChat\Kernel\Clauses\Clause
*/
protected function newClause($handler): Clause
{
@@ -203,7 +207,8 @@ trait Observable
}
/**
* @param mixed $payload
* @param callable $handler
* @param mixed $payload
*
* @return mixed
*/
@@ -264,6 +269,8 @@ trait Observable
* @param mixed $handler
* @param mixed $condition
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \ReflectionException
*/

View File

@@ -26,7 +26,8 @@ use Psr\Http\Message\ResponseInterface;
trait ResponseCastable
{
/**
* @param string|null $type
* @param \Psr\Http\Message\ResponseInterface $response
* @param string|null $type
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*

View File

@@ -114,6 +114,9 @@ class Application extends ServiceContainer
/**
* setCertificate.
*
* @param string $certificate
* @param string $serialNo
*
* @return $this
*/
public function setCertificate(string $certificate, string $serialNo)
@@ -129,6 +132,8 @@ class Application extends ServiceContainer
* returning false indicates that the signature field does not exist or is empty,
* and if the signature verification is wrong, the InvalidSignException will be thrown directly.
*
* @param array $data
*
* @return bool
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException

View File

@@ -24,6 +24,8 @@ class Client extends BaseClient
/**
* apply to settle in to become a small micro merchant.
*
* @param array $params
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -46,6 +48,9 @@ class Client extends BaseClient
/**
* query application status.
*
* @param string $applymentId
* @param string $businessCode
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -76,6 +81,8 @@ class Client extends BaseClient
/**
* merchant upgrade api.
*
* @param array $params
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -99,6 +106,8 @@ class Client extends BaseClient
/**
* get upgrade status.
*
* @param string $subMchId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException

View File

@@ -26,6 +26,8 @@ class Client extends BaseClient
/**
* get certficates.
*
* @param bool $returnRaw
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -63,6 +65,8 @@ class Client extends BaseClient
/**
* decrypt ciphertext.
*
* @param array $encryptCertificate
*
* @return string
*
* @throws \EasyWeChat\MicroMerchant\Kernel\Exceptions\InvalidExtensionException

View File

@@ -32,6 +32,8 @@ class BaseClient extends PaymentBaseClient
/**
* BaseClient constructor.
*
* @param \EasyWeChat\MicroMerchant\Application $app
*/
public function __construct(Application $app)
{
@@ -53,7 +55,11 @@ class BaseClient extends PaymentBaseClient
/**
* httpUpload.
*
* @param bool $returnResponse
* @param string $url
* @param array $files
* @param array $form
* @param array $query
* @param bool $returnResponse
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
@@ -113,7 +119,10 @@ class BaseClient extends PaymentBaseClient
/**
* request.
*
* @param string $endpoint
* @param array $params
* @param string $method
* @param array $options
* @param bool $returnResponse
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
@@ -151,6 +160,8 @@ class BaseClient extends PaymentBaseClient
/**
* processing parameters contain fields that require sensitive information encryption.
*
* @param array $params
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -177,6 +188,8 @@ class BaseClient extends PaymentBaseClient
/**
* To id card, mobile phone number and other fields sensitive information encryption.
*
* @param string $string
*
* @return string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -191,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);
@@ -224,6 +237,8 @@ class BaseClient extends PaymentBaseClient
/**
* getSign.
*
* @param array $params
*
* @return string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException

View File

@@ -24,6 +24,8 @@ class Client extends BaseClient
/**
* update settlement card.
*
* @param array $params
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -47,6 +49,8 @@ class Client extends BaseClient
/**
* update contact info.
*
* @param array $params
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException

View File

@@ -25,6 +25,8 @@ class Client extends BaseClient
/**
* Upload material.
*
* @param string $path
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException

View File

@@ -24,6 +24,11 @@ class Client extends BaseClient
/**
* Service providers configure recommendation functions for small and micro businesses.
*
* @param string $subAppId
* @param string $subscribeAppId
* @param string $receiptAppId
* @param string $subMchId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -52,6 +57,10 @@ class Client extends BaseClient
/**
* Configure the new payment directory.
*
* @param string $jsapiPath
* @param string $appId
* @param string $subMchId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -69,6 +78,10 @@ class Client extends BaseClient
/**
* bind appid.
*
* @param string $subAppId
* @param string $appId
* @param string $subMchId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -86,6 +99,8 @@ class Client extends BaseClient
/**
* add sub dev config.
*
* @param array $params
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -100,6 +115,9 @@ class Client extends BaseClient
/**
* query Sub Dev Config.
*
* @param string $subMchId
* @param string $appId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException

View File

@@ -27,6 +27,10 @@ class Client extends BaseClient
}
/**
* @param string $activityId
* @param int $state
* @param array $params
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -51,6 +55,8 @@ class Client extends BaseClient
}
/**
* @param array $params
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException

View File

@@ -24,6 +24,9 @@ class Client extends BaseClient
/**
* Get AppCode.
*
* @param string $path
* @param array $optional
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*/
public function get(string $path, array $optional = [])
@@ -38,6 +41,9 @@ class Client extends BaseClient
/**
* Get AppCode unlimit.
*
* @param string $scene
* @param array $optional
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*/
public function getUnlimit(string $scene, array $optional = [])
@@ -52,6 +58,9 @@ class Client extends BaseClient
/**
* Create QrCode.
*
* @param string $path
* @param int|null $width
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*/
public function getQrCode(string $path, int $width = null)
@@ -62,6 +71,9 @@ class Client extends BaseClient
/**
* Get stream.
*
* @param string $endpoint
* @param array $params
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

@@ -31,7 +31,7 @@ use EasyWeChat\Kernel\ServiceContainer;
* @property \EasyWeChat\MiniProgram\Plugin\DevClient $plugin_dev
* @property \EasyWeChat\MiniProgram\UniformMessage\Client $uniform_message
* @property \EasyWeChat\MiniProgram\ActivityMessage\Client $activity_message
* @property \EasyWeChat\MiniProgram\Express\Client $logistics
* @property \EasyWeChat\MiniProgram\Express\Client $express
* @property \EasyWeChat\MiniProgram\NearbyPoi\Client $nearby_poi
* @property \EasyWeChat\MiniProgram\OCR\Client $ocr
* @property \EasyWeChat\MiniProgram\Soter\Client $soter
@@ -40,9 +40,24 @@ use EasyWeChat\Kernel\ServiceContainer;
* @property \EasyWeChat\MiniProgram\Mall\ForwardsMall $mall
* @property \EasyWeChat\MiniProgram\SubscribeMessage\Client $subscribe_message
* @property \EasyWeChat\MiniProgram\RealtimeLog\Client $realtime_log
* @property \EasyWeChat\MiniProgram\RiskControl\Client $risk_control
* @property \EasyWeChat\MiniProgram\Search\Client $search
* @property \EasyWeChat\MiniProgram\Live\Client $live
* @property \EasyWeChat\MiniProgram\Broadcast\Client $broadcast
* @property \EasyWeChat\MiniProgram\UrlScheme\Client $url_scheme
* @property \EasyWeChat\MiniProgram\Union\Client $union
* @property \EasyWeChat\MiniProgram\Shop\Register\Client $shop_register
* @property \EasyWeChat\MiniProgram\Shop\Basic\Client $shop_basic
* @property \EasyWeChat\MiniProgram\Shop\Account\Client $shop_account
* @property \EasyWeChat\MiniProgram\Shop\Spu\Client $shop_spu
* @property \EasyWeChat\MiniProgram\Shop\Order\Client $shop_order
* @property \EasyWeChat\MiniProgram\Shop\Delivery\Client $shop_delivery
* @property \EasyWeChat\MiniProgram\Shop\Aftersale\Client $shop_aftersale
* @property \EasyWeChat\MiniProgram\Business\Client $business
* @property \EasyWeChat\MiniProgram\UrlLink\Client $url_link
* @property \EasyWeChat\MiniProgram\QrCode\Client $qr_code
* @property \EasyWeChat\MiniProgram\PhoneNumber\Client $phone_number
* @property \EasyWeChat\MiniProgram\ShortLink\Client $short_link
*/
class Application extends ServiceContainer
{
@@ -60,6 +75,7 @@ class Application extends ServiceContainer
ActivityMessage\ServiceProvider::class,
OpenData\ServiceProvider::class,
Plugin\ServiceProvider::class,
QrCode\ServiceProvider::class,
Base\ServiceProvider::class,
Express\ServiceProvider::class,
NearbyPoi\ServiceProvider::class,
@@ -68,12 +84,27 @@ class Application extends ServiceContainer
Mall\ServiceProvider::class,
SubscribeMessage\ServiceProvider::class,
RealtimeLog\ServiceProvider::class,
RiskControl\ServiceProvider::class,
Search\ServiceProvider::class,
Live\ServiceProvider::class,
Broadcast\ServiceProvider::class,
UrlScheme\ServiceProvider::class,
UrlLink\ServiceProvider::class,
Union\ServiceProvider::class,
PhoneNumber\ServiceProvider::class,
ShortLink\ServiceProvider::class,
// Base services
BasicService\Media\ServiceProvider::class,
BasicService\ContentSecurity\ServiceProvider::class,
Shop\Register\ServiceProvider::class,
Shop\Basic\ServiceProvider::class,
Shop\Account\ServiceProvider::class,
Shop\Spu\ServiceProvider::class,
Shop\Order\ServiceProvider::class,
Shop\Delivery\ServiceProvider::class,
Shop\Aftersale\ServiceProvider::class,
Business\ServiceProvider::class,
];
/**

View File

@@ -23,7 +23,7 @@ class AccessToken extends BaseAccessToken
/**
* @var string
*/
protected $endpointToGetToken = '/cgi-bin/token';
protected $endpointToGetToken = 'cgi-bin/token';
/**
* {@inheritdoc}

View File

@@ -23,6 +23,8 @@ class Client extends BaseClient
/**
* Get session info by code.
*
* @param string $code
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

@@ -23,6 +23,8 @@ class Client extends BaseClient
/**
* Add broadcast goods.
*
* @param array $goodsInfo
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -40,6 +42,9 @@ class Client extends BaseClient
/**
* Reset audit.
*
* @param int $auditId
* @param int $goodsId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -58,6 +63,8 @@ class Client extends BaseClient
/**
* Resubmit audit goods.
*
* @param int $goodsId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -75,6 +82,8 @@ class Client extends BaseClient
/**
* Delete broadcast goods.
*
* @param int $goodsId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -92,6 +101,8 @@ class Client extends BaseClient
/**
* Update goods info.
*
* @param array $goodsInfo
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -109,6 +120,8 @@ class Client extends BaseClient
/**
* Get goods information and review status.
*
* @param array $goodsIdArray
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -124,10 +137,10 @@ class Client extends BaseClient
}
/**
* Get goods list based on status.
* Get goods list based on status
*
* @param array $params
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
@@ -139,8 +152,8 @@ class Client extends BaseClient
/**
* Add goods to the designated live 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
*/
@@ -152,11 +165,11 @@ class Client extends BaseClient
/**
* Get Room List.
*
* @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
*
* @author onekb <1@1kb.ren>
*/
public function getRooms(int $start = 0, int $limit = 10)
@@ -172,11 +185,12 @@ class Client extends BaseClient
/**
* Get Playback List.
*
* @param int $roomId
* @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
*
* @author onekb <1@1kb.ren>
*/
public function getPlaybacks(int $roomId, int $start = 0, int $limit = 10)
@@ -194,8 +208,8 @@ class Client extends BaseClient
/**
* Create a live 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
*/
@@ -203,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);
}
}

View File

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

View File

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

View File

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

View File

@@ -23,6 +23,9 @@ class Client extends BaseClient
/**
* Get summary trend.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function summaryTrend(string $from, string $to)
@@ -33,6 +36,9 @@ class Client extends BaseClient
/**
* Get daily visit trend.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function dailyVisitTrend(string $from, string $to)
@@ -43,6 +49,9 @@ class Client extends BaseClient
/**
* Get weekly visit trend.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function weeklyVisitTrend(string $from, string $to)
@@ -53,6 +62,9 @@ class Client extends BaseClient
/**
* Get monthly visit trend.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function monthlyVisitTrend(string $from, string $to)
@@ -63,6 +75,9 @@ class Client extends BaseClient
/**
* Get visit distribution.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function visitDistribution(string $from, string $to)
@@ -73,6 +88,9 @@ class Client extends BaseClient
/**
* Get daily retain info.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function dailyRetainInfo(string $from, string $to)
@@ -83,6 +101,9 @@ class Client extends BaseClient
/**
* Get weekly retain info.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function weeklyRetainInfo(string $from, string $to)
@@ -93,6 +114,9 @@ class Client extends BaseClient
/**
* Get monthly retain info.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function monthlyRetainInfo(string $from, string $to)
@@ -103,6 +127,9 @@ class Client extends BaseClient
/**
* Get visit page.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function visitPage(string $from, string $to)
@@ -113,6 +140,9 @@ class Client extends BaseClient
/**
* Get user portrait.
*
* @param string $from
* @param string $to
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*/
public function userPortrait(string $from, string $to)
@@ -120,9 +150,42 @@ 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.
*
* @param string $api
* @param string $from
* @param string $to
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

@@ -25,6 +25,12 @@ class Encryptor extends BaseEncryptor
/**
* Decrypt data.
*
* @param string $sessionKey
* @param string $iv
* @param string $encrypted
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\DecryptException
*/
public function decryptData(string $sessionKey, string $iv, string $encrypted): array

View File

@@ -12,6 +12,7 @@
namespace EasyWeChat\MiniProgram\Express;
use EasyWeChat\Kernel\BaseClient;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
/**
* Class Client.
@@ -20,6 +21,22 @@ use EasyWeChat\Kernel\BaseClient;
*/
class Client extends BaseClient
{
/**
* 绑定、解绑物流账号
* @param array $params
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
* @throws InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
*/
public function bind(array $params = [])
{
if (empty($params['type']) || empty($params['biz_id']) || empty($params['delivery_id'])) {
throw new InvalidArgumentException('Missing parameter.');
}
return $this->httpPostJson('cgi-bin/express/business/account/bind', $params);
}
/**
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
@@ -31,6 +48,18 @@ class Client extends BaseClient
}
/**
* @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
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -42,6 +71,8 @@ class Client extends BaseClient
}
/**
* @param array $params
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -53,6 +84,8 @@ class Client extends BaseClient
}
/**
* @param array $params
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -64,6 +97,8 @@ class Client extends BaseClient
}
/**
* @param array $params
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -75,6 +110,9 @@ class Client extends BaseClient
}
/**
* @param string $deliveryId
* @param string $bizId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -100,6 +138,8 @@ class Client extends BaseClient
}
/**
* @param string $openid
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -114,6 +154,8 @@ class Client extends BaseClient
}
/**
* @param string $openid
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -126,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
]);
}
}

View File

@@ -23,8 +23,10 @@ class Client extends BaseClient
/**
* Get Room List.
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
* @param int $start
* @param int $limit
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
* @deprecated This method has been merged into `\EasyWeChat\MiniProgram\Broadcast`
*/
public function getRooms(int $start = 0, int $limit = 10)
@@ -40,8 +42,11 @@ class Client extends BaseClient
/**
* Get Playback List.
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
* @param int $roomId
* @param int $start
* @param int $limit
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
* @deprecated This method has been merged into `\EasyWeChat\MiniProgram\Broadcast`
*/
public function getPlaybacks(int $roomId, int $start = 0, int $limit = 10)

View File

@@ -70,6 +70,7 @@ class CartClient extends BaseClient
* 删除收藏.
*
* @param string $openid
* @param array $products
*
* @return mixed
*

View File

@@ -24,6 +24,8 @@ class Client extends BaseClient
/**
* Add nearby poi.
*
* @param array $params
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -42,6 +44,9 @@ class Client extends BaseClient
/**
* Update nearby poi.
*
* @param string $poiId
* @param array $params
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -60,6 +65,8 @@ class Client extends BaseClient
/**
* Delete nearby poi.
*
* @param string $poiId
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -75,6 +82,9 @@ class Client extends BaseClient
/**
* Get nearby poi list.
*
* @param int $page
* @param int $pageRows
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -90,6 +100,9 @@ class Client extends BaseClient
/**
* Set nearby poi show status.
*
* @param string $poiId
* @param int $status
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException

View File

@@ -23,6 +23,10 @@ class Client extends BaseClient
/**
* removeUserStorage.
*
* @param string $openid
* @param string $sessionKey
* @param array $key
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -37,12 +41,16 @@ class Client extends BaseClient
'signature' => hash_hmac('sha256', json_encode($data), $sessionKey),
];
return $this->httpPostJson('/wxa/remove_user_storage', $data, $query);
return $this->httpPostJson('wxa/remove_user_storage', $data, $query);
}
/**
* setUserStorage.
*
* @param string $openid
* @param string $sessionKey
* @param array $kvList
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -59,10 +67,12 @@ class Client extends BaseClient
'signature' => hash_hmac('sha256', json_encode($data), $sessionKey),
];
return $this->httpPostJson('/wxa/set_user_storage', $data, $query);
return $this->httpPostJson('wxa/set_user_storage', $data, $query);
}
/**
* @param array $params
*
* @return array
*/
protected function formatKVLists(array $params)

View File

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

View File

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

View File

@@ -23,6 +23,9 @@ class DevClient extends BaseClient
/**
* Get users.
*
* @param int $page
* @param int $size
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -40,6 +43,8 @@ class DevClient extends BaseClient
/**
* Agree to use plugin.
*
* @param string $appId
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -56,6 +61,8 @@ class DevClient extends BaseClient
/**
* Refuse to use plugin.
*
* @param string $reason
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

@@ -26,6 +26,8 @@ class ServiceProvider implements ServiceProviderInterface
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param \Pimple\Container $app
*/
public function register(Container $app)
{

View File

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

View File

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

View File

@@ -23,6 +23,11 @@ class Client extends BaseClient
/**
* Real time log query.
*
* @param string $date
* @param int $beginTime
* @param int $endTime
* @param array $options
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

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

View File

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

View File

@@ -23,6 +23,8 @@ class Client extends BaseClient
/**
* Submit applet page URL and parameter information.
*
* @param array $pages
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -21,6 +21,10 @@ use EasyWeChat\Kernel\BaseClient;
class Client extends BaseClient
{
/**
* @param string $openid
* @param string $json
* @param string $signature
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

@@ -30,6 +30,7 @@ class Client extends BaseClient
'template_id' => '',
'page' => '',
'data' => [],
'miniprogram_state' => 'formal',
];
/**
@@ -40,6 +41,8 @@ class Client extends BaseClient
/**
* Send a template message.
*
* @param array $data
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -56,6 +59,8 @@ class Client extends BaseClient
}
/**
* @param array $data
*
* @return array
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
@@ -109,6 +114,10 @@ class Client extends BaseClient
/**
* Combine templates and add them to your personal template library under your account.
*
* @param string $tid
* @param array $kidList
* @param string|null $sceneDesc
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -125,6 +134,8 @@ class Client extends BaseClient
/**
* Delete personal template under account.
*
* @param string $id
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -138,6 +149,8 @@ class Client extends BaseClient
/**
* Get keyword list under template title.
*
* @param string $tid
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -151,6 +164,10 @@ class Client extends BaseClient
/**
* Get the title of the public template under the category to which the account belongs.
*
* @param array $ids
* @param int $start
* @param int $limit
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

View File

@@ -40,6 +40,9 @@ class Client extends BaseClient
protected $required = ['touser', 'template_id', 'form_id'];
/**
* @param int $offset
* @param int $count
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -51,6 +54,8 @@ class Client extends BaseClient
}
/**
* @param string $id
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -62,6 +67,9 @@ class Client extends BaseClient
}
/**
* @param string $id
* @param array $keyword
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -76,6 +84,8 @@ class Client extends BaseClient
}
/**
* @param string $templateId
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
@@ -89,6 +99,9 @@ class Client extends BaseClient
}
/**
* @param int $offset
* @param int $count
*
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException

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