init commit
This commit is contained in:
63
vendor/overtrue/wechat/src/OpenWork/Server/Guard.php
vendored
Normal file
63
vendor/overtrue/wechat/src/OpenWork/Server/Guard.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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\OpenWork\Server;
|
||||
|
||||
use EasyWeChat\Kernel\Encryptor;
|
||||
use EasyWeChat\Kernel\ServerGuard;
|
||||
|
||||
/**
|
||||
* Guard.
|
||||
*
|
||||
* @author xiaomin <keacefull@gmail.com>
|
||||
*/
|
||||
class Guard extends ServerGuard
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $alwaysValidate = true;
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function shouldReturnRawResponse(): bool
|
||||
{
|
||||
return !is_null($this->app['request']->get('echostr'));
|
||||
}
|
||||
|
||||
protected function isSafeMode(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
||||
*/
|
||||
protected function decryptMessage(array $message)
|
||||
{
|
||||
$encryptor = new Encryptor($message['ToUserName'], $this->app['config']->get('token'), $this->app['config']->get('aes_key'));
|
||||
|
||||
return $message = $encryptor->decrypt(
|
||||
$message['Encrypt'],
|
||||
$this->app['request']->get('msg_signature'),
|
||||
$this->app['request']->get('nonce'),
|
||||
$this->app['request']->get('timestamp')
|
||||
);
|
||||
}
|
||||
}
|
||||
60
vendor/overtrue/wechat/src/OpenWork/Server/Handlers/EchoStrHandler.php
vendored
Normal file
60
vendor/overtrue/wechat/src/OpenWork/Server/Handlers/EchoStrHandler.php
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the overtrue/wechat.
|
||||
*
|
||||
* (c) overtrue <i@overtrue.me>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace EasyWeChat\OpenWork\Server\Handlers;
|
||||
|
||||
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
|
||||
use EasyWeChat\Kernel\Decorators\FinallyResult;
|
||||
use EasyWeChat\Kernel\ServiceContainer;
|
||||
|
||||
/**
|
||||
* EchoStrHandler.
|
||||
*
|
||||
* @author xiaomin <keacefull@gmail.com>
|
||||
*/
|
||||
class EchoStrHandler implements EventHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var ServiceContainer
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* EchoStrHandler constructor.
|
||||
*/
|
||||
public function __construct(ServiceContainer $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $payload
|
||||
*
|
||||
* @return FinallyResult|null
|
||||
*/
|
||||
public function handle($payload = null)
|
||||
{
|
||||
if ($decrypted = $this->app['request']->get('echostr')) {
|
||||
$str = $this->app['encryptor_corp']->decrypt(
|
||||
$decrypted,
|
||||
$this->app['request']->get('msg_signature'),
|
||||
$this->app['request']->get('nonce'),
|
||||
$this->app['request']->get('timestamp')
|
||||
);
|
||||
|
||||
return new FinallyResult($str);
|
||||
}
|
||||
//把SuiteTicket缓存起来
|
||||
if (!empty($payload['SuiteTicket']) && !empty($payload['SuiteId']) && $this->app['config']['suite_id'] == $payload['SuiteId']) {
|
||||
$this->app['suite_ticket']->setTicket($payload['SuiteTicket']);
|
||||
}
|
||||
}
|
||||
}
|
||||
56
vendor/overtrue/wechat/src/OpenWork/Server/ServiceProvider.php
vendored
Normal file
56
vendor/overtrue/wechat/src/OpenWork/Server/ServiceProvider.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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\OpenWork\Server;
|
||||
|
||||
use EasyWeChat\Kernel\Encryptor;
|
||||
use EasyWeChat\OpenWork\Server\Handlers\EchoStrHandler;
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
|
||||
/**
|
||||
* ServiceProvider.
|
||||
*
|
||||
* @author xiaomin <keacefull@gmail.com>
|
||||
*/
|
||||
class ServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}.
|
||||
*/
|
||||
public function register(Container $app)
|
||||
{
|
||||
//微信第三方在校验url是使用的是GET方式请求和corp_id进行加密
|
||||
!isset($app['encryptor_corp']) && $app['encryptor_corp'] = function ($app) {
|
||||
return new Encryptor(
|
||||
$app['config']['corp_id'],
|
||||
$app['config']['token'],
|
||||
$app['config']['aes_key']
|
||||
);
|
||||
};
|
||||
|
||||
//微信第三方推送数据时使用的是suite_id进行加密
|
||||
!isset($app['encryptor']) && $app['encryptor'] = function ($app) {
|
||||
return new Encryptor(
|
||||
$app['config']['suite_id'],
|
||||
$app['config']['token'],
|
||||
$app['config']['aes_key']
|
||||
);
|
||||
};
|
||||
|
||||
!isset($app['server']) && $app['server'] = function ($app) {
|
||||
$guard = new Guard($app);
|
||||
$guard->push(new EchoStrHandler($app));
|
||||
|
||||
return $guard;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user