Skip to content

Commit

Permalink
Update HttpRequest.php
Browse files Browse the repository at this point in the history
兼容swoole可能存在ssl验证错误的问题
  • Loading branch information
619096932 authored Jan 19, 2021
1 parent c1020fc commit 804a110
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class HttpRequest
/**
* HttpRequest constructor.
*/
public function __construct()
public function __construct(array $guzz_params = [])
{
$this->client = new Client();
$this->client = new Client($guzz_params);
}

/**
Expand Down Expand Up @@ -118,20 +118,20 @@ public function withApi(string $api)
*/
public function send()
{
try{
try {
$this->data['appkey'] = $this->config->getAppKey();
$this->data['timestamp'] = $this->micro_time();
$this->data['sign'] = hash("sha256", "{$this->config->getAppKey()}{$this->data['timestamp']}{$this->config->getMasterSecret()}");
if($this->authorization instanceof Authorization && method_exists($this->authorization,'getTokenAsString')){
if ($this->authorization instanceof Authorization && method_exists($this->authorization, 'getTokenAsString')) {
$this->headers['token'] = $this->authorization->getTokenAsString();
}
return json_decode($this->client->request($this->method, $this->gateway . $this->config->getAppId() . $this->api, [
'headers' => $this->headers,
'body' => json_encode($this->data)
])->getBody()->getContents(), 1);
}catch (\GuzzleHttp\Exception\ClientException $exception){
$data = json_encode($exception->getResponse()->getBody()->getContents(),1);
if($exception->getResponse()->getStatusCode() == 400 && $data['code'] == 20001){
} catch (\GuzzleHttp\Exception\ClientException $exception) {
$data = json_decode($exception->getResponse()->getBody()->getContents(), 1);
if ($exception->getResponse()->getStatusCode() == 400 && $data['code'] == 20001) {
$this->authorization->refurbishToken();
$this->send();
}
Expand All @@ -145,4 +145,4 @@ private function micro_time()
$time = ($sec . substr($usec, 2, 3));
return $time;
}
}
}

0 comments on commit 804a110

Please sign in to comment.