12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace crmeb\services\wechat;
- use crmeb\services\wechat\config\OpenWebConfig;
- use EasyWeChat\Factory;
- use EasyWeChat\Kernel\Exceptions\BadRequestException;
- use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
- use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
- use EasyWeChat\OpenPlatform\Application;
- use Symfony\Component\Cache\Adapter\RedisAdapter;
- use Symfony\Component\HttpFoundation\Request;
- use think\facade\Cache;
- use think\Response;
- use Yurun\Util\Swoole\Guzzle\SwooleHandler;
- class OpenPlatform extends BaseApplication
- {
-
- protected $config;
-
- protected $application;
-
- public function __construct()
- {
-
- $this->config = app()->make(OpenWebConfig::class);
- $this->debug = DefaultConfig::value('logger');
- }
-
- public static function instance()
- {
- return app()->make(static::class);
- }
-
- public function application()
- {
- if (!$this->application) {
- $this->application = Factory::openPlatform($this->config->all());
- $request = request();
- $this->application['guzzle_handler'] = SwooleHandler::class;
- $this->application->rebind('request', new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
- $this->application->rebind('cache', new RedisAdapter(Cache::store('redis')->handler()));
- }
- return $this->application;
- }
-
- public static function serve(): Response
- {
- $make = self::instance();
- $make->application()->server->push($make->pushMessageHandler);
- $response = $make->application()->server->serve();
- return response($response->getContent());
- }
- }
|