@@ -22,5 +22,5 @@ |
||
| 22 | 22 | * 必传的值 |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected $require = ['requestTimestamp', 'merOrderId', 'mid', 'tid','instMid']; |
|
| 25 | + protected $require = ['requestTimestamp', 'merOrderId', 'mid', 'tid', 'instMid']; |
|
| 26 | 26 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | $gateway = $this->config['gateway'];// 正式环境 |
| 51 | 51 | if($this->config['sandbox'] === false){ |
| 52 | 52 | $this->gateway = isset($gateway[$this->gateway_type]) ? $gateway[$this->gateway_type] : $gateway['default'];// 沙箱环境 |
| 53 | - }else{ |
|
| 53 | + } else{ |
|
| 54 | 54 | $this->gateway = $gateway['sandbox'];// 沙箱环境 |
| 55 | 55 | } |
| 56 | 56 | |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * @param $config |
| 44 | 44 | * @param $params |
| 45 | 45 | */ |
| 46 | - public function __construct($config=[],$params=[]) |
|
| 46 | + public function __construct($config = [], $params = []) |
|
| 47 | 47 | { |
| 48 | - if(!empty($config)){ |
|
| 48 | + if (!empty($config)) { |
|
| 49 | 49 | $this->config = $config; |
| 50 | 50 | $this->loadConfigGateway(); |
| 51 | 51 | } |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | private function loadConfigGateway() |
| 60 | 60 | { |
| 61 | - $gateway = $this->config['gateway'];// 正式环境 |
|
| 62 | - if($this->config['sandbox'] === false){ |
|
| 63 | - $this->gateway = isset($gateway[$this->gateway_type]) ? $gateway[$this->gateway_type] : $gateway['default'];// 沙箱环境 |
|
| 64 | - }else{ |
|
| 65 | - $this->gateway = $gateway['sandbox'];// 沙箱环境 |
|
| 61 | + $gateway = $this->config['gateway']; // 正式环境 |
|
| 62 | + if ($this->config['sandbox'] === false) { |
|
| 63 | + $this->gateway = isset($gateway[$this->gateway_type]) ? $gateway[$this->gateway_type] : $gateway['default']; // 沙箱环境 |
|
| 64 | + } else { |
|
| 65 | + $this->gateway = $gateway['sandbox']; // 沙箱环境 |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | return $this; |
@@ -91,14 +91,14 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function request($params = []) |
| 93 | 93 | { |
| 94 | - if(!empty($params)){ |
|
| 94 | + if (!empty($params)) { |
|
| 95 | 95 | $this->params = $params; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | try { |
| 99 | 99 | $data = $this->loadData(); |
| 100 | 100 | $sign = $this->generateSign($data); |
| 101 | - $gateway = $this->gateway . $this->api; |
|
| 101 | + $gateway = $this->gateway . $this->api; |
|
| 102 | 102 | |
| 103 | 103 | if ('cli' == php_sapi_name()) { |
| 104 | 104 | echo 'api:' . $gateway . PHP_EOL; |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | if ('cli' == php_sapi_name()) { |
| 121 | 121 | echo $e->getMessage() . PHP_EOL; |
| 122 | 122 | } |
| 123 | - throw new TException("Chinaums request error:".$e->getMessage()); |
|
| 123 | + throw new TException("Chinaums request error:" . $e->getMessage()); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | { |
| 132 | 132 | try { |
| 133 | 133 | $data = $this->loadData(); |
| 134 | - $params = $this->generateSign($data,true); |
|
| 135 | - $gateway = $this->gateway . $this->api; |
|
| 134 | + $params = $this->generateSign($data, true); |
|
| 135 | + $gateway = $this->gateway . $this->api; |
|
| 136 | 136 | |
| 137 | 137 | $data = json_encode($data); |
| 138 | 138 | if ('cli' == php_sapi_name()) { |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | CURLOPT_TIMEOUT => 60, |
| 145 | 145 | CURLOPT_CONNECTTIMEOUT => 30 |
| 146 | 146 | ]; |
| 147 | - $response = Http::get($gateway,$params,$options); |
|
| 147 | + $response = Http::get($gateway, $params, $options); |
|
| 148 | 148 | return $response; |
| 149 | 149 | } catch (Exception $e) { |
| 150 | - throw new TException("Chinaums formRequest error:".$e->getMessage()); |
|
| 150 | + throw new TException("Chinaums formRequest error:" . $e->getMessage()); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * @param string $signType |
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | - public function generateSign($body,$openForm=false) |
|
| 197 | + public function generateSign($body, $openForm = false) |
|
| 198 | 198 | { |
| 199 | 199 | $body = (!is_string($body)) ? json_encode($body) : $body; |
| 200 | 200 | $appid = $this->config['appid']; |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | $str = bin2hex(hash('sha256', $body, true)); |
| 205 | 205 | $signature = base64_encode(hash_hmac('sha256', "$appid$timestamp$nonce$str", $appkey, true)); |
| 206 | 206 | $authorization = "OPEN-BODY-SIG AppId=\"$appid\", Timestamp=\"$timestamp\", Nonce=\"$nonce\", Signature=\"$signature\""; |
| 207 | - if($openForm){ |
|
| 207 | + if ($openForm) { |
|
| 208 | 208 | $params = [ |
| 209 | 209 | 'appId'=>$appid, |
| 210 | 210 | 'timestamp'=>$timestamp, |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | $defaults[CURLOPT_SSL_VERIFYHOST] = false; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - curl_setopt_array($ch, (array)$options + $defaults); |
|
| 81 | + curl_setopt_array($ch, (array) $options + $defaults); |
|
| 82 | 82 | $ret = curl_exec($ch); |
| 83 | 83 | $err = curl_error($ch); |
| 84 | 84 | if (false === $ret || !empty($err)) { |
@@ -22,5 +22,5 @@ |
||
| 22 | 22 | * 必传的值 |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected $require = ['requestTimestamp', 'merOrderId', 'mid', 'tid','instMid']; |
|
| 25 | + protected $require = ['requestTimestamp', 'merOrderId', 'mid', 'tid', 'instMid']; |
|
| 26 | 26 | } |
@@ -22,5 +22,5 @@ |
||
| 22 | 22 | * 必传的值 |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected $require = ['requestTimestamp', 'merOrderId', 'mid', 'tid','instMid']; |
|
| 25 | + protected $require = ['requestTimestamp', 'merOrderId', 'mid', 'tid', 'instMid']; |
|
| 26 | 26 | } |
@@ -22,5 +22,5 @@ |
||
| 22 | 22 | * 必传的值 |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected $require = ['requestTimestamp', 'merOrderId', 'mid', 'tid','instMid']; |
|
| 25 | + protected $require = ['requestTimestamp', 'merOrderId', 'mid', 'tid', 'instMid']; |
|
| 26 | 26 | } |
@@ -24,6 +24,6 @@ |
||
| 24 | 24 | * 必传的值 |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $require = ['service', 'accesser_id', 'sign_type', 'request_date', 'request_seq','ums_reg_id']; |
|
| 27 | + protected $require = ['service', 'accesser_id', 'sign_type', 'request_date', 'request_seq', 'ums_reg_id']; |
|
| 28 | 28 | |
| 29 | 29 | } |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | try { |
| 39 | 39 | $this->validate(); |
| 40 | 40 | $data = $this->body; |
| 41 | - $gateway = $this->config['gateway'] . $this->api; |
|
| 41 | + $gateway = $this->config['gateway'] . $this->api; |
|
| 42 | 42 | $data = json_encode($data); |
| 43 | 43 | $sign = hash('sha256', $data); |
| 44 | 44 | $method = $this->method; |
@@ -52,9 +52,9 @@ |
||
| 52 | 52 | try { |
| 53 | 53 | $this->validate(); |
| 54 | 54 | $data = $this->body; |
| 55 | - $gateway = $this->config['gateway'] . $this->api; |
|
| 55 | + $gateway = $this->config['gateway'] . $this->api; |
|
| 56 | 56 | if (strtoupper($this->platform) == 'PC') { |
| 57 | - $gateway = $this->config['gateway'] . $this->PCapi; |
|
| 57 | + $gateway = $this->config['gateway'] . $this->PCapi; |
|
| 58 | 58 | } |
| 59 | 59 | $data = json_encode($data); |
| 60 | 60 | $sign = hash('sha256', $data); |