Completed
Push — master ( 8f5b55...c52b56 )
by frey
04:17 queued 01:50
created

AccessToken::getTokenFromServer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace EntWeChat\Suite;
4
5
use EntWeChat\Core\AccessToken as CoreAccessToken;
6
use EntWeChat\Core\Exceptions\HttpException;
7
8
class AccessToken extends CoreAccessToken
9
{
10
    /**
11
     * API.
12
     */
13
    const API_TOKEN_GET = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token';
14
    /**
15
     * Ticket.
16
     *
17
     * @var \EntWeChat\Suite\Ticket
18
     */
19
    protected $ticket;
20
    /**
21
     * {@inheritdoc}.
22
     */
23
    protected $queryName = 'suite_access_token';
24
25
    /**
26
     * {@inheritdoc}.
27
     */
28
    protected $tokenJsonKey = 'suite_access_token';
29
30
    /**
31
     * {@inheritdoc}.
32
     */
33
    protected $prefix = 'EntWeChat.suite.suite_access_token.';
34
35
    /**
36
     * Set VerifyTicket.
37
     *
38
     * @param \EntWeChat\Suite\Ticket $ticket
39
     *
40
     * @return $this
41
     */
42
    public function setTicket(Ticket $ticket)
43
    {
44
        $this->ticket = $ticket;
45
46
        return $this;
47
    }
48
49
    /**
50
     * {@inheritdoc}.
51
     */
52 View Code Duplication
    public function getTokenFromServer()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $data = [
55
            'suite_id'     => $this->id,
56
            'suite_secret' => $this->secret,
57
            'suite_ticket' => $this->ticket->getTicket(),
58
        ];
59
60
        $http = $this->getHttp();
61
62
        $token = $http->parseJSON($http->json(self::API_TOKEN_GET, $data));
63
64
        if (empty($token[$this->tokenJsonKey])) {
65
            throw new HttpException('Request SuiteAccessToken fail. response: '.json_encode($token, JSON_UNESCAPED_UNICODE));
66
        }
67
68
        return $token;
69
    }
70
}
71