Passed
Push — master ( e1047d...cb7bda )
by Carlos
02:50
created

Guard::decryptMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
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;
13
14
use EasyWeChat\Kernel\Encryptor;
15
use EasyWeChat\Kernel\ServerGuard;
16
17
/**
18
 * Guard.
19
 *
20
 * @author xiaomin <[email protected]>
21
 */
22
class Guard extends ServerGuard
23
{
24
    /**
25
     * @var bool
26
     */
27
    protected $alwaysValidate = true;
28
29
    /**
30
     * @return bool
31
     */
32
    public function validate()
33
    {
34
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type EasyWeChat\OpenWork\Server\Guard which is incompatible with the documented return type boolean.
Loading history...
35
    }
36
37
    /**
38
     * @return bool
39
     */
40
    protected function shouldReturnRawResponse(): bool
41
    {
42
        return !is_null($this->app['request']->get('echostr'));
43
    }
44
45
    protected function isSafeMode(): bool
46
    {
47
        return true;
48
    }
49
50
    /**
51
     * @param array $message
52
     *
53
     * @return mixed
54
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
55
     */
56
    protected function decryptMessage(array $message)
57
    {
58
        $encryptor = new Encryptor($message['ToUserName'], $this->app['config']->get('token'), $this->app['config']->get('aes_token'));
59
60
        return $message = $encryptor->decrypt(
0 ignored issues
show
Unused Code introduced by
The assignment to $message is dead and can be removed.
Loading history...
61
            $message['Encrypt'],
62
            $this->app['request']->get('msg_signature'),
63
            $this->app['request']->get('nonce'),
64
            $this->app['request']->get('timestamp')
65
        );
66
    }
67
}
68