|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the overtrue/wechat. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) overtrue <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace EasyWeChat\OpenPlatform\Server; |
|
13
|
|
|
|
|
14
|
|
|
use EasyWeChat\Kernel\ServerGuard; |
|
15
|
|
|
use EasyWeChat\OpenPlatform\Server\Handlers\Authorized; |
|
16
|
|
|
use EasyWeChat\OpenPlatform\Server\Handlers\Unauthorized; |
|
17
|
|
|
use EasyWeChat\OpenPlatform\Server\Handlers\UpdateAuthorized; |
|
18
|
|
|
use EasyWeChat\OpenPlatform\Server\Handlers\VerifyTicketRefreshed; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
use function EasyWeChat\Kernel\data_get; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class Guard. |
|
24
|
|
|
* |
|
25
|
|
|
* @author mingyoung <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class Guard extends ServerGuard |
|
28
|
|
|
{ |
|
29
|
|
|
public const EVENT_AUTHORIZED = 'authorized'; |
|
30
|
|
|
public const EVENT_UNAUTHORIZED = 'unauthorized'; |
|
31
|
|
|
public const EVENT_UPDATE_AUTHORIZED = 'updateauthorized'; |
|
32
|
|
|
public const EVENT_COMPONENT_VERIFY_TICKET = 'component_verify_ticket'; |
|
33
|
|
|
public const EVENT_THIRD_FAST_REGISTERED = 'notify_third_fasteregister'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
37
|
|
|
* |
|
38
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\BadRequestException |
|
39
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|
40
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
41
|
|
|
*/ |
|
42
|
1 |
|
protected function resolve(): Response |
|
43
|
|
|
{ |
|
44
|
1 |
|
$this->registerHandlers(); |
|
45
|
|
|
|
|
46
|
1 |
|
$message = $this->getMessage(); |
|
47
|
|
|
|
|
48
|
1 |
|
if ($infoType = data_get($message, 'InfoType')) { |
|
49
|
1 |
|
$this->dispatch($infoType, $message); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
return new Response(static::SUCCESS_EMPTY_RESPONSE); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Register event handlers. |
|
57
|
|
|
*/ |
|
58
|
1 |
|
protected function registerHandlers() |
|
59
|
|
|
{ |
|
60
|
1 |
|
$this->on(self::EVENT_AUTHORIZED, Authorized::class); |
|
61
|
1 |
|
$this->on(self::EVENT_UNAUTHORIZED, Unauthorized::class); |
|
62
|
1 |
|
$this->on(self::EVENT_UPDATE_AUTHORIZED, UpdateAuthorized::class); |
|
63
|
1 |
|
$this->on(self::EVENT_COMPONENT_VERIFY_TICKET, VerifyTicketRefreshed::class); |
|
64
|
1 |
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|