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 MerAlter extends Base |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* 平台 PC H5 |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $platform = 'PC'; |
20
|
|
|
/** |
21
|
|
|
* @var string h5接口地址 |
22
|
|
|
*/ |
23
|
|
|
protected $api = '/self-sign-mobile/#/chooseChangeType'; |
24
|
|
|
/** |
25
|
|
|
* @var string pc接口地址 |
26
|
|
|
*/ |
27
|
|
|
protected $PCapi = '/self-sign-web/#/alterHome'; |
28
|
|
|
/** |
29
|
|
|
* @var array $body 请求参数 |
30
|
|
|
*/ |
31
|
|
|
protected $body = [ |
32
|
|
|
'service' => 'merAlter', |
33
|
|
|
'sign_type' => 'SHA-256', |
34
|
|
|
]; |
35
|
|
|
/** |
36
|
|
|
* 必传的值 |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
protected $require = ['service', 'accesser_id', 'sign_type', 'request_date', 'request_seq', 'mchnNo']; |
40
|
|
|
public function setPlatform($value) |
41
|
|
|
{ |
42
|
|
|
$this->platform = $value; |
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
public function request($data = []) |
46
|
|
|
{ |
47
|
|
|
$data['accesser_id'] = $this->config['accesser_id']; |
48
|
|
|
$key = $this->config['private_key']; |
49
|
|
|
if ($data) { |
50
|
|
|
$this->body = array_merge($this->body, $data); |
51
|
|
|
} |
52
|
|
|
try { |
53
|
|
|
$this->validate(); |
54
|
|
|
$data = $this->body; |
55
|
|
|
$gateway = $this->config['gateway'] . $this->api; |
56
|
|
|
if (strtoupper($this->platform) == 'PC') { |
57
|
|
|
$gateway = $this->config['gateway'] . $this->PCapi; |
58
|
|
|
} |
59
|
|
|
$data = json_encode($data); |
60
|
|
|
$sign = hash('sha256', $data); |
61
|
|
|
$method = $this->method; |
62
|
|
|
$des = new DES($key, $method, DES::OUTPUT_HEX); |
63
|
|
|
// 加密 |
64
|
|
|
$str = $des->encrypt($data); |
65
|
|
|
$url = $gateway . '?sign_data=' . $sign . '&json_data=' . $str . '&accesser_id=' . $this->config['accesser_id']; |
66
|
|
|
return json_encode(['res_code' => '0000', 'res_msg' => 'success', 'url' => $url], JSON_UNESCAPED_SLASHES); |
67
|
|
|
} catch (Exception $e) { |
68
|
|
|
return json_encode(['res_code' => -1, 'res_msg' => $e->getMessage(), 'request_seq' => null]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|