diff --git a/src/OpenPlatform/Account/Client.php b/src/OpenPlatform/Account/Client.php new file mode 100644 index 000000000..d501b5200 --- /dev/null +++ b/src/OpenPlatform/Account/Client.php @@ -0,0 +1,95 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EasyWeChat\OpenPlatform\Account; + +use EasyWeChat\Kernel\BaseClient; + +/** + * Class Client. + * + * @author Scholer + */ +class Client extends BaseClient +{ + /** + * @var string + */ + protected $baseUri = 'https://api.weixin.qq.com/cgi-bin/open/'; + + /** + * 创建开放平台帐号并绑定公众号/小程序. + * + * @param string $appId 授权公众号或小程序的appid + * + * @return mixed + */ + public function create(string $appId) + { + $params = [ + 'appid' => $appId, + ]; + + return $this->httpPostJson('create', $params); + } + + /** + * 将公众号/小程序绑定到开放平台帐号下. + * + * @param string $appId 授权公众号或小程序的appid + * @param string $openAppId 开放平台帐号appid + * + * @return mixed + */ + public function bind(string $appId, string $openAppId) + { + $params = [ + 'appid' => $appId, + 'open_appid' => $openAppId, + ]; + + return $this->httpPostJson('bind', $params); + } + + /** + * 将公众号/小程序从开放平台帐号下解绑. + * + * @param string $appId 授权公众号或小程序的appid + * @param string $openAppId 开放平台帐号appid + * + * @return mixed + */ + public function unbind(string $appId, string $openAppId) + { + $params = [ + 'appid' => $appId, + 'open_appid' => $openAppId, + ]; + + return $this->httpPostJson('unbind', $params); + } + + /** + * 获取公众号/小程序所绑定的开放平台帐号. + * + * @param string $appId 授权公众号或小程序的appid + * + * @return mixed + */ + public function getBinding(string $appId) + { + $params = [ + 'appid' => $appId, + ]; + + return $this->httpPostJson('get', $params); + } +} diff --git a/src/OpenPlatform/Account/ServiceProvider.php b/src/OpenPlatform/Account/ServiceProvider.php new file mode 100644 index 000000000..10a177a5f --- /dev/null +++ b/src/OpenPlatform/Account/ServiceProvider.php @@ -0,0 +1,37 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace EasyWeChat\OpenPlatform\Account; + +use EasyWeChat\OpenPlatform\Auth\AuthorizerAccessToken; +use Pimple\Container; +use Pimple\ServiceProviderInterface; + +/** + * Class ServiceProvider. + * + * @author Scholer + */ +class ServiceProvider implements ServiceProviderInterface +{ + /** + * {@inheritdoc}. + */ + public function register(Container $app) + { + $accessToken = new AuthorizerAccessToken($app); + $accessToken->setOpenPlatformAccessToken($app['access_token']); + + $app['account'] = function ($app) use ($accessToken) { + return new Client($app, $accessToken); + }; + } +} diff --git a/src/OpenPlatform/Application.php b/src/OpenPlatform/Application.php index 8c876dade..5d884eedf 100644 --- a/src/OpenPlatform/Application.php +++ b/src/OpenPlatform/Application.php @@ -39,6 +39,7 @@ class Application extends ServiceContainer * @var array */ protected $providers = [ + Account\ServiceProvider::class, Auth\ServiceProvider::class, Base\ServiceProvider::class, Server\ServiceProvider::class,