StoreChangeSign   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 23
c 1
b 0
f 1
dl 0
loc 45
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 21 3
1
<?php
2
3
namespace tinymeng\Chinaums\Service\Contract;
4
5
use tinymeng\Chinaums\Service\Contract\Base;
6
use tinymeng\Chinaums\Tools\DES;
7
use Exception;
8
9
/**
10
 * 分店变更签约接口
11
 */
12
class StoreChangeSign extends Base
13
{
14
    /**
15
     * @var string 接口地址
16
     */
17
    protected $api = '/self-contract-nmrs/interface/autoReg';
18
    /**
19
     * @var array $body 请求参数
20
     */
21
    protected $body = [
22
        'service' => 'store_change_sign',
23
        'sign_type' => 'SHA-256',
24
    ];
25
    /**
26
     * 必传的值
27
     * @var array
28
     */
29
    protected $require = ['service', 'accesser_id', 'sign_type', 'request_date', 'request_seq', 'ums_reg_id'];
30
31
    /**
32
     * 获取get前端签约方式
33
     * @param array $data
34
     * @return void
35
     */
36
    public function getUrl($data = [])
37
    {
38
        $data['accesser_id'] = $this->config['accesser_id'];
39
        $key = $this->config['private_key'];
40
        if ($data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
introduced by
$data is a non-empty array, thus is always true.
Loading history...
41
            $this->body = array_merge($this->body, $data);
42
        }
43
        try {
44
            $this->validate();
45
            $data = $this->body;
46
            $gateway  = $this->config['gateway'] . $this->api;
47
            $data = json_encode($data);
48
            $sign = hash('sha256', $data);
49
            $method = $this->method;
50
            $des = new DES($key, $method, DES::OUTPUT_HEX);
51
            // 加密
52
            $str = $des->encrypt($data);
53
            $url = $gateway . '?sign_data=' . $sign . '&json_data=' . $str . '&accesser_id=' . $this->config['accesser_id'];
54
            return json_encode(['res_code' => '0000', 'res_msg' => 'success', 'url' => $url], JSON_UNESCAPED_SLASHES);
0 ignored issues
show
Bug Best Practice introduced by
The expression return json_encode(array...JSON_UNESCAPED_SLASHES) returns the type string which is incompatible with the documented return type void.
Loading history...
55
        } catch (Exception $e) {
56
            return json_encode(['res_code' => -1, 'res_msg' => $e->getMessage(), 'request_seq' => null]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return json_encode(array...'request_seq' => null)) returns the type string which is incompatible with the documented return type void.
Loading history...
57
        }
58
    }
59
}
60