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 AlterSign 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' => 'alter_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 | * |
||
34 | * @param array $data |
||
35 | * @return void |
||
36 | */ |
||
37 | public function getUrl($data = []) |
||
38 | { |
||
39 | $data['accesser_id'] = $this->config['accesser_id']; |
||
40 | $key = $this->config['private_key']; |
||
41 | if ($data) { |
||
0 ignored issues
–
show
|
|||
42 | $this->body = array_merge($this->body, $data); |
||
43 | } |
||
44 | try { |
||
45 | $this->validate(); |
||
46 | $data = $this->body; |
||
47 | $gateway = $this->config['gateway'] . $this->api; |
||
48 | $data = json_encode($data); |
||
49 | $sign = hash('sha256', $data); |
||
50 | $method = $this->method; |
||
51 | $des = new DES($key, $method, DES::OUTPUT_HEX); |
||
52 | // 加密 |
||
53 | $str = $des->encrypt($data); |
||
54 | $url = $gateway . '?sign_data=' . $sign . '&json_data=' . $str . '&accesser_id=' . $this->config['accesser_id']; |
||
55 | return json_encode(['res_code' => '0000', 'res_msg' => 'success', 'url' => $url], JSON_UNESCAPED_SLASHES); |
||
0 ignored issues
–
show
|
|||
56 | } catch (Exception $e) { |
||
57 | return json_encode(['res_code' => -1, 'res_msg' => $e->getMessage(), 'request_seq' => null]); |
||
0 ignored issues
–
show
|
|||
58 | } |
||
59 | } |
||
60 | } |
||
61 |
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.