Completed
Pull Request — master (#1001)
by mingyoung
01:33
created

Client   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 16 3
A getCacheKey() 0 4 1
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\Payment\Sandbox;
13
14
use EasyWeChat\Kernel\Traits\InteractsWithCache;
15
use EasyWeChat\Payment\Kernel\BaseClient;
16
use EasyWeChat\Payment\Kernel\Exceptions\SandboxException;
17
18
/**
19
 * Class Client.
20
 *
21
 * @author mingyoung <[email protected]>
22
 */
23
class Client extends BaseClient
24
{
25
    use InteractsWithCache;
26
27
    /**
28
     * @return string
29
     *
30
     * @throws \EasyWeChat\Payment\Kernel\Exceptions\SandboxException
31
     */
32
    public function getKey(): string
33
    {
34
        if ($cache = $this->getCache()->get($this->getCacheKey())) {
35
            return $cache;
36
        }
37
38
        $response = $this->request('sandboxnew/pay/getsignkey');
39
40
        if ($response['return_code'] === 'SUCCESS') {
41
            $this->getCache()->set($this->getCacheKey(), $key = $response['sandbox_signkey'], 24 * 3600);
42
43
            return $key;
44
        }
45
46
        throw new SandboxException($response['return_msg']);
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    protected function getCacheKey(): string
53
    {
54
        return 'easywechat.payment.sandbox.'.md5($this->app['config']->app_id.$this->app['config']['mch_id']);
55
    }
56
}
57