125 changed files with 9988 additions and 0 deletions
File diff suppressed because it is too large
@ -0,0 +1,67 @@ |
|||
# Contribute |
|||
|
|||
## Introduction |
|||
|
|||
First, thank you for considering contributing to wechat! It's people like you that make the open source community such a great community! 😊 |
|||
|
|||
We welcome any type of contribution, not only code. You can help with |
|||
- **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open) |
|||
- **Marketing**: writing blog posts, howto's, printing stickers, ... |
|||
- **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ... |
|||
- **Code**: take a look at the [open issues](issues). Even if you can't write code, commenting on them, showing that you care about a given issue matters. It helps us triage them. |
|||
- **Money**: we welcome financial contributions in full transparency on our [open collective](https://opencollective.com/wechat). |
|||
|
|||
## Your First Contribution |
|||
|
|||
Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). |
|||
|
|||
## Submitting code |
|||
|
|||
Any code change should be submitted as a pull request. The description should explain what the code does and give steps to execute it. The pull request should also contain tests. |
|||
|
|||
## Code review process |
|||
|
|||
The bigger the pull request, the longer it will take to review and merge. Try to break down large pull requests in smaller chunks that are easier to review and merge. |
|||
It is also always helpful to have some context for your pull request. What was the purpose? Why does it matter to you? |
|||
|
|||
## Financial contributions |
|||
|
|||
We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/wechat). |
|||
Anyone can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed. |
|||
|
|||
## Questions |
|||
|
|||
If you have any questions, create an [issue](issue) (protip: do a quick search first to see if someone else didn't ask the same question before!). |
|||
You can also reach us at hello@wechat.opencollective.com. |
|||
|
|||
## Credits |
|||
|
|||
### Contributors |
|||
|
|||
Thank you to all the people who have already contributed to wechat! |
|||
<a href="graphs/contributors"><img src="https://opencollective.com/wechat/contributors.svg?width=890" /></a> |
|||
|
|||
|
|||
### Backers |
|||
|
|||
Thank you to all our backers! [[Become a backer](https://opencollective.com/wechat#backer)] |
|||
|
|||
<a href="https://opencollective.com/wechat#backers" target="_blank"><img src="https://opencollective.com/wechat/backers.svg?width=890"></a> |
|||
|
|||
|
|||
### Sponsors |
|||
|
|||
Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/wechat#sponsor)) |
|||
|
|||
<a href="https://opencollective.com/wechat/sponsor/0/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/0/avatar.svg"></a> |
|||
<a href="https://opencollective.com/wechat/sponsor/1/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/1/avatar.svg"></a> |
|||
<a href="https://opencollective.com/wechat/sponsor/2/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/2/avatar.svg"></a> |
|||
<a href="https://opencollective.com/wechat/sponsor/3/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/3/avatar.svg"></a> |
|||
<a href="https://opencollective.com/wechat/sponsor/4/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/4/avatar.svg"></a> |
|||
<a href="https://opencollective.com/wechat/sponsor/5/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/5/avatar.svg"></a> |
|||
<a href="https://opencollective.com/wechat/sponsor/6/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/6/avatar.svg"></a> |
|||
<a href="https://opencollective.com/wechat/sponsor/7/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/7/avatar.svg"></a> |
|||
<a href="https://opencollective.com/wechat/sponsor/8/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/8/avatar.svg"></a> |
|||
<a href="https://opencollective.com/wechat/sponsor/9/website" target="_blank"><img src="https://opencollective.com/wechat/sponsor/9/avatar.svg"></a> |
|||
|
|||
<!-- This `CONTRIBUTING.md` is based on @nayafia's template https://github.com/nayafia/contributing-template --> |
|||
@ -0,0 +1,22 @@ |
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) overtrue <i@overtrue.me> |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
|
|||
@ -0,0 +1,92 @@ |
|||
<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. |
|||
|
|||
[](https://github.com/overtrue/wechat/actions) |
|||
[](https://github.com/overtrue/wechat/actions) |
|||
[](https://packagist.org/packages/overtrue/wechat) |
|||
[](https://packagist.org/packages/overtrue/wechat) |
|||
[](https://scrutinizer-ci.com/g/overtrue/wechat/?branch=master) |
|||
[](https://scrutinizer-ci.com/g/overtrue/wechat/?branch=master) |
|||
[](https://packagist.org/packages/overtrue/wechat) |
|||
[](https://packagist.org/packages/overtrue/wechat) |
|||
|
|||
|
|||
## Requirement |
|||
|
|||
1. PHP >= 7.1 |
|||
2. **[Composer](https://getcomposer.org/)** |
|||
3. openssl 拓展 |
|||
4. fileinfo 拓展(素材管理模块需要用到) |
|||
|
|||
## Installation |
|||
|
|||
```shell |
|||
$ composer require "overtrue/wechat:^4.2" -vvv |
|||
``` |
|||
|
|||
## Usage |
|||
|
|||
基本使用(以服务端为例): |
|||
|
|||
```php |
|||
<?php |
|||
|
|||
use EasyWeChat\Factory; |
|||
|
|||
$options = [ |
|||
'app_id' => 'wx3cf0f39249eb0exxx', |
|||
'secret' => 'f1c242f4f28f735d4687abb469072xxx', |
|||
'token' => 'easywechat', |
|||
'log' => [ |
|||
'level' => 'debug', |
|||
'file' => '/tmp/easywechat.log', |
|||
], |
|||
// ... |
|||
]; |
|||
|
|||
$app = Factory::officialAccount($options); |
|||
|
|||
$server = $app->server; |
|||
$user = $app->user; |
|||
|
|||
$server->push(function($message) use ($user) { |
|||
$fromUser = $user->get($message['FromUserName']); |
|||
|
|||
return "{$fromUser->nickname} 您好!欢迎关注 overtrue!"; |
|||
}); |
|||
|
|||
$server->serve()->send(); |
|||
``` |
|||
|
|||
更多请参考 [https://www.easywechat.com/](https://www.easywechat.com/)。 |
|||
|
|||
## 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) |
|||
|
|||
## Integration |
|||
|
|||
[Laravel 5 拓展包: overtrue/laravel-wechat](https://github.com/overtrue/laravel-wechat) |
|||
|
|||
## Contributors |
|||
|
|||
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. |
|||
<a href="https://github.com/overtrue/wechat/graphs/contributors"><img src="https://opencollective.com/wechat/contributors.svg?width=890" /></a> |
|||
|
|||
|
|||
## PHP 扩展包开发 |
|||
|
|||
> 想知道如何从零开始构建 PHP 扩展包? |
|||
> |
|||
> 请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package) |
|||
|
|||
|
|||
## License |
|||
|
|||
MIT |
|||
|
|||
|
|||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fovertrue%2Fwechat?ref=badge_large) |
|||
@ -0,0 +1,59 @@ |
|||
{ |
|||
"name": "overtrue/wechat", |
|||
"description": "微信SDK", |
|||
"keywords": [ |
|||
"wechat", |
|||
"weixin", |
|||
"weixin-sdk", |
|||
"sdk" |
|||
], |
|||
"license": "MIT", |
|||
"authors": [ |
|||
{ |
|||
"name": "overtrue", |
|||
"email": "anzhengchao@gmail.com" |
|||
} |
|||
], |
|||
"require": { |
|||
"php": ">=7.1", |
|||
"ext-fileinfo": "*", |
|||
"ext-openssl": "*", |
|||
"ext-simplexml": "*", |
|||
"easywechat-composer/easywechat-composer": "^1.1", |
|||
"guzzlehttp/guzzle": "^6.2", |
|||
"monolog/monolog": "^1.22 || ^2.0", |
|||
"overtrue/socialite": "~2.0", |
|||
"pimple/pimple": "^3.0", |
|||
"psr/simple-cache": "^1.0", |
|||
"symfony/cache": "^3.3 || ^4.3", |
|||
"symfony/event-dispatcher": "^4.3", |
|||
"symfony/http-foundation": "^2.7 || ^3.0 || ^4.0", |
|||
"symfony/psr-http-message-bridge": "^0.3 || ^1.0" |
|||
}, |
|||
"require-dev": { |
|||
"friendsofphp/php-cs-fixer": "^2.15", |
|||
"mikey179/vfsstream": "^1.6", |
|||
"mockery/mockery": "^1.2.3", |
|||
"phpstan/phpstan": "^0.11.12", |
|||
"phpunit/phpunit": "^7.5" |
|||
}, |
|||
"autoload": { |
|||
"psr-4": { |
|||
"EasyWeChat\\": "src/" |
|||
}, |
|||
"files": [ |
|||
"src/Kernel/Support/Helpers.php", |
|||
"src/Kernel/Helpers.php" |
|||
] |
|||
}, |
|||
"autoload-dev": { |
|||
"psr-4": { |
|||
"EasyWeChat\\Tests\\": "tests/" |
|||
} |
|||
}, |
|||
"scripts": { |
|||
"phpcs": "vendor/bin/php-cs-fixer fix", |
|||
"phpstan": "vendor/bin/phpstan analyse", |
|||
"test": "vendor/bin/phpunit" |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
<?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; |
|||
|
|||
/** |
|||
* Class Factory. |
|||
* |
|||
* @method static \EasyWeChat\Payment\Application payment(array $config) |
|||
* @method static \EasyWeChat\MiniProgram\Application miniProgram(array $config) |
|||
* @method static \EasyWeChat\OpenPlatform\Application openPlatform(array $config) |
|||
* @method static \EasyWeChat\OfficialAccount\Application officialAccount(array $config) |
|||
* @method static \EasyWeChat\BasicService\Application basicService(array $config) |
|||
* @method static \EasyWeChat\Work\Application work(array $config) |
|||
* @method static \EasyWeChat\OpenWork\Application openWork(array $config) |
|||
* @method static \EasyWeChat\MicroMerchant\Application microMerchant(array $config) |
|||
*/ |
|||
class Factory |
|||
{ |
|||
/** |
|||
* @param string $name |
|||
* @param array $config |
|||
* |
|||
* @return \EasyWeChat\Kernel\ServiceContainer |
|||
*/ |
|||
public static function make($name, array $config) |
|||
{ |
|||
$namespace = Kernel\Support\Str::studly($name); |
|||
$application = "\\EasyWeChat\\{$namespace}\\Application"; |
|||
|
|||
return new $application($config); |
|||
} |
|||
|
|||
/** |
|||
* Dynamically pass methods to the application. |
|||
* |
|||
* @param string $name |
|||
* @param array $arguments |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public static function __callStatic($name, $arguments) |
|||
{ |
|||
return self::make($name, ...$arguments); |
|||
} |
|||
} |
|||
@ -0,0 +1,220 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform; |
|||
|
|||
use EasyWeChat\Kernel\ServiceContainer; |
|||
use EasyWeChat\MiniProgram\Encryptor; |
|||
use EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken; |
|||
use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Application as MiniProgram; |
|||
use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Auth\Client; |
|||
use EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Account\Client as AccountClient; |
|||
use EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Application as OfficialAccount; |
|||
use EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\OAuth\ComponentDelegate; |
|||
use EasyWeChat\OpenPlatform\Authorizer\Server\Guard; |
|||
|
|||
/** |
|||
* Class Application. |
|||
* |
|||
* @property \EasyWeChat\OpenPlatform\Server\Guard $server |
|||
* @property \EasyWeChat\OpenPlatform\Auth\AccessToken $access_token |
|||
* @property \EasyWeChat\OpenPlatform\CodeTemplate\Client $code_template |
|||
* @property \EasyWeChat\OpenPlatform\Component\Client $component |
|||
* |
|||
* @method mixed handleAuthorize(string $authCode = null) |
|||
* @method mixed getAuthorizer(string $appId) |
|||
* @method mixed getAuthorizerOption(string $appId, string $name) |
|||
* @method mixed setAuthorizerOption(string $appId, string $name, string $value) |
|||
* @method mixed getAuthorizers(int $offset = 0, int $count = 500) |
|||
* @method mixed createPreAuthorizationCode() |
|||
*/ |
|||
class Application extends ServiceContainer |
|||
{ |
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $providers = [ |
|||
Auth\ServiceProvider::class, |
|||
Base\ServiceProvider::class, |
|||
Server\ServiceProvider::class, |
|||
CodeTemplate\ServiceProvider::class, |
|||
Component\ServiceProvider::class, |
|||
]; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $defaultConfig = [ |
|||
'http' => [ |
|||
'timeout' => 5.0, |
|||
'base_uri' => 'https://api.weixin.qq.com/', |
|||
], |
|||
]; |
|||
|
|||
/** |
|||
* Creates the officialAccount application. |
|||
* |
|||
* @param string $appId |
|||
* @param string|null $refreshToken |
|||
* @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken |
|||
* |
|||
* @return \EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Application |
|||
*/ |
|||
public function officialAccount(string $appId, string $refreshToken = null, AccessToken $accessToken = null): OfficialAccount |
|||
{ |
|||
$application = new OfficialAccount($this->getAuthorizerConfig($appId, $refreshToken), $this->getReplaceServices($accessToken) + [ |
|||
'encryptor' => $this['encryptor'], |
|||
|
|||
'account' => function ($app) { |
|||
return new AccountClient($app, $this); |
|||
}, |
|||
]); |
|||
|
|||
$application->extend('oauth', function ($socialite) { |
|||
/* @var \Overtrue\Socialite\Providers\WeChatProvider $socialite */ |
|||
return $socialite->component(new ComponentDelegate($this)); |
|||
}); |
|||
|
|||
return $application; |
|||
} |
|||
|
|||
/** |
|||
* Creates the miniProgram application. |
|||
* |
|||
* @param string $appId |
|||
* @param string|null $refreshToken |
|||
* @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken |
|||
* |
|||
* @return \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Application |
|||
*/ |
|||
public function miniProgram(string $appId, string $refreshToken = null, AccessToken $accessToken = null): MiniProgram |
|||
{ |
|||
return new MiniProgram($this->getAuthorizerConfig($appId, $refreshToken), $this->getReplaceServices($accessToken) + [ |
|||
'encryptor' => function () { |
|||
return new Encryptor($this['config']['app_id'], $this['config']['token'], $this['config']['aes_key']); |
|||
}, |
|||
|
|||
'auth' => function ($app) { |
|||
return new Client($app, $this); |
|||
}, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Return the pre-authorization login page url. |
|||
* |
|||
* @param string $callbackUrl |
|||
* @param string|array|null $optional |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getPreAuthorizationUrl(string $callbackUrl, $optional = []): string |
|||
{ |
|||
// 兼容旧版 API 设计 |
|||
if (\is_string($optional)) { |
|||
$optional = [ |
|||
'pre_auth_code' => $optional, |
|||
]; |
|||
} else { |
|||
$optional['pre_auth_code'] = $this->createPreAuthorizationCode()['pre_auth_code']; |
|||
} |
|||
|
|||
$queries = \array_merge($optional, [ |
|||
'component_appid' => $this['config']['app_id'], |
|||
'redirect_uri' => $callbackUrl, |
|||
]); |
|||
|
|||
return 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?'.http_build_query($queries); |
|||
} |
|||
|
|||
/** |
|||
* Return the pre-authorization login page url (mobile). |
|||
* |
|||
* @param string $callbackUrl |
|||
* @param string|array|null $optional |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getMobilePreAuthorizationUrl(string $callbackUrl, $optional = []): string |
|||
{ |
|||
// 兼容旧版 API 设计 |
|||
if (\is_string($optional)) { |
|||
$optional = [ |
|||
'pre_auth_code' => $optional, |
|||
]; |
|||
} else { |
|||
$optional['pre_auth_code'] = $this->createPreAuthorizationCode()['pre_auth_code']; |
|||
} |
|||
|
|||
$queries = \array_merge($optional, [ |
|||
'component_appid' => $this['config']['app_id'], |
|||
'redirect_uri' => $callbackUrl, |
|||
'action' => 'bindcomponent', |
|||
'no_scan' => 1, |
|||
]); |
|||
|
|||
return 'https://mp.weixin.qq.com/safe/bindcomponent?'.http_build_query($queries).'#wechat_redirect'; |
|||
} |
|||
|
|||
/** |
|||
* @param string $appId |
|||
* @param string|null $refreshToken |
|||
* |
|||
* @return array |
|||
*/ |
|||
protected function getAuthorizerConfig(string $appId, string $refreshToken = null): array |
|||
{ |
|||
return $this['config']->merge([ |
|||
'component_app_id' => $this['config']['app_id'], |
|||
'app_id' => $appId, |
|||
'refresh_token' => $refreshToken, |
|||
])->toArray(); |
|||
} |
|||
|
|||
/** |
|||
* @param \EasyWeChat\OpenPlatform\Authorizer\Auth\AccessToken|null $accessToken |
|||
* |
|||
* @return array |
|||
*/ |
|||
protected function getReplaceServices(AccessToken $accessToken = null): array |
|||
{ |
|||
$services = [ |
|||
'access_token' => $accessToken ?: function ($app) { |
|||
return new AccessToken($app, $this); |
|||
}, |
|||
|
|||
'server' => function ($app) { |
|||
return new Guard($app); |
|||
}, |
|||
]; |
|||
|
|||
foreach (['cache', 'http_client', 'log', 'logger', 'request'] as $reuse) { |
|||
if (isset($this[$reuse])) { |
|||
$services[$reuse] = $this[$reuse]; |
|||
} |
|||
} |
|||
|
|||
return $services; |
|||
} |
|||
|
|||
/** |
|||
* Handle dynamic calls. |
|||
* |
|||
* @param string $method |
|||
* @param array $args |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function __call($method, $args) |
|||
{ |
|||
return $this->base->$method(...$args); |
|||
} |
|||
} |
|||
@ -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\OpenPlatform\Auth; |
|||
|
|||
use EasyWeChat\Kernel\AccessToken as BaseAccessToken; |
|||
|
|||
/** |
|||
* Class AccessToken. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class AccessToken extends BaseAccessToken |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $requestMethod = 'POST'; |
|||
|
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $tokenKey = 'component_access_token'; |
|||
|
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $endpointToGetToken = 'cgi-bin/component/api_component_token'; |
|||
|
|||
/** |
|||
* @return array |
|||
*/ |
|||
protected function getCredentials(): array |
|||
{ |
|||
return [ |
|||
'component_appid' => $this->app['config']['app_id'], |
|||
'component_appsecret' => $this->app['config']['secret'], |
|||
'component_verify_ticket' => $this->app['verify_ticket']->getTicket(), |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Auth; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['verify_ticket'] = function ($app) { |
|||
return new VerifyTicket($app); |
|||
}; |
|||
|
|||
$app['access_token'] = function ($app) { |
|||
return new AccessToken($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Auth; |
|||
|
|||
use EasyWeChat\Kernel\Exceptions\RuntimeException; |
|||
use EasyWeChat\Kernel\Traits\InteractsWithCache; |
|||
use EasyWeChat\OpenPlatform\Application; |
|||
|
|||
/** |
|||
* Class VerifyTicket. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class VerifyTicket |
|||
{ |
|||
use InteractsWithCache; |
|||
|
|||
/** |
|||
* @var \EasyWeChat\OpenPlatform\Application |
|||
*/ |
|||
protected $app; |
|||
|
|||
/** |
|||
* Constructor. |
|||
* |
|||
* @param \EasyWeChat\OpenPlatform\Application $app |
|||
*/ |
|||
public function __construct(Application $app) |
|||
{ |
|||
$this->app = $app; |
|||
} |
|||
|
|||
/** |
|||
* Put the credential `component_verify_ticket` in cache. |
|||
* |
|||
* @param string $ticket |
|||
* |
|||
* @return $this |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \Psr\SimpleCache\InvalidArgumentException |
|||
*/ |
|||
public function setTicket(string $ticket) |
|||
{ |
|||
$this->getCache()->set($this->getCacheKey(), $ticket, 3600); |
|||
|
|||
if (!$this->getCache()->has($this->getCacheKey())) { |
|||
throw new RuntimeException('Failed to cache verify ticket.'); |
|||
} |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the credential `component_verify_ticket` from cache. |
|||
* |
|||
* @return string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|||
* @throws \Psr\SimpleCache\InvalidArgumentException |
|||
*/ |
|||
public function getTicket(): string |
|||
{ |
|||
if ($cached = $this->getCache()->get($this->getCacheKey())) { |
|||
return $cached; |
|||
} |
|||
|
|||
throw new RuntimeException('Credential "component_verify_ticket" does not exist in cache.'); |
|||
} |
|||
|
|||
/** |
|||
* Get cache key. |
|||
* |
|||
* @return string |
|||
*/ |
|||
protected function getCacheKey(): string |
|||
{ |
|||
return 'easywechat.open_platform.verify_ticket.'.$this->app['config']['app_id']; |
|||
} |
|||
} |
|||
@ -0,0 +1,96 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\Aggregate\Account; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author Scholer <scholer_l@live.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* 创建开放平台帐号并绑定公众号/小程序. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create() |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']['app_id'], |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/open/create', $params); |
|||
} |
|||
|
|||
/** |
|||
* 将公众号/小程序绑定到开放平台帐号下. |
|||
* |
|||
* @param string $openAppId 开放平台帐号appid |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function bindTo(string $openAppId) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']['app_id'], |
|||
'open_appid' => $openAppId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/open/bind', $params); |
|||
} |
|||
|
|||
/** |
|||
* 将公众号/小程序从开放平台帐号下解绑. |
|||
* |
|||
* @param string $openAppId 开放平台帐号appid |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function unbindFrom(string $openAppId) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']['app_id'], |
|||
'open_appid' => $openAppId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/open/unbind', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取公众号/小程序所绑定的开放平台帐号. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getBinding() |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']['app_id'], |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/open/get', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\Aggregate; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class AggregateServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\Auth; |
|||
|
|||
use EasyWeChat\Kernel\AccessToken as BaseAccessToken; |
|||
use EasyWeChat\OpenPlatform\Application; |
|||
use Pimple\Container; |
|||
|
|||
/** |
|||
* Class AccessToken. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class AccessToken extends BaseAccessToken |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $requestMethod = 'POST'; |
|||
|
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $queryName = 'access_token'; |
|||
|
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
protected $tokenKey = 'authorizer_access_token'; |
|||
|
|||
/** |
|||
* @var \EasyWeChat\OpenPlatform\Application |
|||
*/ |
|||
protected $component; |
|||
|
|||
/** |
|||
* AuthorizerAccessToken constructor. |
|||
* |
|||
* @param \Pimple\Container $app |
|||
* @param \EasyWeChat\OpenPlatform\Application $component |
|||
*/ |
|||
public function __construct(Container $app, Application $component) |
|||
{ |
|||
parent::__construct($app); |
|||
|
|||
$this->component = $component; |
|||
} |
|||
|
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
protected function getCredentials(): array |
|||
{ |
|||
return [ |
|||
'component_appid' => $this->component['config']['app_id'], |
|||
'authorizer_appid' => $this->app['config']['app_id'], |
|||
'authorizer_refresh_token' => $this->app['config']['refresh_token'], |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
public function getEndpoint(): string |
|||
{ |
|||
return 'cgi-bin/component/api_authorizer_token?'.http_build_query([ |
|||
'component_access_token' => $this->component['access_token']->getToken()['component_access_token'], |
|||
]); |
|||
} |
|||
} |
|||
@ -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\OpenPlatform\Authorizer\MiniProgram\Account; |
|||
|
|||
use EasyWeChat\OpenPlatform\Authorizer\Aggregate\Account\Client as BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author ClouderSky <clouder.flow@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* 获取账号基本信息. |
|||
*/ |
|||
public function getBasicInfo() |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/account/getaccountbasicinfo'); |
|||
} |
|||
|
|||
/** |
|||
* 修改头像. |
|||
* |
|||
* @param string $mediaId 头像素材mediaId |
|||
* @param float $left 剪裁框左上角x坐标(取值范围:[0, 1]) |
|||
* @param float $top 剪裁框左上角y坐标(取值范围:[0, 1]) |
|||
* @param float $right 剪裁框右下角x坐标(取值范围:[0, 1]) |
|||
* @param float $bottom 剪裁框右下角y坐标(取值范围:[0, 1]) |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function updateAvatar( |
|||
string $mediaId, |
|||
float $left = 0.0, |
|||
float $top = 0.0, |
|||
float $right = 1.0, |
|||
float $bottom = 1.0 |
|||
) { |
|||
$params = [ |
|||
'head_img_media_id' => $mediaId, |
|||
'x1' => $left, 'y1' => $top, 'x2' => $right, 'y2' => $bottom, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/account/modifyheadimage', $params); |
|||
} |
|||
|
|||
/** |
|||
* 修改功能介绍. |
|||
* |
|||
* @param string $signature 功能介绍(简介) |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function updateSignature(string $signature) |
|||
{ |
|||
$params = ['signature' => $signature]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/account/modifysignature', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Account; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['account'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram; |
|||
|
|||
use EasyWeChat\MiniProgram\Application as MiniProgram; |
|||
use EasyWeChat\OpenPlatform\Authorizer\Aggregate\AggregateServiceProvider; |
|||
|
|||
/** |
|||
* Class Application. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
* |
|||
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Account\Client $account |
|||
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client $code |
|||
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Domain\Client $domain |
|||
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Setting\Client $setting |
|||
* @property \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester\Client $tester |
|||
*/ |
|||
class Application extends MiniProgram |
|||
{ |
|||
/** |
|||
* Application constructor. |
|||
* |
|||
* @param array $config |
|||
* @param array $prepends |
|||
*/ |
|||
public function __construct(array $config = [], array $prepends = []) |
|||
{ |
|||
parent::__construct($config, $prepends); |
|||
|
|||
$providers = [ |
|||
AggregateServiceProvider::class, |
|||
Code\ServiceProvider::class, |
|||
Domain\ServiceProvider::class, |
|||
Account\ServiceProvider::class, |
|||
Setting\ServiceProvider::class, |
|||
Tester\ServiceProvider::class, |
|||
]; |
|||
|
|||
foreach ($providers as $provider) { |
|||
$this->register(new $provider()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Auth; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\ServiceContainer; |
|||
use EasyWeChat\OpenPlatform\Application; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @var \EasyWeChat\OpenPlatform\Application |
|||
*/ |
|||
protected $component; |
|||
|
|||
/** |
|||
* Client constructor. |
|||
* |
|||
* @param \EasyWeChat\Kernel\ServiceContainer $app |
|||
* @param \EasyWeChat\OpenPlatform\Application $component |
|||
*/ |
|||
public function __construct(ServiceContainer $app, Application $component) |
|||
{ |
|||
parent::__construct($app); |
|||
|
|||
$this->component = $component; |
|||
} |
|||
|
|||
/** |
|||
* 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 |
|||
*/ |
|||
public function session(string $code) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']['app_id'], |
|||
'js_code' => $code, |
|||
'grant_type' => 'authorization_code', |
|||
'component_appid' => $this->component['config']['app_id'], |
|||
'component_access_token' => $this->component['access_token']->getToken()['component_access_token'], |
|||
]; |
|||
|
|||
return $this->httpGet('sns/component/jscode2session', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,267 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @param int $templateId |
|||
* @param string $extJson |
|||
* @param string $version |
|||
* @param string $description |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function commit(int $templateId, string $extJson, string $version, string $description) |
|||
{ |
|||
return $this->httpPostJson('wxa/commit', [ |
|||
'template_id' => $templateId, |
|||
'ext_json' => $extJson, |
|||
'user_version' => $version, |
|||
'user_desc' => $description, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param string|null $path |
|||
* |
|||
* @return \EasyWeChat\Kernel\Http\Response |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getQrCode(string $path = null) |
|||
{ |
|||
return $this->requestRaw('wxa/get_qrcode', 'GET', [ |
|||
'query' => ['path' => $path], |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function getCategory() |
|||
{ |
|||
return $this->httpGet('wxa/get_category'); |
|||
} |
|||
|
|||
/** |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function getPage() |
|||
{ |
|||
return $this->httpGet('wxa/get_page'); |
|||
} |
|||
|
|||
/** |
|||
* @param array $itemList |
|||
* @param string|null $feedbackInfo |
|||
* @param string|null $feedbackStuff |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function submitAudit(array $itemList, string $feedbackInfo = null, string $feedbackStuff = null) |
|||
{ |
|||
return $this->httpPostJson('wxa/submit_audit', [ |
|||
'item_list' => $itemList, |
|||
'feedback_info' => $feedbackInfo, |
|||
'feedback_stuff' => $feedbackStuff, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param int $auditId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getAuditStatus(int $auditId) |
|||
{ |
|||
return $this->httpPostJson('wxa/get_auditstatus', [ |
|||
'auditid' => $auditId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function getLatestAuditStatus() |
|||
{ |
|||
return $this->httpGet('wxa/get_latest_auditstatus'); |
|||
} |
|||
|
|||
/** |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function release() |
|||
{ |
|||
return $this->httpPostJson('wxa/release'); |
|||
} |
|||
|
|||
/** |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function withdrawAudit() |
|||
{ |
|||
return $this->httpGet('wxa/undocodeaudit'); |
|||
} |
|||
|
|||
/** |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function rollbackRelease() |
|||
{ |
|||
return $this->httpGet('wxa/revertcoderelease'); |
|||
} |
|||
|
|||
/** |
|||
* @param string $action |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function changeVisitStatus(string $action) |
|||
{ |
|||
return $this->httpPostJson('wxa/change_visitstatus', [ |
|||
'action' => $action, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 分阶段发布. |
|||
* |
|||
* @param int $grayPercentage |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function grayRelease(int $grayPercentage) |
|||
{ |
|||
return $this->httpPostJson('wxa/grayrelease', [ |
|||
'gray_percentage' => $grayPercentage, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 取消分阶段发布. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function revertGrayRelease() |
|||
{ |
|||
return $this->httpGet('wxa/revertgrayrelease'); |
|||
} |
|||
|
|||
/** |
|||
* 查询当前分阶段发布详情. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function getGrayRelease() |
|||
{ |
|||
return $this->httpGet('wxa/getgrayreleaseplan'); |
|||
} |
|||
|
|||
/** |
|||
* 查询当前设置的最低基础库版本及各版本用户占比. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getSupportVersion() |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/getweappsupportversion'); |
|||
} |
|||
|
|||
/** |
|||
* 设置最低基础库版本. |
|||
* |
|||
* @param string $version |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setSupportVersion(string $version) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/setweappsupportversion', [ |
|||
'version' => $version, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 查询服务商的当月提审限额(quota)和加急次数. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function queryQuota() |
|||
{ |
|||
return $this->httpGet('wxa/queryquota'); |
|||
} |
|||
|
|||
/** |
|||
* 加急审核申请. |
|||
* |
|||
* @param int $auditId 审核单ID |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function speedupAudit(int $auditId) |
|||
{ |
|||
return $this->httpPostJson('wxa/speedupaudit', [ |
|||
'auditid' => $auditId, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['code'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Domain; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function modify(array $params) |
|||
{ |
|||
return $this->httpPostJson('wxa/modify_domain', $params); |
|||
} |
|||
|
|||
/** |
|||
* 设置小程序业务域名. |
|||
* |
|||
* @param array $domains |
|||
* @param string $action |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setWebviewDomain(array $domains, $action = 'add') |
|||
{ |
|||
return $this->httpPostJson('wxa/setwebviewdomain', [ |
|||
'action' => $action, |
|||
'webviewdomain' => $domains, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Domain; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['domain'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,248 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Setting; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author ClouderSky <clouder.flow@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* 获取账号可以设置的所有类目. |
|||
*/ |
|||
public function getAllCategories() |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/getallcategories'); |
|||
} |
|||
|
|||
/** |
|||
* 添加类目. |
|||
* |
|||
* @param array $categories 类目数组 |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function addCategories(array $categories) |
|||
{ |
|||
$params = ['categories' => $categories]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/wxopen/addcategory', $params); |
|||
} |
|||
|
|||
/** |
|||
* 删除类目. |
|||
* |
|||
* @param int $firstId 一级类目ID |
|||
* @param int $secondId 二级类目ID |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function deleteCategories(int $firstId, int $secondId) |
|||
{ |
|||
$params = ['first' => $firstId, 'second' => $secondId]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/wxopen/deletecategory', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取账号已经设置的所有类目. |
|||
*/ |
|||
public function getCategories() |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/getcategory'); |
|||
} |
|||
|
|||
/** |
|||
* 修改类目. |
|||
* |
|||
* @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 updateCategory(array $category) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/modifycategory', $category); |
|||
} |
|||
|
|||
/** |
|||
* 小程序名称设置及改名. |
|||
* |
|||
* @param string $nickname 昵称 |
|||
* @param string $idCardMediaId 身份证照片素材ID |
|||
* @param string $licenseMediaId 组织机构代码证或营业执照素材ID |
|||
* @param array $otherStuffs 其他证明材料素材ID |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setNickname( |
|||
string $nickname, |
|||
string $idCardMediaId = '', |
|||
string $licenseMediaId = '', |
|||
array $otherStuffs = [] |
|||
) { |
|||
$params = [ |
|||
'nick_name' => $nickname, |
|||
'id_card' => $idCardMediaId, |
|||
'license' => $licenseMediaId, |
|||
]; |
|||
|
|||
for ($i = \count($otherStuffs) - 1; $i >= 0; --$i) { |
|||
$params['naming_other_stuff_'.($i + 1)] = $otherStuffs[$i]; |
|||
} |
|||
|
|||
return $this->httpPostJson('wxa/setnickname', $params); |
|||
} |
|||
|
|||
/** |
|||
* 小程序改名审核状态查询. |
|||
* |
|||
* @param int $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 getNicknameAuditStatus($auditId) |
|||
{ |
|||
$params = ['audit_id' => $auditId]; |
|||
|
|||
return $this->httpPostJson('wxa/api_wxa_querynickname', $params); |
|||
} |
|||
|
|||
/** |
|||
* 微信认证名称检测. |
|||
* |
|||
* @param string $nickname 名称(昵称) |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function isAvailableNickname($nickname) |
|||
{ |
|||
$params = ['nick_name' => $nickname]; |
|||
|
|||
return $this->httpPostJson( |
|||
'cgi-bin/wxverify/checkwxverifynickname', $params); |
|||
} |
|||
|
|||
/** |
|||
* 查询小程序是否可被搜索. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getSearchStatus() |
|||
{ |
|||
return $this->httpGet('wxa/getwxasearchstatus'); |
|||
} |
|||
|
|||
/** |
|||
* 设置小程序可被搜素. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setSearchable() |
|||
{ |
|||
return $this->httpPostJson('wxa/changewxasearchstatus', [ |
|||
'status' => 0, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 设置小程序不可被搜素. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setUnsearchable() |
|||
{ |
|||
return $this->httpPostJson('wxa/changewxasearchstatus', [ |
|||
'status' => 1, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 获取展示的公众号信息. |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getDisplayedOfficialAccount() |
|||
{ |
|||
return $this->httpGet('wxa/getshowwxaitem'); |
|||
} |
|||
|
|||
/** |
|||
* 设置展示的公众号. |
|||
* |
|||
* @param string|bool $appid |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setDisplayedOfficialAccount($appid) |
|||
{ |
|||
return $this->httpPostJson('wxa/updateshowwxaitem', [ |
|||
'appid' => $appid ?: null, |
|||
'wxa_subscribe_biz_flag' => $appid ? 1 : 0, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 获取可以用来设置的公众号列表. |
|||
* |
|||
* @param int $page |
|||
* @param int $num |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getDisplayableOfficialAccounts(int $page, int $num) |
|||
{ |
|||
return $this->httpGet('wxa/getwxamplinkforshow', [ |
|||
'page' => $page, |
|||
'num' => $num, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Setting; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['setting'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author caikeal <caiyuezhang@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* 绑定小程序体验者. |
|||
* |
|||
* @param string $wechatId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function bind(string $wechatId) |
|||
{ |
|||
return $this->httpPostJson('wxa/bind_tester', [ |
|||
'wechatid' => $wechatId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 解绑小程序体验者. |
|||
* |
|||
* @param string $wechatId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function unbind(string $wechatId) |
|||
{ |
|||
return $this->httpPostJson('wxa/unbind_tester', [ |
|||
'wechatid' => $wechatId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 获取体验者列表. |
|||
* |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list() |
|||
{ |
|||
return $this->httpPostJson('wxa/memberauth', [ |
|||
'action' => 'get_experiencer', |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Tester; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['tester'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Account; |
|||
|
|||
use EasyWeChat\Kernel\ServiceContainer; |
|||
use EasyWeChat\OpenPlatform\Application; |
|||
use EasyWeChat\OpenPlatform\Authorizer\Aggregate\Account\Client as BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author Keal <caiyuezhang@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @var \EasyWeChat\OpenPlatform\Application |
|||
*/ |
|||
protected $component; |
|||
|
|||
/** |
|||
* Client constructor. |
|||
* |
|||
* @param \EasyWeChat\Kernel\ServiceContainer $app |
|||
* @param \EasyWeChat\OpenPlatform\Application $component |
|||
*/ |
|||
public function __construct(ServiceContainer $app, Application $component) |
|||
{ |
|||
parent::__construct($app); |
|||
|
|||
$this->component = $component; |
|||
} |
|||
|
|||
/** |
|||
* 从第三方平台跳转至微信公众平台授权注册页面, 授权注册小程序. |
|||
* |
|||
* @param string $callbackUrl |
|||
* @param bool $copyWxVerify |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getFastRegistrationUrl(string $callbackUrl, bool $copyWxVerify = true): string |
|||
{ |
|||
$queries = [ |
|||
'copy_wx_verify' => $copyWxVerify, |
|||
'component_appid' => $this->component['config']['app_id'], |
|||
'appid' => $this->app['config']['app_id'], |
|||
'redirect_uri' => $callbackUrl, |
|||
]; |
|||
|
|||
return 'https://mp.weixin.qq.com/cgi-bin/fastregisterauth?'.http_build_query($queries); |
|||
} |
|||
|
|||
/** |
|||
* 小程序快速注册. |
|||
* |
|||
* @param string $ticket |
|||
* |
|||
* @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 $ticket) |
|||
{ |
|||
$params = [ |
|||
'ticket' => $ticket, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/account/fastregister', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\OfficialAccount; |
|||
|
|||
use EasyWeChat\OfficialAccount\Application as OfficialAccount; |
|||
use EasyWeChat\OpenPlatform\Authorizer\Aggregate\AggregateServiceProvider; |
|||
|
|||
/** |
|||
* Class Application. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
* |
|||
* @property \EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\Account\Client $account |
|||
* @property \EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\MiniProgram\Client $mini_program |
|||
*/ |
|||
class Application extends OfficialAccount |
|||
{ |
|||
/** |
|||
* Application constructor. |
|||
* |
|||
* @param array $config |
|||
* @param array $prepends |
|||
*/ |
|||
public function __construct(array $config = [], array $prepends = []) |
|||
{ |
|||
parent::__construct($config, $prepends); |
|||
|
|||
$providers = [ |
|||
AggregateServiceProvider::class, |
|||
MiniProgram\ServiceProvider::class, |
|||
]; |
|||
|
|||
foreach ($providers as $provider) { |
|||
$this->register(new $provider()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\MiniProgram; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author Keal <caiyuezhang@gmail.com> |
|||
*/ |
|||
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 list() |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/wxopen/wxamplinkget'); |
|||
} |
|||
|
|||
/** |
|||
* 关联小程序. |
|||
* |
|||
* @param string $appId |
|||
* @param bool $notifyUsers |
|||
* @param bool $showProfile |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function link(string $appId, bool $notifyUsers = true, bool $showProfile = false) |
|||
{ |
|||
$params = [ |
|||
'appid' => $appId, |
|||
'notify_users' => (string) $notifyUsers, |
|||
'show_profile' => (string) $showProfile, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/wxopen/wxamplink', $params); |
|||
} |
|||
|
|||
/** |
|||
* 解除已关联的小程序. |
|||
* |
|||
* @param string $appId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function unlink(string $appId) |
|||
{ |
|||
$params = [ |
|||
'appid' => $appId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/wxopen/wxampunlink', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\MiniProgram; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['mini_program'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\OfficialAccount\OAuth; |
|||
|
|||
use EasyWeChat\OpenPlatform\Application; |
|||
use Overtrue\Socialite\WeChatComponentInterface; |
|||
|
|||
/** |
|||
* Class ComponentDelegate. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ComponentDelegate implements WeChatComponentInterface |
|||
{ |
|||
/** |
|||
* @var \EasyWeChat\OpenPlatform\Application |
|||
*/ |
|||
protected $app; |
|||
|
|||
/** |
|||
* ComponentDelegate Constructor. |
|||
* |
|||
* @param \EasyWeChat\OpenPlatform\Application $app |
|||
*/ |
|||
public function __construct(Application $app) |
|||
{ |
|||
$this->app = $app; |
|||
} |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
public function getAppId() |
|||
{ |
|||
return $this->app['config']['app_id']; |
|||
} |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
public function getToken() |
|||
{ |
|||
return $this->app['access_token']->getToken()['component_access_token']; |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Authorizer\Server; |
|||
|
|||
use EasyWeChat\Kernel\ServerGuard; |
|||
|
|||
/** |
|||
* Class Guard. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Guard extends ServerGuard |
|||
{ |
|||
/** |
|||
* Get token from OpenPlatform encryptor. |
|||
* |
|||
* @return string |
|||
*/ |
|||
protected function getToken() |
|||
{ |
|||
return $this->app['encryptor']->getToken(); |
|||
} |
|||
} |
|||
@ -0,0 +1,166 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Base; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get authorization info. |
|||
* |
|||
* @param string|null $authCode |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function handleAuthorize(string $authCode = null) |
|||
{ |
|||
$params = [ |
|||
'component_appid' => $this->app['config']['app_id'], |
|||
'authorization_code' => $authCode ?? $this->app['request']->get('auth_code'), |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/component/api_query_auth', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get authorizer info. |
|||
* |
|||
* @param string $appId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getAuthorizer(string $appId) |
|||
{ |
|||
$params = [ |
|||
'component_appid' => $this->app['config']['app_id'], |
|||
'authorizer_appid' => $appId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/component/api_get_authorizer_info', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get options. |
|||
* |
|||
* @param string $appId |
|||
* @param string $name |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getAuthorizerOption(string $appId, string $name) |
|||
{ |
|||
$params = [ |
|||
'component_appid' => $this->app['config']['app_id'], |
|||
'authorizer_appid' => $appId, |
|||
'option_name' => $name, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/component/api_get_authorizer_option', $params); |
|||
} |
|||
|
|||
/** |
|||
* Set authorizer option. |
|||
* |
|||
* @param string $appId |
|||
* @param string $name |
|||
* @param string $value |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function setAuthorizerOption(string $appId, string $name, string $value) |
|||
{ |
|||
$params = [ |
|||
'component_appid' => $this->app['config']['app_id'], |
|||
'authorizer_appid' => $appId, |
|||
'option_name' => $name, |
|||
'option_value' => $value, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/component/api_set_authorizer_option', $params); |
|||
} |
|||
|
|||
/** |
|||
* Get authorizer list. |
|||
* |
|||
* @param int $offset |
|||
* @param int $count |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getAuthorizers($offset = 0, $count = 500) |
|||
{ |
|||
$params = [ |
|||
'component_appid' => $this->app['config']['app_id'], |
|||
'offset' => $offset, |
|||
'count' => $count, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/component/api_get_authorizer_list', $params); |
|||
} |
|||
|
|||
/** |
|||
* Create pre-authorization code. |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function createPreAuthorizationCode() |
|||
{ |
|||
$params = [ |
|||
'component_appid' => $this->app['config']['app_id'], |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/component/api_create_preauthcode', $params); |
|||
} |
|||
|
|||
/** |
|||
* OpenPlatform Clear quota. |
|||
* |
|||
* @see https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318587 |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function clearQuota() |
|||
{ |
|||
$params = [ |
|||
'component_appid' => $this->app['config']['app_id'], |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/component/clear_quota', $params); |
|||
} |
|||
} |
|||
@ -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\OpenPlatform\Base; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['base'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,86 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\CodeTemplate; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author caikeal <caiyuezhang@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* 获取草稿箱内的所有临时代码草稿 |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getDrafts() |
|||
{ |
|||
return $this->httpGet('wxa/gettemplatedraftlist'); |
|||
} |
|||
|
|||
/** |
|||
* 将草稿箱的草稿选为小程序代码模版. |
|||
* |
|||
* @param int $draftId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function createFromDraft(int $draftId) |
|||
{ |
|||
$params = [ |
|||
'draft_id' => $draftId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('wxa/addtotemplate', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取代码模版库中的所有小程序代码模版. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function list() |
|||
{ |
|||
return $this->httpGet('wxa/gettemplatelist'); |
|||
} |
|||
|
|||
/** |
|||
* 删除指定小程序代码模版. |
|||
* |
|||
* @param string $templateId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete($templateId) |
|||
{ |
|||
$params = [ |
|||
'template_id' => $templateId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('wxa/deletetemplate', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\CodeTemplate; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['code_template'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -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\OpenPlatform\Component; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author dudashuang <dudashuang1222@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* 通过法人微信快速创建小程序. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function registerMiniProgram(array $params) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/component/fastregisterweapp', $params, ['action' => 'create']); |
|||
} |
|||
|
|||
/** |
|||
* 查询创建任务状态. |
|||
* |
|||
* @param string $companyName |
|||
* @param string $legalPersonaWechat |
|||
* @param string $legalPersonaName |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getRegistrationStatus(string $companyName, string $legalPersonaWechat, string $legalPersonaName) |
|||
{ |
|||
$params = [ |
|||
'name' => $companyName, |
|||
'legal_persona_wechat' => $legalPersonaWechat, |
|||
'legal_persona_name' => $legalPersonaName, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/component/fastregisterweapp', $params, ['action' => 'search']); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Component; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['component'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Server; |
|||
|
|||
use function EasyWeChat\Kernel\data_get; |
|||
use EasyWeChat\Kernel\ServerGuard; |
|||
use EasyWeChat\OpenPlatform\Server\Handlers\Authorized; |
|||
use EasyWeChat\OpenPlatform\Server\Handlers\Unauthorized; |
|||
use EasyWeChat\OpenPlatform\Server\Handlers\UpdateAuthorized; |
|||
use EasyWeChat\OpenPlatform\Server\Handlers\VerifyTicketRefreshed; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
|
|||
/** |
|||
* Class Guard. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Guard extends ServerGuard |
|||
{ |
|||
const EVENT_AUTHORIZED = 'authorized'; |
|||
const EVENT_UNAUTHORIZED = 'unauthorized'; |
|||
const EVENT_UPDATE_AUTHORIZED = 'updateauthorized'; |
|||
const EVENT_COMPONENT_VERIFY_TICKET = 'component_verify_ticket'; |
|||
const EVENT_THIRD_FAST_REGISTERED = 'notify_third_fasteregister'; |
|||
|
|||
/** |
|||
* @return \Symfony\Component\HttpFoundation\Response |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\BadRequestException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
protected function resolve(): Response |
|||
{ |
|||
$this->registerHandlers(); |
|||
|
|||
$message = $this->getMessage(); |
|||
|
|||
if ($infoType = data_get($message, 'InfoType')) { |
|||
$this->dispatch($infoType, $message); |
|||
} |
|||
|
|||
return new Response(static::SUCCESS_EMPTY_RESPONSE); |
|||
} |
|||
|
|||
/** |
|||
* Register event handlers. |
|||
*/ |
|||
protected function registerHandlers() |
|||
{ |
|||
$this->on(self::EVENT_AUTHORIZED, Authorized::class); |
|||
$this->on(self::EVENT_UNAUTHORIZED, Unauthorized::class); |
|||
$this->on(self::EVENT_UPDATE_AUTHORIZED, UpdateAuthorized::class); |
|||
$this->on(self::EVENT_COMPONENT_VERIFY_TICKET, VerifyTicketRefreshed::class); |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Server\Handlers; |
|||
|
|||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface; |
|||
|
|||
/** |
|||
* Class Authorized. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Authorized implements EventHandlerInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function handle($payload = null) |
|||
{ |
|||
// Do nothing for the time being. |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Server\Handlers; |
|||
|
|||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface; |
|||
|
|||
/** |
|||
* Class Unauthorized. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Unauthorized implements EventHandlerInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function handle($payload = null) |
|||
{ |
|||
// Do nothing for the time being. |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Server\Handlers; |
|||
|
|||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface; |
|||
|
|||
/** |
|||
* Class UpdateAuthorized. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class UpdateAuthorized implements EventHandlerInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function handle($payload = null) |
|||
{ |
|||
// Do nothing for the time being. |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Server\Handlers; |
|||
|
|||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface; |
|||
use EasyWeChat\OpenPlatform\Application; |
|||
|
|||
/** |
|||
* Class VerifyTicketRefreshed. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class VerifyTicketRefreshed implements EventHandlerInterface |
|||
{ |
|||
/** |
|||
* @var \EasyWeChat\OpenPlatform\Application |
|||
*/ |
|||
protected $app; |
|||
|
|||
/** |
|||
* Constructor. |
|||
* |
|||
* @param \EasyWeChat\OpenPlatform\Application $app |
|||
*/ |
|||
public function __construct(Application $app) |
|||
{ |
|||
$this->app = $app; |
|||
} |
|||
|
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function handle($payload = null) |
|||
{ |
|||
if (!empty($payload['ComponentVerifyTicket'])) { |
|||
$this->app['verify_ticket']->setTicket($payload['ComponentVerifyTicket']); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\OpenPlatform\Server; |
|||
|
|||
use EasyWeChat\Kernel\Encryptor; |
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['encryptor'] = function ($app) { |
|||
return new Encryptor( |
|||
$app['config']['app_id'], |
|||
$app['config']['token'], |
|||
$app['config']['aes_key'] |
|||
); |
|||
}; |
|||
|
|||
$app['server'] = function ($app) { |
|||
return new Guard($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,206 @@ |
|||
<?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\Payment; |
|||
|
|||
use Closure; |
|||
use EasyWeChat\BasicService; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
use EasyWeChat\Kernel\ServiceContainer; |
|||
use EasyWeChat\Kernel\Support; |
|||
use EasyWeChat\OfficialAccount; |
|||
|
|||
/** |
|||
* Class Application. |
|||
* |
|||
* @property \EasyWeChat\Payment\Bill\Client $bill |
|||
* @property \EasyWeChat\Payment\Jssdk\Client $jssdk |
|||
* @property \EasyWeChat\Payment\Order\Client $order |
|||
* @property \EasyWeChat\Payment\Refund\Client $refund |
|||
* @property \EasyWeChat\Payment\Coupon\Client $coupon |
|||
* @property \EasyWeChat\Payment\Reverse\Client $reverse |
|||
* @property \EasyWeChat\Payment\Redpack\Client $redpack |
|||
* @property \EasyWeChat\BasicService\Url\Client $url |
|||
* @property \EasyWeChat\Payment\Transfer\Client $transfer |
|||
* @property \EasyWeChat\Payment\Security\Client $security |
|||
* @property \EasyWeChat\Payment\ProfitSharing\Client $profit_sharing |
|||
* @property \EasyWeChat\OfficialAccount\Auth\AccessToken $access_token |
|||
* |
|||
* @method mixed pay(array $attributes) |
|||
* @method mixed authCodeToOpenid(string $authCode) |
|||
*/ |
|||
class Application extends ServiceContainer |
|||
{ |
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $providers = [ |
|||
OfficialAccount\Auth\ServiceProvider::class, |
|||
BasicService\Url\ServiceProvider::class, |
|||
Base\ServiceProvider::class, |
|||
Bill\ServiceProvider::class, |
|||
Coupon\ServiceProvider::class, |
|||
Jssdk\ServiceProvider::class, |
|||
Merchant\ServiceProvider::class, |
|||
Order\ServiceProvider::class, |
|||
Redpack\ServiceProvider::class, |
|||
Refund\ServiceProvider::class, |
|||
Reverse\ServiceProvider::class, |
|||
Sandbox\ServiceProvider::class, |
|||
Transfer\ServiceProvider::class, |
|||
Security\ServiceProvider::class, |
|||
ProfitSharing\ServiceProvider::class, |
|||
]; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $defaultConfig = [ |
|||
'http' => [ |
|||
'base_uri' => 'https://api.mch.weixin.qq.com/', |
|||
], |
|||
]; |
|||
|
|||
/** |
|||
* Build payment scheme for product. |
|||
* |
|||
* @param string $productId |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function scheme(string $productId): string |
|||
{ |
|||
$params = [ |
|||
'appid' => $this['config']->app_id, |
|||
'mch_id' => $this['config']->mch_id, |
|||
'time_stamp' => time(), |
|||
'nonce_str' => uniqid(), |
|||
'product_id' => $productId, |
|||
]; |
|||
|
|||
$params['sign'] = Support\generate_sign($params, $this['config']->key); |
|||
|
|||
return 'weixin://wxpay/bizpayurl?'.http_build_query($params); |
|||
} |
|||
|
|||
/** |
|||
* @param string $codeUrl |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function codeUrlScheme(string $codeUrl) |
|||
{ |
|||
return \sprintf('weixin://wxpay/bizpayurl?sr=%s', $codeUrl); |
|||
} |
|||
|
|||
/** |
|||
* @param \Closure $closure |
|||
* |
|||
* @return \Symfony\Component\HttpFoundation\Response |
|||
* |
|||
* @codeCoverageIgnore |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\Exception |
|||
*/ |
|||
public function handlePaidNotify(Closure $closure) |
|||
{ |
|||
return (new Notify\Paid($this))->handle($closure); |
|||
} |
|||
|
|||
/** |
|||
* @param \Closure $closure |
|||
* |
|||
* @return \Symfony\Component\HttpFoundation\Response |
|||
* |
|||
* @codeCoverageIgnore |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\Exception |
|||
*/ |
|||
public function handleRefundedNotify(Closure $closure) |
|||
{ |
|||
return (new Notify\Refunded($this))->handle($closure); |
|||
} |
|||
|
|||
/** |
|||
* @param \Closure $closure |
|||
* |
|||
* @return \Symfony\Component\HttpFoundation\Response |
|||
* |
|||
* @codeCoverageIgnore |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\Exception |
|||
*/ |
|||
public function handleScannedNotify(Closure $closure) |
|||
{ |
|||
return (new Notify\Scanned($this))->handle($closure); |
|||
} |
|||
|
|||
/** |
|||
* Set sub-merchant. |
|||
* |
|||
* @param string $mchId |
|||
* @param string|null $appId |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function setSubMerchant(string $mchId, string $appId = null) |
|||
{ |
|||
$this['config']->set('sub_mch_id', $mchId); |
|||
$this['config']->set('sub_appid', $appId); |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* @return bool |
|||
*/ |
|||
public function inSandbox(): bool |
|||
{ |
|||
return (bool) $this['config']->get('sandbox'); |
|||
} |
|||
|
|||
/** |
|||
* @param string|null $endpoint |
|||
* |
|||
* @return string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
public function getKey(string $endpoint = null) |
|||
{ |
|||
if ('sandboxnew/pay/getsignkey' === $endpoint) { |
|||
return $this['config']->key; |
|||
} |
|||
|
|||
$key = $this->inSandbox() ? $this['sandbox']->getKey() : $this['config']->key; |
|||
|
|||
if (empty($key)) { |
|||
throw new InvalidArgumentException('config key should not empty.'); |
|||
} |
|||
|
|||
if (32 !== strlen($key)) { |
|||
throw new InvalidArgumentException(sprintf("'%s' should be 32 chars length.", $key)); |
|||
} |
|||
|
|||
return $key; |
|||
} |
|||
|
|||
/** |
|||
* @param string $name |
|||
* @param array $arguments |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function __call($name, $arguments) |
|||
{ |
|||
return call_user_func_array([$this['base'], $name], $arguments); |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
<?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\Payment\Base; |
|||
|
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Pay the order. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function pay(array $params) |
|||
{ |
|||
$params['appid'] = $this->app['config']->app_id; |
|||
|
|||
return $this->request($this->wrap('pay/micropay'), $params); |
|||
} |
|||
|
|||
/** |
|||
* Get openid by auth code. |
|||
* |
|||
* @param string $authCode |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function authCodeToOpenid(string $authCode) |
|||
{ |
|||
return $this->request('tools/authcodetoopenid', [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'auth_code' => $authCode, |
|||
]); |
|||
} |
|||
} |
|||
@ -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\Payment\Base; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['base'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<?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\Payment\Bill; |
|||
|
|||
use EasyWeChat\Kernel\Http\StreamResponse; |
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Download bill history as a table file. |
|||
* |
|||
* @param string $date |
|||
* @param string $type |
|||
* @param array $optional |
|||
* |
|||
* @return \EasyWeChat\Kernel\Http\StreamResponse|\Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get(string $date, string $type = 'ALL', array $optional = []) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'bill_date' => $date, |
|||
'bill_type' => $type, |
|||
] + $optional; |
|||
|
|||
$response = $this->requestRaw($this->wrap('pay/downloadbill'), $params); |
|||
|
|||
if (0 === strpos($response->getBody()->getContents(), '<xml>')) { |
|||
return $this->castResponseToType($response, $this->app['config']->get('response_type')); |
|||
} |
|||
|
|||
return StreamResponse::buildFromPsrResponse($response); |
|||
} |
|||
} |
|||
@ -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\Payment\Bill; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['bill'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
<?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\Payment\Coupon; |
|||
|
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author tianyong90 <412039588@qq.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* send a cash coupon. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function send(array $params) |
|||
{ |
|||
$params['appid'] = $this->app['config']->app_id; |
|||
$params['openid_count'] = 1; |
|||
|
|||
return $this->safeRequest('mmpaymkttransfers/send_coupon', $params); |
|||
} |
|||
|
|||
/** |
|||
* query a coupon stock. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function stock(array $params) |
|||
{ |
|||
$params['appid'] = $this->app['config']->app_id; |
|||
|
|||
return $this->request('mmpaymkttransfers/query_coupon_stock', $params); |
|||
} |
|||
|
|||
/** |
|||
* query a info of coupon. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function info(array $params) |
|||
{ |
|||
$params['appid'] = $this->app['config']->app_id; |
|||
|
|||
return $this->request('mmpaymkttransfers/querycouponsinfo', $params); |
|||
} |
|||
} |
|||
@ -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\Payment\Coupon; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['coupon'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,135 @@ |
|||
<?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\Payment\Jssdk; |
|||
|
|||
use EasyWeChat\BasicService\Jssdk\Client as JssdkClient; |
|||
use EasyWeChat\Kernel\Support; |
|||
use Overtrue\Socialite\AccessTokenInterface; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends JssdkClient |
|||
{ |
|||
/** |
|||
* [WeixinJSBridge] Generate js config for payment. |
|||
* |
|||
* <pre> |
|||
* WeixinJSBridge.invoke( |
|||
* 'getBrandWCPayRequest', |
|||
* ... |
|||
* ); |
|||
* </pre> |
|||
* |
|||
* @param string $prepayId |
|||
* @param bool $json |
|||
* |
|||
* @return string|array |
|||
*/ |
|||
public function bridgeConfig(string $prepayId, bool $json = true) |
|||
{ |
|||
$params = [ |
|||
'appId' => $this->app['config']->sub_appid ?: $this->app['config']->app_id, |
|||
'timeStamp' => strval(time()), |
|||
'nonceStr' => uniqid(), |
|||
'package' => "prepay_id=$prepayId", |
|||
'signType' => 'MD5', |
|||
]; |
|||
|
|||
$params['paySign'] = Support\generate_sign($params, $this->app['config']->key, 'md5'); |
|||
|
|||
return $json ? json_encode($params) : $params; |
|||
} |
|||
|
|||
/** |
|||
* [JSSDK] Generate js config for payment. |
|||
* |
|||
* <pre> |
|||
* wx.chooseWXPay({...}); |
|||
* </pre> |
|||
* |
|||
* @param string $prepayId |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function sdkConfig(string $prepayId): array |
|||
{ |
|||
$config = $this->bridgeConfig($prepayId, false); |
|||
|
|||
$config['timestamp'] = $config['timeStamp']; |
|||
unset($config['timeStamp']); |
|||
|
|||
return $config; |
|||
} |
|||
|
|||
/** |
|||
* Generate app payment parameters. |
|||
* |
|||
* @param string $prepayId |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function appConfig(string $prepayId): array |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'partnerid' => $this->app['config']->mch_id, |
|||
'prepayid' => $prepayId, |
|||
'noncestr' => uniqid(), |
|||
'timestamp' => time(), |
|||
'package' => 'Sign=WXPay', |
|||
]; |
|||
|
|||
$params['sign'] = Support\generate_sign($params, $this->app['config']->key); |
|||
|
|||
return $params; |
|||
} |
|||
|
|||
/** |
|||
* Generate js config for share user address. |
|||
* |
|||
* @param string|\Overtrue\Socialite\AccessTokenInterface $accessToken |
|||
* @param bool $json |
|||
* |
|||
* @return string|array |
|||
*/ |
|||
public function shareAddressConfig($accessToken, bool $json = true) |
|||
{ |
|||
if ($accessToken instanceof AccessTokenInterface) { |
|||
$accessToken = $accessToken->getToken(); |
|||
} |
|||
|
|||
$params = [ |
|||
'appId' => $this->app['config']->app_id, |
|||
'scope' => 'jsapi_address', |
|||
'timeStamp' => strval(time()), |
|||
'nonceStr' => uniqid(), |
|||
'signType' => 'SHA1', |
|||
]; |
|||
|
|||
$signParams = [ |
|||
'appid' => $params['appId'], |
|||
'url' => $this->getUrl(), |
|||
'timestamp' => $params['timeStamp'], |
|||
'noncestr' => $params['nonceStr'], |
|||
'accesstoken' => strval($accessToken), |
|||
]; |
|||
|
|||
ksort($signParams); |
|||
|
|||
$params['addrSign'] = sha1(urldecode(http_build_query($signParams))); |
|||
|
|||
return $json ? json_encode($params) : $params; |
|||
} |
|||
} |
|||
@ -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\Payment\Jssdk; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['jssdk'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,190 @@ |
|||
<?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\Payment\Kernel; |
|||
|
|||
use EasyWeChat\Kernel\Support; |
|||
use EasyWeChat\Kernel\Traits\HasHttpRequests; |
|||
use EasyWeChat\Payment\Application; |
|||
use GuzzleHttp\MessageFormatter; |
|||
use GuzzleHttp\Middleware; |
|||
use Psr\Http\Message\ResponseInterface; |
|||
|
|||
/** |
|||
* Class BaseClient. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class BaseClient |
|||
{ |
|||
use HasHttpRequests { request as performRequest; } |
|||
|
|||
/** |
|||
* @var \EasyWeChat\Payment\Application |
|||
*/ |
|||
protected $app; |
|||
|
|||
/** |
|||
* Constructor. |
|||
* |
|||
* @param \EasyWeChat\Payment\Application $app |
|||
*/ |
|||
public function __construct(Application $app) |
|||
{ |
|||
$this->app = $app; |
|||
|
|||
$this->setHttpClient($this->app['http_client']); |
|||
} |
|||
|
|||
/** |
|||
* Extra request params. |
|||
* |
|||
* @return array |
|||
*/ |
|||
protected function prepends() |
|||
{ |
|||
return []; |
|||
} |
|||
|
|||
/** |
|||
* Make a API request. |
|||
* |
|||
* @param string $endpoint |
|||
* @param array $params |
|||
* @param string $method |
|||
* @param array $options |
|||
* @param bool $returnResponse |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function request(string $endpoint, array $params = [], $method = 'post', array $options = [], $returnResponse = false) |
|||
{ |
|||
$base = [ |
|||
'mch_id' => $this->app['config']['mch_id'], |
|||
'nonce_str' => uniqid(), |
|||
'sub_mch_id' => $this->app['config']['sub_mch_id'], |
|||
'sub_appid' => $this->app['config']['sub_appid'], |
|||
]; |
|||
|
|||
$params = array_filter(array_merge($base, $this->prepends(), $params), 'strlen'); |
|||
|
|||
$secretKey = $this->app->getKey($endpoint); |
|||
|
|||
$encryptMethod = Support\get_encrypt_method(Support\Arr::get($params, 'sign_type', 'MD5'), $secretKey); |
|||
|
|||
$params['sign'] = Support\generate_sign($params, $secretKey, $encryptMethod); |
|||
|
|||
$options = array_merge([ |
|||
'body' => Support\XML::build($params), |
|||
], $options); |
|||
|
|||
$this->pushMiddleware($this->logMiddleware(), 'log'); |
|||
|
|||
$response = $this->performRequest($endpoint, $method, $options); |
|||
|
|||
return $returnResponse ? $response : $this->castResponseToType($response, $this->app->config->get('response_type')); |
|||
} |
|||
|
|||
/** |
|||
* Log the request. |
|||
* |
|||
* @return \Closure |
|||
*/ |
|||
protected function logMiddleware() |
|||
{ |
|||
$formatter = new MessageFormatter($this->app['config']['http.log_template'] ?? MessageFormatter::DEBUG); |
|||
|
|||
return Middleware::log($this->app['logger'], $formatter); |
|||
} |
|||
|
|||
/** |
|||
* Make a request and return raw response. |
|||
* |
|||
* @param string $endpoint |
|||
* @param array $params |
|||
* @param string $method |
|||
* @param array $options |
|||
* |
|||
* @return ResponseInterface |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function requestRaw(string $endpoint, array $params = [], $method = 'post', array $options = []) |
|||
{ |
|||
/** @var ResponseInterface $response */ |
|||
$response = $this->request($endpoint, $params, $method, $options, true); |
|||
|
|||
return $response; |
|||
} |
|||
|
|||
/** |
|||
* Make a request and return an array. |
|||
* |
|||
* @param string $endpoint |
|||
* @param array $params |
|||
* @param string $method |
|||
* @param array $options |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function requestArray(string $endpoint, array $params = [], $method = 'post', array $options = []): array |
|||
{ |
|||
$response = $this->requestRaw($endpoint, $params, $method, $options); |
|||
|
|||
return $this->castResponseToType($response, 'array'); |
|||
} |
|||
|
|||
/** |
|||
* Request with SSL. |
|||
* |
|||
* @param string $endpoint |
|||
* @param array $params |
|||
* @param string $method |
|||
* @param array $options |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function safeRequest($endpoint, array $params, $method = 'post', array $options = []) |
|||
{ |
|||
$options = array_merge([ |
|||
'cert' => $this->app['config']->get('cert_path'), |
|||
'ssl_key' => $this->app['config']->get('key_path'), |
|||
], $options); |
|||
|
|||
return $this->request($endpoint, $params, $method, $options); |
|||
} |
|||
|
|||
/** |
|||
* Wrapping an API endpoint. |
|||
* |
|||
* @param string $endpoint |
|||
* |
|||
* @return string |
|||
*/ |
|||
protected function wrap(string $endpoint): string |
|||
{ |
|||
return $this->app->inSandbox() ? "sandboxnew/{$endpoint}" : $endpoint; |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
<?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\Payment\Kernel\Exceptions; |
|||
|
|||
use EasyWeChat\Kernel\Exceptions\Exception; |
|||
|
|||
class InvalidSignException extends Exception |
|||
{ |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
<?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\Payment\Kernel\Exceptions; |
|||
|
|||
use EasyWeChat\Kernel\Exceptions\Exception; |
|||
|
|||
class SandboxException extends Exception |
|||
{ |
|||
} |
|||
@ -0,0 +1,94 @@ |
|||
<?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\Payment\Merchant; |
|||
|
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Add sub-merchant. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function addSubMerchant(array $params) |
|||
{ |
|||
return $this->manage($params, ['action' => 'add']); |
|||
} |
|||
|
|||
/** |
|||
* Query sub-merchant by merchant id. |
|||
* |
|||
* @param string $id |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function querySubMerchantByMerchantId(string $id) |
|||
{ |
|||
$params = [ |
|||
'micro_mch_id' => $id, |
|||
]; |
|||
|
|||
return $this->manage($params, ['action' => 'query']); |
|||
} |
|||
|
|||
/** |
|||
* Query sub-merchant by wechat id. |
|||
* |
|||
* @param string $id |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function querySubMerchantByWeChatId(string $id) |
|||
{ |
|||
$params = [ |
|||
'recipient_wechatid' => $id, |
|||
]; |
|||
|
|||
return $this->manage($params, ['action' => 'query']); |
|||
} |
|||
|
|||
/** |
|||
* @param array $params |
|||
* @param array $query |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function manage(array $params, array $query) |
|||
{ |
|||
$params = array_merge($params, [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'nonce_str' => '', |
|||
'sub_mch_id' => '', |
|||
'sub_appid' => '', |
|||
]); |
|||
|
|||
return $this->safeRequest('secapi/mch/submchmanage', $params, 'post', compact('query')); |
|||
} |
|||
} |
|||
@ -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\Payment\Merchant; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['merchant'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,201 @@ |
|||
<?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\Payment\Notify; |
|||
|
|||
use Closure; |
|||
use EasyWeChat\Kernel\Exceptions\Exception; |
|||
use EasyWeChat\Kernel\Support; |
|||
use EasyWeChat\Kernel\Support\XML; |
|||
use EasyWeChat\Payment\Kernel\Exceptions\InvalidSignException; |
|||
use Symfony\Component\HttpFoundation\Response; |
|||
|
|||
abstract class Handler |
|||
{ |
|||
const SUCCESS = 'SUCCESS'; |
|||
const FAIL = 'FAIL'; |
|||
|
|||
/** |
|||
* @var \EasyWeChat\Payment\Application |
|||
*/ |
|||
protected $app; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $message; |
|||
|
|||
/** |
|||
* @var string|null |
|||
*/ |
|||
protected $fail; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $attributes = []; |
|||
|
|||
/** |
|||
* Check sign. |
|||
* If failed, throws an exception. |
|||
* |
|||
* @var bool |
|||
*/ |
|||
protected $check = true; |
|||
|
|||
/** |
|||
* Respond with sign. |
|||
* |
|||
* @var bool |
|||
*/ |
|||
protected $sign = false; |
|||
|
|||
/** |
|||
* @param \EasyWeChat\Payment\Application $app |
|||
*/ |
|||
public function __construct($app) |
|||
{ |
|||
$this->app = $app; |
|||
} |
|||
|
|||
/** |
|||
* Handle incoming notify. |
|||
* |
|||
* @param \Closure $closure |
|||
* |
|||
* @return \Symfony\Component\HttpFoundation\Response |
|||
*/ |
|||
abstract public function handle(Closure $closure); |
|||
|
|||
/** |
|||
* @param string $message |
|||
*/ |
|||
public function fail(string $message) |
|||
{ |
|||
$this->fail = $message; |
|||
} |
|||
|
|||
/** |
|||
* @param array $attributes |
|||
* @param bool $sign |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function respondWith(array $attributes, bool $sign = false) |
|||
{ |
|||
$this->attributes = $attributes; |
|||
$this->sign = $sign; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Build xml and return the response to WeChat. |
|||
* |
|||
* @return \Symfony\Component\HttpFoundation\Response |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
public function toResponse(): Response |
|||
{ |
|||
$base = [ |
|||
'return_code' => is_null($this->fail) ? static::SUCCESS : static::FAIL, |
|||
'return_msg' => $this->fail, |
|||
]; |
|||
|
|||
$attributes = array_merge($base, $this->attributes); |
|||
|
|||
if ($this->sign) { |
|||
$attributes['sign'] = Support\generate_sign($attributes, $this->app->getKey()); |
|||
} |
|||
|
|||
return new Response(XML::build($attributes)); |
|||
} |
|||
|
|||
/** |
|||
* Return the notify message from request. |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\Exception |
|||
*/ |
|||
public function getMessage(): array |
|||
{ |
|||
if (!empty($this->message)) { |
|||
return $this->message; |
|||
} |
|||
|
|||
try { |
|||
$message = XML::parse(strval($this->app['request']->getContent())); |
|||
} catch (\Throwable $e) { |
|||
throw new Exception('Invalid request XML: '.$e->getMessage(), 400); |
|||
} |
|||
|
|||
if (!is_array($message) || empty($message)) { |
|||
throw new Exception('Invalid request XML.', 400); |
|||
} |
|||
|
|||
if ($this->check) { |
|||
$this->validate($message); |
|||
} |
|||
|
|||
return $this->message = $message; |
|||
} |
|||
|
|||
/** |
|||
* Decrypt message. |
|||
* |
|||
* @param string $key |
|||
* |
|||
* @return string|null |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\Exception |
|||
*/ |
|||
public function decryptMessage(string $key) |
|||
{ |
|||
$message = $this->getMessage(); |
|||
if (empty($message[$key])) { |
|||
return null; |
|||
} |
|||
|
|||
return Support\AES::decrypt( |
|||
base64_decode($message[$key], true), md5($this->app['config']->key), '', OPENSSL_RAW_DATA, 'AES-256-ECB' |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Validate the request params. |
|||
* |
|||
* @param array $message |
|||
* |
|||
* @throws \EasyWeChat\Payment\Kernel\Exceptions\InvalidSignException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
protected function validate(array $message) |
|||
{ |
|||
$sign = $message['sign']; |
|||
unset($message['sign']); |
|||
|
|||
if (Support\generate_sign($message, $this->app->getKey()) !== $sign) { |
|||
throw new InvalidSignException(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @param mixed $result |
|||
*/ |
|||
protected function strict($result) |
|||
{ |
|||
if (true !== $result && is_null($this->fail)) { |
|||
$this->fail(strval($result)); |
|||
} |
|||
} |
|||
} |
|||
@ -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\Payment\Notify; |
|||
|
|||
use Closure; |
|||
|
|||
class Paid extends Handler |
|||
{ |
|||
/** |
|||
* @param \Closure $closure |
|||
* |
|||
* @return \Symfony\Component\HttpFoundation\Response |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\Exception |
|||
*/ |
|||
public function handle(Closure $closure) |
|||
{ |
|||
$this->strict( |
|||
\call_user_func($closure, $this->getMessage(), [$this, 'fail']) |
|||
); |
|||
|
|||
return $this->toResponse(); |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<?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\Payment\Notify; |
|||
|
|||
use Closure; |
|||
use EasyWeChat\Kernel\Support\XML; |
|||
|
|||
class Refunded extends Handler |
|||
{ |
|||
protected $check = false; |
|||
|
|||
/** |
|||
* @param \Closure $closure |
|||
* |
|||
* @return \Symfony\Component\HttpFoundation\Response |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\Exception |
|||
*/ |
|||
public function handle(Closure $closure) |
|||
{ |
|||
$this->strict( |
|||
\call_user_func($closure, $this->getMessage(), $this->reqInfo(), [$this, 'fail']) |
|||
); |
|||
|
|||
return $this->toResponse(); |
|||
} |
|||
|
|||
/** |
|||
* Decrypt the `req_info` from request message. |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\Exception |
|||
*/ |
|||
public function reqInfo() |
|||
{ |
|||
return XML::parse($this->decryptMessage('req_info')); |
|||
} |
|||
} |
|||
@ -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\Payment\Notify; |
|||
|
|||
use Closure; |
|||
|
|||
class Scanned extends Handler |
|||
{ |
|||
protected $check = false; |
|||
|
|||
/** |
|||
* @var string|null |
|||
*/ |
|||
protected $alert; |
|||
|
|||
/** |
|||
* @param string $message |
|||
*/ |
|||
public function alert(string $message) |
|||
{ |
|||
$this->alert = $message; |
|||
} |
|||
|
|||
/** |
|||
* @param \Closure $closure |
|||
* |
|||
* @return \Symfony\Component\HttpFoundation\Response |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\Exception |
|||
*/ |
|||
public function handle(Closure $closure) |
|||
{ |
|||
$result = \call_user_func($closure, $this->getMessage(), [$this, 'fail'], [$this, 'alert']); |
|||
|
|||
$attributes = [ |
|||
'result_code' => is_null($this->alert) && is_null($this->fail) ? static::SUCCESS : static::FAIL, |
|||
'err_code_des' => $this->alert, |
|||
]; |
|||
|
|||
if (is_null($this->alert) && is_string($result)) { |
|||
$attributes += [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'mch_id' => $this->app['config']->mch_id, |
|||
'nonce_str' => uniqid(), |
|||
'prepay_id' => $result, |
|||
]; |
|||
} |
|||
|
|||
return $this->respondWith($attributes, true)->toResponse(); |
|||
} |
|||
} |
|||
@ -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\Payment\Order; |
|||
|
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidConfigException; |
|||
use EasyWeChat\Kernel\Support; |
|||
use EasyWeChat\Kernel\Support\Collection; |
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
use Psr\Http\Message\ResponseInterface; |
|||
|
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Unify order. |
|||
* |
|||
* @param array $params |
|||
* @param bool $isContract |
|||
* |
|||
* @return ResponseInterface|Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function unify(array $params, $isContract = false) |
|||
{ |
|||
if (empty($params['spbill_create_ip'])) { |
|||
$params['spbill_create_ip'] = ('NATIVE' === $params['trade_type']) ? Support\get_server_ip() : Support\get_client_ip(); |
|||
} |
|||
|
|||
$params['appid'] = $this->app['config']->app_id; |
|||
$params['notify_url'] = $params['notify_url'] ?? $this->app['config']['notify_url']; |
|||
|
|||
if ($isContract) { |
|||
$params['contract_appid'] = $this->app['config']['app_id']; |
|||
$params['contract_mchid'] = $this->app['config']['mch_id']; |
|||
$params['request_serial'] = $params['request_serial'] ?? time(); |
|||
$params['contract_notify_url'] = $params['contract_notify_url'] ?? $this->app['config']['contract_notify_url']; |
|||
|
|||
return $this->request($this->wrap('pay/contractorder'), $params); |
|||
} |
|||
|
|||
return $this->request($this->wrap('pay/unifiedorder'), $params); |
|||
} |
|||
|
|||
/** |
|||
* Query order by out trade number. |
|||
* |
|||
* @param string $number |
|||
* |
|||
* @return ResponseInterface|Collection|array|object|string |
|||
* |
|||
* @throws InvalidArgumentException |
|||
* @throws InvalidConfigException |
|||
*/ |
|||
public function queryByOutTradeNumber(string $number) |
|||
{ |
|||
return $this->query([ |
|||
'out_trade_no' => $number, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* Query order by transaction id. |
|||
* |
|||
* @param string $transactionId |
|||
* |
|||
* @return ResponseInterface|Collection|array|object|string |
|||
* |
|||
* @throws InvalidArgumentException |
|||
* @throws InvalidConfigException |
|||
*/ |
|||
public function queryByTransactionId(string $transactionId) |
|||
{ |
|||
return $this->query([ |
|||
'transaction_id' => $transactionId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param array $params |
|||
* |
|||
* @return ResponseInterface|Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function query(array $params) |
|||
{ |
|||
$params['appid'] = $this->app['config']->app_id; |
|||
|
|||
return $this->request($this->wrap('pay/orderquery'), $params); |
|||
} |
|||
|
|||
/** |
|||
* Close order by out_trade_no. |
|||
* |
|||
* @param string $tradeNo |
|||
* |
|||
* @return ResponseInterface|Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function close(string $tradeNo) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'out_trade_no' => $tradeNo, |
|||
]; |
|||
|
|||
return $this->request($this->wrap('pay/closeorder'), $params); |
|||
} |
|||
} |
|||
@ -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\Payment\Order; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['order'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,201 @@ |
|||
<?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\Payment\ProfitSharing; |
|||
|
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author ClouderSky <clouder.flow@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
protected function prepends() |
|||
{ |
|||
return [ |
|||
'sign_type' => 'HMAC-SHA256', |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* Add profit sharing receiver. |
|||
* 服务商代子商户发起添加分账接收方请求. |
|||
* 后续可通过发起分账请求将结算后的钱分到该分账接收方. |
|||
* |
|||
* @param array $receiver 分账接收方对象,json格式 |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function addReceiver(array $receiver) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'receiver' => json_encode( |
|||
$receiver, JSON_UNESCAPED_UNICODE |
|||
), |
|||
]; |
|||
|
|||
return $this->request( |
|||
'pay/profitsharingaddreceiver', $params |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Delete profit sharing receiver. |
|||
* 服务商代子商户发起删除分账接收方请求. |
|||
* 删除后不支持将结算后的钱分到该分账接收方. |
|||
* |
|||
* @param array $receiver 分账接收方对象,json格式 |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function deleteReceiver(array $receiver) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'receiver' => json_encode( |
|||
$receiver, JSON_UNESCAPED_UNICODE |
|||
), |
|||
]; |
|||
|
|||
return $this->request( |
|||
'pay/profitsharingremovereceiver', $params |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Single profit sharing. |
|||
* 请求单次分账. |
|||
* |
|||
* @param string $transactionId 微信支付订单号 |
|||
* @param string $outOrderNo 商户系统内部的分账单号 |
|||
* @param array $receivers 分账接收方列表 |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function share( |
|||
string $transactionId, |
|||
string $outOrderNo, |
|||
array $receivers |
|||
) { |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'transaction_id' => $transactionId, |
|||
'out_order_no' => $outOrderNo, |
|||
'receivers' => json_encode( |
|||
$receivers, JSON_UNESCAPED_UNICODE |
|||
), |
|||
]; |
|||
|
|||
return $this->safeRequest( |
|||
'secapi/pay/profitsharing', $params |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Multi profit sharing. |
|||
* 请求多次分账. |
|||
* |
|||
* @param string $transactionId 微信支付订单号 |
|||
* @param string $outOrderNo 商户系统内部的分账单号 |
|||
* @param array $receivers 分账接收方列表 |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function multiShare( |
|||
string $transactionId, |
|||
string $outOrderNo, |
|||
array $receivers |
|||
) { |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'transaction_id' => $transactionId, |
|||
'out_order_no' => $outOrderNo, |
|||
'receivers' => json_encode( |
|||
$receivers, JSON_UNESCAPED_UNICODE |
|||
), |
|||
]; |
|||
|
|||
return $this->safeRequest( |
|||
'secapi/pay/multiprofitsharing', $params |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Finish profit sharing. |
|||
* 完结分账. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function markOrderAsFinished(array $params) |
|||
{ |
|||
$params['appid'] = $this->app['config']->app_id; |
|||
$params['sub_appid'] = null; |
|||
|
|||
return $this->safeRequest( |
|||
'secapi/pay/profitsharingfinish', $params |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Query profit sharing result. |
|||
* 查询分账结果. |
|||
* |
|||
* @param string $transactionId 微信支付订单号 |
|||
* @param string $outOrderNo 商户系统内部的分账单号 |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function query( |
|||
string $transactionId, string $outOrderNo |
|||
) { |
|||
$params = [ |
|||
'sub_appid' => null, |
|||
'transaction_id' => $transactionId, |
|||
'out_order_no' => $outOrderNo, |
|||
]; |
|||
|
|||
return $this->request( |
|||
'pay/profitsharingquery', $params |
|||
); |
|||
} |
|||
} |
|||
@ -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\Payment\ProfitSharing; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author ClouderSky <clouder.flow@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['profit_sharing'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,88 @@ |
|||
<?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\Payment\Redpack; |
|||
|
|||
use EasyWeChat\Kernel\Support; |
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author tianyong90 <412039588@qq.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Query redpack. |
|||
* |
|||
* @param mixed $mchBillno |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function info($mchBillno) |
|||
{ |
|||
$params = is_array($mchBillno) ? $mchBillno : ['mch_billno' => $mchBillno]; |
|||
$base = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'bill_type' => 'MCHT', |
|||
]; |
|||
|
|||
return $this->safeRequest('mmpaymkttransfers/gethbinfo', array_merge($base, $params)); |
|||
} |
|||
|
|||
/** |
|||
* Send normal redpack. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function sendNormal(array $params) |
|||
{ |
|||
$base = [ |
|||
'total_num' => 1, |
|||
'client_ip' => $params['client_ip'] ?? Support\get_server_ip(), |
|||
'wxappid' => $this->app['config']->app_id, |
|||
]; |
|||
|
|||
return $this->safeRequest('mmpaymkttransfers/sendredpack', array_merge($base, $params)); |
|||
} |
|||
|
|||
/** |
|||
* Send group redpack. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function sendGroup(array $params) |
|||
{ |
|||
$base = [ |
|||
'amt_type' => 'ALL_RAND', |
|||
'wxappid' => $this->app['config']->app_id, |
|||
]; |
|||
|
|||
return $this->safeRequest('mmpaymkttransfers/sendgroupredpack', array_merge($base, $params)); |
|||
} |
|||
} |
|||
@ -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\Payment\Redpack; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['redpack'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,159 @@ |
|||
<?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\Payment\Refund; |
|||
|
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Refund by out trade number. |
|||
* |
|||
* @param string $number |
|||
* @param string $refundNumber |
|||
* @param int $totalFee |
|||
* @param int $refundFee |
|||
* @param array $optional |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function byOutTradeNumber(string $number, string $refundNumber, int $totalFee, int $refundFee, array $optional = []) |
|||
{ |
|||
return $this->refund($refundNumber, $totalFee, $refundFee, array_merge($optional, ['out_trade_no' => $number])); |
|||
} |
|||
|
|||
/** |
|||
* Refund by transaction id. |
|||
* |
|||
* @param string $transactionId |
|||
* @param string $refundNumber |
|||
* @param int $totalFee |
|||
* @param int $refundFee |
|||
* @param array $optional |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function byTransactionId(string $transactionId, string $refundNumber, int $totalFee, int $refundFee, array $optional = []) |
|||
{ |
|||
return $this->refund($refundNumber, $totalFee, $refundFee, array_merge($optional, ['transaction_id' => $transactionId])); |
|||
} |
|||
|
|||
/** |
|||
* Query refund by transaction id. |
|||
* |
|||
* @param string $transactionId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function queryByTransactionId(string $transactionId) |
|||
{ |
|||
return $this->query($transactionId, 'transaction_id'); |
|||
} |
|||
|
|||
/** |
|||
* Query refund by out trade number. |
|||
* |
|||
* @param string $outTradeNumber |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function queryByOutTradeNumber(string $outTradeNumber) |
|||
{ |
|||
return $this->query($outTradeNumber, 'out_trade_no'); |
|||
} |
|||
|
|||
/** |
|||
* Query refund by out refund number. |
|||
* |
|||
* @param string $outRefundNumber |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function queryByOutRefundNumber(string $outRefundNumber) |
|||
{ |
|||
return $this->query($outRefundNumber, 'out_refund_no'); |
|||
} |
|||
|
|||
/** |
|||
* Query refund by refund id. |
|||
* |
|||
* @param string $refundId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function queryByRefundId(string $refundId) |
|||
{ |
|||
return $this->query($refundId, 'refund_id'); |
|||
} |
|||
|
|||
/** |
|||
* Refund. |
|||
* |
|||
* @param string $refundNumber |
|||
* @param int $totalFee |
|||
* @param int $refundFee |
|||
* @param array $optional |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function refund(string $refundNumber, int $totalFee, int $refundFee, $optional = []) |
|||
{ |
|||
$params = array_merge([ |
|||
'out_refund_no' => $refundNumber, |
|||
'total_fee' => $totalFee, |
|||
'refund_fee' => $refundFee, |
|||
'appid' => $this->app['config']->app_id, |
|||
], $optional); |
|||
|
|||
return $this->safeRequest($this->wrap( |
|||
$this->app->inSandbox() ? 'pay/refund' : 'secapi/pay/refund' |
|||
), $params); |
|||
} |
|||
|
|||
/** |
|||
* Query refund. |
|||
* |
|||
* @param string $number |
|||
* @param string $type |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function query(string $number, string $type) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
$type => $number, |
|||
]; |
|||
|
|||
return $this->request($this->wrap('pay/refundquery'), $params); |
|||
} |
|||
} |
|||
@ -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\Payment\Refund; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['refund'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
<?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\Payment\Reverse; |
|||
|
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Reverse order by out trade number. |
|||
* |
|||
* @param string $outTradeNumber |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function byOutTradeNumber(string $outTradeNumber) |
|||
{ |
|||
return $this->reverse($outTradeNumber, 'out_trade_no'); |
|||
} |
|||
|
|||
/** |
|||
* Reverse order by transaction_id. |
|||
* |
|||
* @param string $transactionId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function byTransactionId(string $transactionId) |
|||
{ |
|||
return $this->reverse($transactionId, 'transaction_id'); |
|||
} |
|||
|
|||
/** |
|||
* Reverse order. |
|||
* |
|||
* @param string $number |
|||
* @param string $type |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected function reverse(string $number, string $type) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
$type => $number, |
|||
]; |
|||
|
|||
return $this->safeRequest($this->wrap('secapi/pay/reverse'), $params); |
|||
} |
|||
} |
|||
@ -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\Payment\Reverse; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['reverse'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -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\Payment\Sandbox; |
|||
|
|||
use EasyWeChat\Kernel\Traits\InteractsWithCache; |
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
use EasyWeChat\Payment\Kernel\Exceptions\SandboxException; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
use InteractsWithCache; |
|||
|
|||
/** |
|||
* @return string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Payment\Kernel\Exceptions\SandboxException |
|||
* @throws \Psr\SimpleCache\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getKey(): string |
|||
{ |
|||
if ($cache = $this->getCache()->get($this->getCacheKey())) { |
|||
return $cache; |
|||
} |
|||
|
|||
$response = $this->requestArray('sandboxnew/pay/getsignkey'); |
|||
|
|||
if ('SUCCESS' === $response['return_code']) { |
|||
$this->getCache()->set($this->getCacheKey(), $key = $response['sandbox_signkey'], 24 * 3600); |
|||
|
|||
return $key; |
|||
} |
|||
|
|||
throw new SandboxException($response['retmsg'] ?? $response['return_msg']); |
|||
} |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected function getCacheKey(): string |
|||
{ |
|||
return 'easywechat.payment.sandbox.'.md5($this->app['config']->app_id.$this->app['config']['mch_id']); |
|||
} |
|||
} |
|||
@ -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\Payment\Sandbox; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* @param \Pimple\Container $app |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['sandbox'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
<?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\Payment\Security; |
|||
|
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getPublicKey() |
|||
{ |
|||
$params = [ |
|||
'sign_type' => 'MD5', |
|||
]; |
|||
|
|||
return $this->safeRequest('https://fraud.mch.weixin.qq.com/risk/getpublickey', $params); |
|||
} |
|||
} |
|||
@ -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\Payment\Security; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['security'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,122 @@ |
|||
<?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\Payment\Transfer; |
|||
|
|||
use EasyWeChat\Kernel\Exceptions\RuntimeException; |
|||
use function EasyWeChat\Kernel\Support\get_server_ip; |
|||
use function EasyWeChat\Kernel\Support\rsa_public_encrypt; |
|||
use EasyWeChat\Payment\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author AC <alexever@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Query MerchantPay to balance. |
|||
* |
|||
* @param string $partnerTradeNo |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function queryBalanceOrder(string $partnerTradeNo) |
|||
{ |
|||
$params = [ |
|||
'appid' => $this->app['config']->app_id, |
|||
'mch_id' => $this->app['config']->mch_id, |
|||
'partner_trade_no' => $partnerTradeNo, |
|||
]; |
|||
|
|||
return $this->safeRequest('mmpaymkttransfers/gettransferinfo', $params); |
|||
} |
|||
|
|||
/** |
|||
* Send MerchantPay to balance. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function toBalance(array $params) |
|||
{ |
|||
$base = [ |
|||
'mch_id' => null, |
|||
'mchid' => $this->app['config']->mch_id, |
|||
'mch_appid' => $this->app['config']->app_id, |
|||
]; |
|||
|
|||
if (empty($params['spbill_create_ip'])) { |
|||
$params['spbill_create_ip'] = get_server_ip(); |
|||
} |
|||
|
|||
return $this->safeRequest('mmpaymkttransfers/promotion/transfers', array_merge($base, $params)); |
|||
} |
|||
|
|||
/** |
|||
* Query MerchantPay order to BankCard. |
|||
* |
|||
* @param string $partnerTradeNo |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function queryBankCardOrder(string $partnerTradeNo) |
|||
{ |
|||
$params = [ |
|||
'mch_id' => $this->app['config']->mch_id, |
|||
'partner_trade_no' => $partnerTradeNo, |
|||
]; |
|||
|
|||
return $this->safeRequest('mmpaysptrans/query_bank', $params); |
|||
} |
|||
|
|||
/** |
|||
* Send MerchantPay to BankCard. |
|||
* |
|||
* @param array $params |
|||
* |
|||
* @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 |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function toBankCard(array $params) |
|||
{ |
|||
foreach (['bank_code', 'partner_trade_no', 'enc_bank_no', 'enc_true_name', 'amount'] as $key) { |
|||
if (empty($params[$key])) { |
|||
throw new RuntimeException(\sprintf('"%s" is required.', $key)); |
|||
} |
|||
} |
|||
|
|||
$publicKey = file_get_contents($this->app['config']->get('rsa_public_key_path')); |
|||
|
|||
$params['enc_bank_no'] = rsa_public_encrypt($params['enc_bank_no'], $publicKey); |
|||
$params['enc_true_name'] = rsa_public_encrypt($params['enc_true_name'], $publicKey); |
|||
|
|||
return $this->safeRequest('mmpaysptrans/pay_bank', $params); |
|||
} |
|||
} |
|||
@ -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\Payment\Transfer; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['transfer'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
<?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\Work\Agent; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* This is WeWork Agent Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get agent. |
|||
* |
|||
* @param int $agentId |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function get(int $agentId) |
|||
{ |
|||
$params = [ |
|||
'agentid' => $agentId, |
|||
]; |
|||
|
|||
return $this->httpGet('cgi-bin/agent/get', $params); |
|||
} |
|||
|
|||
/** |
|||
* Set agent. |
|||
* |
|||
* @param int $agentId |
|||
* @param array $attributes |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function set(int $agentId, array $attributes) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/agent/set', array_merge(['agentid' => $agentId], $attributes)); |
|||
} |
|||
|
|||
/** |
|||
* Get agent list. |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function list() |
|||
{ |
|||
return $this->httpGet('cgi-bin/agent/list'); |
|||
} |
|||
} |
|||
@ -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\Work\Agent; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['agent'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,100 @@ |
|||
<?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\Work; |
|||
|
|||
use EasyWeChat\Kernel\ServiceContainer; |
|||
use EasyWeChat\Work\MiniProgram\Application as MiniProgram; |
|||
|
|||
/** |
|||
* Application. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
* |
|||
* @property \EasyWeChat\Work\OA\Client $oa |
|||
* @property \EasyWeChat\Work\Auth\AccessToken $access_token |
|||
* @property \EasyWeChat\Work\Agent\Client $agent |
|||
* @property \EasyWeChat\Work\Department\Client $department |
|||
* @property \EasyWeChat\Work\Media\Client $media |
|||
* @property \EasyWeChat\Work\Menu\Client $menu |
|||
* @property \EasyWeChat\Work\Message\Client $message |
|||
* @property \EasyWeChat\Work\Message\Messenger $messenger |
|||
* @property \EasyWeChat\Work\User\Client $user |
|||
* @property \EasyWeChat\Work\User\TagClient $tag |
|||
* @property \EasyWeChat\Work\Server\ServiceProvider $server |
|||
* @property \EasyWeChat\Work\Jssdk\Client $jssdk |
|||
* @property \Overtrue\Socialite\Providers\WeWorkProvider $oauth |
|||
* @property \EasyWeChat\Work\Invoice\Client $invoice |
|||
* @property \EasyWeChat\Work\Chat\Client $chat |
|||
* @property \EasyWeChat\Work\ExternalContact\Client $external_contact |
|||
* @property \EasyWeChat\Work\ExternalContact\ContactWayClient $contact_way |
|||
* @property \EasyWeChat\Work\ExternalContact\StatisticsClient $external_contact_statistics |
|||
* @property \EasyWeChat\Work\ExternalContact\MessageClient $external_contact_message |
|||
* @property \EasyWeChat\Work\GroupRobot\Client $group_robot |
|||
* @property \EasyWeChat\Work\GroupRobot\Messenger $group_robot_messenger |
|||
* |
|||
* @method mixed getCallbackIp() |
|||
*/ |
|||
class Application extends ServiceContainer |
|||
{ |
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $providers = [ |
|||
OA\ServiceProvider::class, |
|||
Auth\ServiceProvider::class, |
|||
Base\ServiceProvider::class, |
|||
Menu\ServiceProvider::class, |
|||
OAuth\ServiceProvider::class, |
|||
User\ServiceProvider::class, |
|||
Agent\ServiceProvider::class, |
|||
Media\ServiceProvider::class, |
|||
Message\ServiceProvider::class, |
|||
Department\ServiceProvider::class, |
|||
Server\ServiceProvider::class, |
|||
Jssdk\ServiceProvider::class, |
|||
Invoice\ServiceProvider::class, |
|||
Chat\ServiceProvider::class, |
|||
ExternalContact\ServiceProvider::class, |
|||
GroupRobot\ServiceProvider::class, |
|||
]; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $defaultConfig = [ |
|||
// http://docs.guzzlephp.org/en/stable/request-options.html |
|||
'http' => [ |
|||
'base_uri' => 'https://qyapi.weixin.qq.com/', |
|||
], |
|||
]; |
|||
|
|||
/** |
|||
* Creates the miniProgram application. |
|||
* |
|||
* @return \EasyWeChat\Work\MiniProgram\Application |
|||
*/ |
|||
public function miniProgram(): MiniProgram |
|||
{ |
|||
return new MiniProgram($this->getConfig()); |
|||
} |
|||
|
|||
/** |
|||
* @param string $method |
|||
* @param array $arguments |
|||
* |
|||
* @return mixed |
|||
*/ |
|||
public function __call($method, $arguments) |
|||
{ |
|||
return $this['base']->$method(...$arguments); |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\Work\Auth; |
|||
|
|||
use EasyWeChat\Kernel\AccessToken as BaseAccessToken; |
|||
|
|||
/** |
|||
* Class AccessToken. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class AccessToken extends BaseAccessToken |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $endpointToGetToken = 'cgi-bin/gettoken'; |
|||
|
|||
/** |
|||
* @var int |
|||
*/ |
|||
protected $safeSeconds = 0; |
|||
|
|||
/** |
|||
* Credential for get token. |
|||
* |
|||
* @return array |
|||
*/ |
|||
protected function getCredentials(): array |
|||
{ |
|||
return [ |
|||
'corpid' => $this->app['config']['corp_id'], |
|||
'corpsecret' => $this->app['config']['secret'], |
|||
]; |
|||
} |
|||
} |
|||
@ -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\Work\Auth; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author overtrue <i@overtrue.me> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
isset($app['access_token']) || $app['access_token'] = function ($app) { |
|||
return new AccessToken($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?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\Work\Base; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get callback ip. |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function getCallbackIp() |
|||
{ |
|||
return $this->httpGet('cgi-bin/getcallbackip'); |
|||
} |
|||
} |
|||
@ -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\Work\Base; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* @param Container $app |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['base'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
<?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\Work\Chat; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author XiaolonY <xiaolony@hotmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Get chat. |
|||
* |
|||
* @param string $chatId |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function get(string $chatId) |
|||
{ |
|||
return $this->httpGet('cgi-bin/appchat/get', ['chatid' => $chatId]); |
|||
} |
|||
|
|||
/** |
|||
* Create chat. |
|||
* |
|||
* @param array $data |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(array $data) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/appchat/create', $data); |
|||
} |
|||
|
|||
/** |
|||
* Update chat. |
|||
* |
|||
* @param string $chatId |
|||
* @param array $data |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(string $chatId, array $data) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/appchat/update', array_merge(['chatid' => $chatId], $data)); |
|||
} |
|||
|
|||
/** |
|||
* Send a message. |
|||
* |
|||
* @param array $message |
|||
* |
|||
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function send(array $message) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/appchat/send', $message); |
|||
} |
|||
} |
|||
@ -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\Work\Chat; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author XiaolonY <xiaolony@hotmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['chat'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
<?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\Work\Department; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* This is WeWork Department Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* Create a department. |
|||
* |
|||
* @param array $data |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(array $data) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/department/create', $data); |
|||
} |
|||
|
|||
/** |
|||
* Update a department. |
|||
* |
|||
* @param int $id |
|||
* @param array $data |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(int $id, array $data) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/department/update', array_merge(compact('id'), $data)); |
|||
} |
|||
|
|||
/** |
|||
* Delete a department. |
|||
* |
|||
* @param int $id |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function delete($id) |
|||
{ |
|||
return $this->httpGet('cgi-bin/department/delete', compact('id')); |
|||
} |
|||
|
|||
/** |
|||
* Get department lists. |
|||
* |
|||
* @param int|null $id |
|||
* |
|||
* @return mixed |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function list($id = null) |
|||
{ |
|||
return $this->httpGet('cgi-bin/department/list', compact('id')); |
|||
} |
|||
} |
|||
@ -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\Work\Department; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['department'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,118 @@ |
|||
<?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\Work\ExternalContact; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* 获取配置了客户联系功能的成员列表. |
|||
* |
|||
* @see https://work.weixin.qq.com/api/doc#90000/90135/91554 |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function getFollowUsers() |
|||
{ |
|||
return $this->httpGet('cgi-bin/externalcontact/get_follow_user_list'); |
|||
} |
|||
|
|||
/** |
|||
* 获取外部联系人列表. |
|||
* |
|||
* @see https://work.weixin.qq.com/api/doc#90000/90135/91555 |
|||
* |
|||
* @param string $userId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function list(string $userId) |
|||
{ |
|||
return $this->httpGet('cgi-bin/externalcontact/list', [ |
|||
'userid' => $userId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 获取外部联系人详情. |
|||
* |
|||
* @see https://work.weixin.qq.com/api/doc#90000/90135/91556 |
|||
* |
|||
* @param string $externalUserId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
public function get(string $externalUserId) |
|||
{ |
|||
return $this->httpGet('cgi-bin/externalcontact/get', [ |
|||
'external_userid' => $externalUserId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 获取离职成员的客户列表. |
|||
* |
|||
* @see https://work.weixin.qq.com/api/doc#90000/90135/91563 |
|||
* |
|||
* @param int $pageId |
|||
* @param int $pageSize |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function getUnassigned(int $pageId = 0, int $pageSize = 1000) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/externalcontact/get_unassigned_list', [ |
|||
'page_id' => $pageId, |
|||
'page_size' => $pageSize, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 离职成员的外部联系人再分配. |
|||
* |
|||
* @see https://work.weixin.qq.com/api/doc#90000/90135/91564 |
|||
* |
|||
* @param string $externalUserId |
|||
* @param string $handoverUserId |
|||
* @param string $takeoverUserId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function transfer(string $externalUserId, string $handoverUserId, string $takeoverUserId) |
|||
{ |
|||
$params = [ |
|||
'external_userid' => $externalUserId, |
|||
'handover_userid' => $handoverUserId, |
|||
'takeover_userid' => $takeoverUserId, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/externalcontact/transfer', $params); |
|||
} |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
<?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\Work\ExternalContact; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class ContactWayClient. |
|||
* |
|||
* @author milkmeowo <milkmeowo@gmail.com> |
|||
*/ |
|||
class ContactWayClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 配置客户联系「联系我」方式. |
|||
* |
|||
* @param int $type |
|||
* @param int $scene |
|||
* @param array $config |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function create(int $type, int $scene, array $config = []) |
|||
{ |
|||
$params = array_merge([ |
|||
'type' => $type, |
|||
'scene' => $scene, |
|||
], $config); |
|||
|
|||
return $this->httpPostJson('cgi-bin/externalcontact/add_contact_way', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取企业已配置的「联系我」方式. |
|||
* |
|||
* @param string $configId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function get(string $configId) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/externalcontact/get_contact_way', [ |
|||
'config_id' => $configId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 更新企业已配置的「联系我」方式. |
|||
* |
|||
* @param string $configId |
|||
* @param array $config |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function update(string $configId, array $config = []) |
|||
{ |
|||
$params = array_merge([ |
|||
'config_id' => $configId, |
|||
], $config); |
|||
|
|||
return $this->httpPostJson('cgi-bin/externalcontact/update_contact_way', $params); |
|||
} |
|||
|
|||
/** |
|||
* 删除企业已配置的「联系我」方式. |
|||
* |
|||
* @param string $configId |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function delete(string $configId) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/externalcontact/del_contact_way', [ |
|||
'config_id' => $configId, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,168 @@ |
|||
<?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\Work\ExternalContact; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|||
|
|||
/** |
|||
* Class MessageClient. |
|||
* |
|||
* @author milkmeowo <milkmeowo@gmail.com> |
|||
*/ |
|||
class MessageClient extends BaseClient |
|||
{ |
|||
/** |
|||
* Required attributes. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $required = ['content', 'media_id', 'title', 'url', 'pic_media_id', 'appid', 'page']; |
|||
|
|||
protected $textMessage = [ |
|||
'content' => '', |
|||
]; |
|||
|
|||
protected $imageMessage = [ |
|||
'media_id' => '', |
|||
]; |
|||
|
|||
protected $linkMessage = [ |
|||
'title' => '', |
|||
'picurl' => '', |
|||
'desc' => '', |
|||
'url' => '', |
|||
]; |
|||
|
|||
protected $miniprogramMessage = [ |
|||
'title' => '', |
|||
'pic_media_id' => '', |
|||
'appid' => '', |
|||
'page' => '', |
|||
]; |
|||
|
|||
/** |
|||
* 添加企业群发消息模板 |
|||
* |
|||
* @see https://work.weixin.qq.com/api/doc#90000/90135/91560 |
|||
* |
|||
* @param array $msg |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function submit(array $msg) |
|||
{ |
|||
$params = $this->formatMessage($msg); |
|||
|
|||
return $this->httpPostJson('cgi-bin/externalcontact/add_msg_template', $params); |
|||
} |
|||
|
|||
/** |
|||
* 获取企业群发消息发送结果. |
|||
* |
|||
* @see https://work.weixin.qq.com/api/doc#90000/90135/91561 |
|||
* |
|||
* @param string $msgId |
|||
* |
|||
* @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 $msgId) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/externalcontact/get_group_msg_result', [ |
|||
'msgid' => $msgId, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 发送新客户欢迎语. |
|||
* |
|||
* @see https://work.weixin.qq.com/api/doc#90000/90135/91688 |
|||
* |
|||
* @param string $welcomeCode |
|||
* @param array $msg |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function sendWelcome(string $welcomeCode, array $msg) |
|||
{ |
|||
$formattedMsg = $this->formatMessage($msg); |
|||
|
|||
$params = array_merge($formattedMsg, [ |
|||
'welcome_code' => $welcomeCode, |
|||
]); |
|||
|
|||
return $this->httpPostJson('cgi-bin/externalcontact/send_welcome_msg', $params); |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws InvalidArgumentException |
|||
*/ |
|||
protected function formatMessage(array $data = []) |
|||
{ |
|||
$params = $data; |
|||
|
|||
if (!empty($params['text'])) { |
|||
$params['text'] = $this->formatFields($params['text'], $this->textMessage); |
|||
} |
|||
|
|||
if (!empty($params['image'])) { |
|||
$params['image'] = $this->formatFields($params['image'], $this->imageMessage); |
|||
} |
|||
|
|||
if (!empty($params['link'])) { |
|||
$params['link'] = $this->formatFields($params['link'], $this->linkMessage); |
|||
} |
|||
|
|||
if (!empty($params['miniprogram'])) { |
|||
$params['miniprogram'] = $this->formatFields($params['miniprogram'], $this->miniprogramMessage); |
|||
} |
|||
|
|||
return $params; |
|||
} |
|||
|
|||
/** |
|||
* @param array $data |
|||
* @param array $default |
|||
* |
|||
* @return array |
|||
* |
|||
* @throws InvalidArgumentException |
|||
*/ |
|||
protected function formatFields(array $data = [], array $default = []) |
|||
{ |
|||
$params = array_merge($default, $data); |
|||
foreach ($params as $key => $value) { |
|||
if (in_array($key, $this->required, true) && empty($value) && empty($default[$key])) { |
|||
throw new InvalidArgumentException(sprintf('Attribute "%s" can not be empty!', $key)); |
|||
} |
|||
|
|||
$params[$key] = empty($value) ? $default[$key] : $value; |
|||
} |
|||
|
|||
return $params; |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\Work\ExternalContact; |
|||
|
|||
use Pimple\Container; |
|||
use Pimple\ServiceProviderInterface; |
|||
|
|||
/** |
|||
* Class ServiceProvider. |
|||
* |
|||
* @author mingyoung <mingyoungcheung@gmail.com> |
|||
*/ |
|||
class ServiceProvider implements ServiceProviderInterface |
|||
{ |
|||
/** |
|||
* {@inheritdoc}. |
|||
*/ |
|||
public function register(Container $app) |
|||
{ |
|||
$app['external_contact'] = function ($app) { |
|||
return new Client($app); |
|||
}; |
|||
|
|||
$app['contact_way'] = function ($app) { |
|||
return new ContactWayClient($app); |
|||
}; |
|||
|
|||
$app['external_contact_statistics'] = function ($app) { |
|||
return new StatisticsClient($app); |
|||
}; |
|||
|
|||
$app['external_contact_message'] = function ($app) { |
|||
return new MessageClient($app); |
|||
}; |
|||
} |
|||
} |
|||
@ -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\Work\ExternalContact; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
|
|||
/** |
|||
* Class StatisticsClient. |
|||
* |
|||
* @author milkmeowo <milkmeowo@gmail.com> |
|||
*/ |
|||
class StatisticsClient extends BaseClient |
|||
{ |
|||
/** |
|||
* 获取员工行为数据. |
|||
* |
|||
* @see https://work.weixin.qq.com/api/doc#90000/90135/91580 |
|||
* |
|||
* @param array $userIds |
|||
* @param string $from |
|||
* @param string $to |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function userBehavior(array $userIds, string $from, string $to) |
|||
{ |
|||
$params = [ |
|||
'userid' => $userIds, |
|||
'start_time' => $from, |
|||
'end_time' => $to, |
|||
]; |
|||
|
|||
return $this->httpPostJson('cgi-bin/externalcontact/get_user_behavior_data', $params); |
|||
} |
|||
} |
|||
@ -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\Work\GroupRobot; |
|||
|
|||
use EasyWeChat\Kernel\BaseClient; |
|||
use EasyWeChat\Work\GroupRobot\Messages\Message; |
|||
|
|||
/** |
|||
* Class Client. |
|||
* |
|||
* @author her-cat <i@her-cat.com> |
|||
*/ |
|||
class Client extends BaseClient |
|||
{ |
|||
/** |
|||
* @param string|Message $message |
|||
* |
|||
* @return Messenger |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
public function message($message) |
|||
{ |
|||
return (new Messenger($this))->message($message); |
|||
} |
|||
|
|||
/** |
|||
* @param string $key |
|||
* @param array $message |
|||
* |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function send(string $key, array $message) |
|||
{ |
|||
return $this->httpPostJson('cgi-bin/webhook/send', $message, ['key' => $key]); |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
<?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\Work\GroupRobot\Messages; |
|||
|
|||
/** |
|||
* Class Image. |
|||
* |
|||
* @author her-cat <i@her-cat.com> |
|||
*/ |
|||
class Image extends Message |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $type = 'image'; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $properties = ['base64', 'md5']; |
|||
|
|||
/** |
|||
* Image constructor. |
|||
* |
|||
* @param string $base64 |
|||
* @param string $md5 |
|||
*/ |
|||
public function __construct(string $base64, string $md5) |
|||
{ |
|||
parent::__construct(compact('base64', 'md5')); |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
<?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\Work\GroupRobot\Messages; |
|||
|
|||
/** |
|||
* Class Markdown. |
|||
* |
|||
* @author her-cat <i@her-cat.com> |
|||
*/ |
|||
class Markdown extends Message |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $type = 'markdown'; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $properties = ['content']; |
|||
|
|||
/** |
|||
* Markdown constructor. |
|||
* |
|||
* @param string $content |
|||
*/ |
|||
public function __construct(string $content) |
|||
{ |
|||
parent::__construct(compact('content')); |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<?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\Work\GroupRobot\Messages; |
|||
|
|||
use EasyWeChat\Kernel\Messages\Message as BaseMessage; |
|||
|
|||
/** |
|||
* Class Message. |
|||
* |
|||
* @author her-cat <i@her-cat.com> |
|||
*/ |
|||
class Message extends BaseMessage |
|||
{ |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
<?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\Work\GroupRobot\Messages; |
|||
|
|||
/** |
|||
* Class News. |
|||
* |
|||
* @author her-cat <i@her-cat.com> |
|||
*/ |
|||
class News extends Message |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $type = 'news'; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $properties = ['items']; |
|||
|
|||
/** |
|||
* 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) { |
|||
if ($item instanceof NewsItem) { |
|||
return $item->toJsonArray(); |
|||
} |
|||
}, $this->get('items'))]; |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
<?php |
|||
|
|||
/* |
|||
* This file is part of the overtrue/wechat. |
|||
* |
|||
* (c) overtrue <i@overtrue.me> |
|||
* |
|||
* This source file is subject to the MIT license that is bundled |
|||
* with this source code in the file LICENSE. |
|||
*/ |
|||
|
|||
namespace EasyWeChat\Work\GroupRobot\Messages; |
|||
|
|||
/** |
|||
* Class NewsItem. |
|||
* |
|||
* @author her-cat <i@her-cat.com> |
|||
*/ |
|||
class NewsItem extends Message |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $type = 'news'; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $properties = [ |
|||
'title', |
|||
'description', |
|||
'url', |
|||
'image', |
|||
]; |
|||
|
|||
public function toJsonArray() |
|||
{ |
|||
return [ |
|||
'title' => $this->get('title'), |
|||
'description' => $this->get('description'), |
|||
'url' => $this->get('url'), |
|||
'picurl' => $this->get('image'), |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
<?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\Work\GroupRobot\Messages; |
|||
|
|||
/** |
|||
* Class Text. |
|||
* |
|||
* @author her-cat <i@her-cat.com> |
|||
*/ |
|||
class Text extends Message |
|||
{ |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $type = 'text'; |
|||
|
|||
/** |
|||
* @var array |
|||
*/ |
|||
protected $properties = ['content', 'mentioned_list', 'mentioned_mobile_list']; |
|||
|
|||
/** |
|||
* Text constructor. |
|||
* |
|||
* @param string $content |
|||
* @param string|array $userIds |
|||
* @param string|array $mobiles |
|||
*/ |
|||
public function __construct(string $content, $userIds = [], $mobiles = []) |
|||
{ |
|||
parent::__construct([ |
|||
'content' => $content, |
|||
'mentioned_list' => (array) $userIds, |
|||
'mentioned_mobile_list' => (array) $mobiles, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* @param array $userIds |
|||
* |
|||
* @return Text |
|||
*/ |
|||
public function mention($userIds) |
|||
{ |
|||
$this->set('mentioned_list', (array) $userIds); |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* @param array $mobiles |
|||
* |
|||
* @return Text |
|||
*/ |
|||
public function mentionByMobile($mobiles) |
|||
{ |
|||
$this->set('mentioned_mobile_list', (array) $mobiles); |
|||
|
|||
return $this; |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue