@@ -29,8 +29,8 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | public function register(Container $pimple) |
| 31 | 31 | { |
| 32 | - $pimple['http_client'] = function ($app) { |
|
| 33 | - return new Client($app['config']->get('http', [])); |
|
| 32 | + $pimple[ 'http_client' ] = function($app) { |
|
| 33 | + return new Client($app[ 'config' ]->get('http', [ ])); |
|
| 34 | 34 | }; |
| 35 | 35 | } |
| 36 | 36 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | public function register(Container $pimple) |
| 31 | 31 | { |
| 32 | - $pimple['request'] = function () { |
|
| 32 | + $pimple[ 'request' ] = function() { |
|
| 33 | 33 | return Request::createFromGlobals(); |
| 34 | 34 | }; |
| 35 | 35 | } |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | foreach ($params as $k => $v) { |
| 54 | 54 | if (false === $this->checkEmpty($v) && "@" !== substr($v, 0, 1)) { |
| 55 | 55 | if ($i === 0) { |
| 56 | - $stringToBeSigned .= "$k"."="."$v"; |
|
| 56 | + $stringToBeSigned .= "$k" . "=" . "$v"; |
|
| 57 | 57 | } else { |
| 58 | - $stringToBeSigned .= "&"."$k"."="."$v"; |
|
| 58 | + $stringToBeSigned .= "&" . "$k" . "=" . "$v"; |
|
| 59 | 59 | } |
| 60 | 60 | $i++; |
| 61 | 61 | } |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | foreach ($params as $k => $v) { |
| 83 | 83 | if (false === $this->checkEmpty($v) && "@" !== substr($v, 0, 1)) { |
| 84 | 84 | if ($i === 0) { |
| 85 | - $stringToBeSigned .= "$k"."=".urlencode($v); |
|
| 85 | + $stringToBeSigned .= "$k" . "=" . urlencode($v); |
|
| 86 | 86 | } else { |
| 87 | - $stringToBeSigned .= "&"."$k"."=".urlencode($v); |
|
| 87 | + $stringToBeSigned .= "&" . "$k" . "=" . urlencode($v); |
|
| 88 | 88 | } |
| 89 | 89 | $i++; |
| 90 | 90 | } |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | protected function sign($data, $signType = "RSA2") |
| 109 | 109 | { |
| 110 | - $rsaPrivateKeyFilePath = $this->app['config']->get('private_key_path'); |
|
| 110 | + $rsaPrivateKeyFilePath = $this->app[ 'config' ]->get('private_key_path'); |
|
| 111 | 111 | if ($this->checkEmpty($rsaPrivateKeyFilePath)) { |
| 112 | - $priKey = $this->app['config']['private_key']; |
|
| 113 | - $res = "-----BEGIN RSA PRIVATE KEY-----\n". |
|
| 114 | - wordwrap($priKey, 64, "\n", true). |
|
| 112 | + $priKey = $this->app[ 'config' ][ 'private_key' ]; |
|
| 113 | + $res = "-----BEGIN RSA PRIVATE KEY-----\n" . |
|
| 114 | + wordwrap($priKey, 64, "\n", true) . |
|
| 115 | 115 | "\n-----END RSA PRIVATE KEY-----"; |
| 116 | 116 | } else { |
| 117 | 117 | $priKey = file_get_contents($rsaPrivateKeyFilePath); |
@@ -175,13 +175,13 @@ discard block |
||
| 175 | 175 | { |
| 176 | 176 | $response_suffix = '_response'; |
| 177 | 177 | $error_respones = 'error_response'; |
| 178 | - $apiMethod = $this->app['config']['api_method'] ?? $apiMethod; |
|
| 179 | - $rootNodeName = str_replace(".", "_", $apiMethod).$response_suffix; |
|
| 178 | + $apiMethod = $this->app[ 'config' ][ 'api_method' ] ?? $apiMethod; |
|
| 179 | + $rootNodeName = str_replace(".", "_", $apiMethod) . $response_suffix; |
|
| 180 | 180 | |
| 181 | - if (isset($response[$rootNodeName])) { |
|
| 182 | - return $response[$rootNodeName]; |
|
| 183 | - } elseif (isset($response[$error_respones])) { |
|
| 184 | - return $response[$error_respones]; |
|
| 181 | + if (isset($response[ $rootNodeName ])) { |
|
| 182 | + return $response[ $rootNodeName ]; |
|
| 183 | + } elseif (isset($response[ $error_respones ])) { |
|
| 184 | + return $response[ $error_respones ]; |
|
| 185 | 185 | } else { |
| 186 | 186 | return $response; |
| 187 | 187 | } |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | public function verify(string $data, $sign, $signType = 'RSA2') |
| 202 | 202 | { |
| 203 | - $alipayPublicKeyPath = $this->app['config']->get('alipay_public_Key_path'); |
|
| 203 | + $alipayPublicKeyPath = $this->app[ 'config' ]->get('alipay_public_Key_path'); |
|
| 204 | 204 | if ($this->checkEmpty($alipayPublicKeyPath)) { |
| 205 | - $pubKey = $this->app['config']->get('alipay_public_Key'); |
|
| 206 | - $res = "-----BEGIN PUBLIC KEY-----\n". |
|
| 207 | - wordwrap($pubKey, 64, "\n", true). |
|
| 205 | + $pubKey = $this->app[ 'config' ]->get('alipay_public_Key'); |
|
| 206 | + $res = "-----BEGIN PUBLIC KEY-----\n" . |
|
| 207 | + wordwrap($pubKey, 64, "\n", true) . |
|
| 208 | 208 | "\n-----END PUBLIC KEY-----"; |
| 209 | 209 | } else { |
| 210 | 210 | // Read public key file |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $result = $this->verify( |
| 250 | 250 | $content, |
| 251 | 251 | $sign, |
| 252 | - $this->app['config']->get('sign_type', 'RSA2') |
|
| 252 | + $this->app[ 'config' ]->get('sign_type', 'RSA2') |
|
| 253 | 253 | ); |
| 254 | 254 | } else { |
| 255 | 255 | throw new InvalidSignException('check sign Fail! The reason : sign data is Empty', 0, $content); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | if (!$result) { |
| 259 | 259 | throw new InvalidSignException(sprintf( |
| 260 | 260 | '"%s" method responds to parameter validation signature error', |
| 261 | - $this->app['config']['api_method'] |
|
| 261 | + $this->app[ 'config' ][ 'api_method' ] |
|
| 262 | 262 | )); |
| 263 | 263 | } |
| 264 | 264 | |
@@ -48,17 +48,17 @@ discard block |
||
| 48 | 48 | /** |
| 49 | 49 | * @var array |
| 50 | 50 | */ |
| 51 | - protected $providers = []; |
|
| 51 | + protected $providers = [ ]; |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @var array |
| 55 | 55 | */ |
| 56 | - protected $userConfig = []; |
|
| 56 | + protected $userConfig = [ ]; |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * @var array |
| 60 | 60 | */ |
| 61 | - protected $defaultConfig = []; |
|
| 61 | + protected $defaultConfig = [ ]; |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Application constructor. |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function __construct(array $config) |
| 69 | 69 | { |
| 70 | - parent::__construct(['app_client_providers' => $this->providers]); |
|
| 70 | + parent::__construct([ 'app_client_providers' => $this->providers ]); |
|
| 71 | 71 | $this->registerProviders($this->getProviders()); |
| 72 | 72 | $this->init($config); |
| 73 | 73 | } |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function __get($name) |
| 85 | 85 | { |
| 86 | - if (isset($this[$name])) { |
|
| 87 | - return $this[$name]; |
|
| 86 | + if (isset($this[ $name ])) { |
|
| 87 | + return $this[ $name ]; |
|
| 88 | 88 | } |
| 89 | 89 | throw new RuntimeException(sprintf('Identifier "%s" is not defined', $name)); |
| 90 | 90 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $this->config->set('api_method', $endpoint); |
| 131 | 131 | |
| 132 | 132 | return array_merge([ |
| 133 | - 'app_id' => $this->config['sys_params.app_id'], |
|
| 133 | + 'app_id' => $this->config[ 'sys_params.app_id' ], |
|
| 134 | 134 | 'method' => $endpoint, |
| 135 | 135 | 'format' => 'JSON', |
| 136 | 136 | 'charset' => $this->config->get('sys_params.charset', 'utf-8'), |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | 'timestamp' => date('Y-m-d H:i:s'), |
| 140 | 140 | 'version' => '1.0', |
| 141 | 141 | 'app_auth_token' => $this->config->get('sys_params.app_auth_token', ''), |
| 142 | - ], $this->config->get($endpoint.'config', [])); |
|
| 142 | + ], $this->config->get($endpoint . 'config', [ ])); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function setEndpointConfig(string $endpoint, array $config) |
| 154 | 154 | { |
| 155 | - $this->config->set($endpoint.'config', $config); |
|
| 155 | + $this->config->set($endpoint . 'config', $config); |
|
| 156 | 156 | |
| 157 | 157 | return $this; |
| 158 | 158 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function getEnv() |
| 180 | 180 | { |
| 181 | - return isset($this->userConfig['env']) ? $this->userConfig['env'] : self::NORMAL_ENV; |
|
| 181 | + return isset($this->userConfig[ 'env' ]) ? $this->userConfig[ 'env' ] : self::NORMAL_ENV; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -188,11 +188,11 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | public function getGateway() |
| 190 | 190 | { |
| 191 | - if (isset($this->gateway[$this->getEnv()])) { |
|
| 192 | - return $this->gateway[$this->getEnv()]; |
|
| 191 | + if (isset($this->gateway[ $this->getEnv() ])) { |
|
| 192 | + return $this->gateway[ $this->getEnv() ]; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - return $this->gateway[self::NORMAL_ENV]; |
|
| 195 | + return $this->gateway[ self::NORMAL_ENV ]; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $this->app = $app; |
| 47 | 47 | |
| 48 | - $this->setHttpClient($this->app['http_client']); |
|
| 48 | + $this->setHttpClient($this->app[ 'http_client' ]); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -63,17 +63,17 @@ discard block |
||
| 63 | 63 | * @throws \WannanBigPig\Alipay\Kernel\Exceptions\InvalidSignException |
| 64 | 64 | * @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException |
| 65 | 65 | */ |
| 66 | - public function request($endpoint, $params = [], $method = 'POST', array $options = [], $returnResponse = false) |
|
| 66 | + public function request($endpoint, $params = [ ], $method = 'POST', array $options = [ ], $returnResponse = false) |
|
| 67 | 67 | { |
| 68 | 68 | // Get api system parameters |
| 69 | 69 | $sysParams = $this->app->apiCommonConfig($endpoint); |
| 70 | 70 | // Filter system parameters |
| 71 | - $sysParams = array_filter($sysParams, function ($value) { |
|
| 71 | + $sysParams = array_filter($sysParams, function($value) { |
|
| 72 | 72 | return !($this->checkEmpty($value)); |
| 73 | 73 | }); |
| 74 | 74 | $params = $this->json($params); |
| 75 | 75 | // Set the signature |
| 76 | - $sysParams['sign'] = $this->generateSign(array_merge($sysParams, $params), $sysParams['sign_type']); |
|
| 76 | + $sysParams[ 'sign' ] = $this->generateSign(array_merge($sysParams, $params), $sysParams[ 'sign_type' ]); |
|
| 77 | 77 | // Set log middleware to record data, Log request and response data to the log file info level |
| 78 | 78 | $this->pushMiddleware($this->logMiddleware(), 'log'); |
| 79 | 79 | // Set http parameter options |
@@ -81,17 +81,17 @@ discard block |
||
| 81 | 81 | 'form_params' => $params, |
| 82 | 82 | 'headers' => [ |
| 83 | 83 | 'content-type' => 'application/x-www-form-urlencoded', |
| 84 | - 'charset' => $sysParams['charset'], |
|
| 84 | + 'charset' => $sysParams[ 'charset' ], |
|
| 85 | 85 | ], |
| 86 | 86 | ], $options); |
| 87 | 87 | |
| 88 | - $response = $this->performRequest($method, '?'.http_build_query($sysParams), $options); |
|
| 88 | + $response = $this->performRequest($method, '?' . http_build_query($sysParams), $options); |
|
| 89 | 89 | |
| 90 | - $arrayBody = \GuzzleHttp\json_decode((string)$response->getBody(), true, 512, JSON_BIGINT_AS_STRING); |
|
| 90 | + $arrayBody = \GuzzleHttp\json_decode((string) $response->getBody(), true, 512, JSON_BIGINT_AS_STRING); |
|
| 91 | 91 | $context = \GuzzleHttp\json_encode($this->parserSignSource($arrayBody, $endpoint), JSON_UNESCAPED_UNICODE); |
| 92 | 92 | |
| 93 | 93 | // Verify Response Signature |
| 94 | - $this->checkResponseSign($context, $arrayBody['sign'] ?? null); |
|
| 94 | + $this->checkResponseSign($context, $arrayBody[ 'sign' ] ?? null); |
|
| 95 | 95 | |
| 96 | 96 | return $returnResponse ? $response : $this->handleResponse($response, $context); |
| 97 | 97 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | public function handleResponse(ResponseInterface $response, string $context = null) |
| 110 | 110 | { |
| 111 | 111 | $is_build = true; |
| 112 | - if ($this->app['config']->get('handle_response', true) && !is_null($context)) { |
|
| 112 | + if ($this->app[ 'config' ]->get('handle_response', true) && !is_null($context)) { |
|
| 113 | 113 | $response = new Response( |
| 114 | 114 | $response->getStatusCode(), |
| 115 | 115 | $response->getHeaders(), |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $is_build = false; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - return $this->castResponseToType($response, $this->app['config']->get('response_type', 'array'), $is_build); |
|
| 123 | + return $this->castResponseToType($response, $this->app[ 'config' ]->get('response_type', 'array'), $is_build); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -130,9 +130,9 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | protected function logMiddleware() |
| 132 | 132 | { |
| 133 | - $formatter = new MessageFormatter($this->app['config']['http.log_template'] ?? MessageFormatter::DEBUG); |
|
| 133 | + $formatter = new MessageFormatter($this->app[ 'config' ][ 'http.log_template' ] ?? MessageFormatter::DEBUG); |
|
| 134 | 134 | |
| 135 | - return Middleware::log($this->app['logger']->getLogger(), $formatter); |
|
| 135 | + return Middleware::log($this->app[ 'logger' ]->getLogger(), $formatter); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | protected function json(array $data): array |
| 146 | 146 | { |
| 147 | - $array = []; |
|
| 148 | - if (isset($data['biz_content']) && is_array($data['biz_content'])) { |
|
| 149 | - $array['biz_content'] = \GuzzleHttp\json_encode($data['biz_content'], JSON_UNESCAPED_UNICODE); |
|
| 147 | + $array = [ ]; |
|
| 148 | + if (isset($data[ 'biz_content' ]) && is_array($data[ 'biz_content' ])) { |
|
| 149 | + $array[ 'biz_content' ] = \GuzzleHttp\json_encode($data[ 'biz_content' ], JSON_UNESCAPED_UNICODE); |
|
| 150 | 150 | } else { |
| 151 | 151 | return $data; |
| 152 | 152 | } |