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

EchoStrHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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