Completed
Pull Request — master (#1414)
by milkmeowo
04:39
created

EchoStrHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 23.08%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 37
ccs 3
cts 13
cp 0.2308
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 15 3
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\OpenWork\Server\Handlers;
13
14
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
15
use EasyWeChat\Kernel\Decorators\FinallyResult;
16
use EasyWeChat\Kernel\ServiceContainer;
17
18
/**
19
 * EchoStrHandler.
20
 *
21
 * @author xiaomin <[email protected]>
22
 */
23
class EchoStrHandler implements EventHandlerInterface
24
{
25
    /**
26
     * @var ServiceContainer
27
     */
28
    protected $app;
29
30
    /**
31
     * EchoStrHandler constructor.
32
     *
33
     * @param ServiceContainer $app
34
     */
35 1
    public function __construct(ServiceContainer $app)
36
    {
37 1
        $this->app = $app;
38 1
    }
39
40
    /**
41
     * @param mixed $payload
42
     *
43
     * @return FinallyResult|null
44
     */
45
    public function handle($payload = null)
46
    {
47
        if ($decrypted = $this->app['request']->get('echostr')) {
48
            $str = $this->app['encryptor_corp']->decrypt(
49
                $decrypted,
50
                $this->app['request']->get('msg_signature'),
51
                $this->app['request']->get('nonce'),
52
                $this->app['request']->get('timestamp')
53
            );
54
55
            return new FinallyResult($str);
56
        }
57
        //把SuiteTicket缓存起来
58
        if (!empty($payload['SuiteTicket'])) {
59
            $this->app['suite_ticket']->setTicket($payload['SuiteTicket']);
60
        }
61
    }
62
}
63