Skip to content

Commit

Permalink
feat: custom host
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jul 16, 2024
1 parent fa43b42 commit b97d8b7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Gateways/QcloudGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Overtrue\EasySms\Gateways;

use GuzzleHttp\Psr7\Uri;
use Overtrue\EasySms\Contracts\MessageInterface;
use Overtrue\EasySms\Contracts\PhoneNumberInterface;
use Overtrue\EasySms\Exceptions\GatewayErrorException;
Expand All @@ -28,8 +29,6 @@ class QcloudGateway extends Gateway

public const ENDPOINT_URL = 'https://sms.tencentcloudapi.com';

public const ENDPOINT_HOST = 'sms.tencentcloudapi.com';

public const ENDPOINT_SERVICE = 'sms';

public const ENDPOINT_METHOD = 'SendSms';
Expand Down Expand Up @@ -66,10 +65,12 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config

$time = time();

$result = $this->request('post', self::ENDPOINT_URL, [
$endpoint = $this->config->get('endpoint', self::ENDPOINT_URL);

$result = $this->request('post', $endpoint, [
'headers' => [
'Authorization' => $this->generateSign($params, $time),
'Host' => self::ENDPOINT_HOST,
'Host' => (new Uri($endpoint))->getHost(),
'Content-Type' => 'application/json; charset=utf-8',
'X-TC-Action' => self::ENDPOINT_METHOD,
'X-TC-Region' => $this->config->get('region', self::ENDPOINT_REGION),
Expand Down Expand Up @@ -106,12 +107,14 @@ protected function generateSign($params, $timestamp)
$date = gmdate('Y-m-d', $timestamp);
$secretKey = $this->config->get('secret_key');
$secretId = $this->config->get('secret_id');
$endpoint = $this->config->get('endpoint', self::ENDPOINT_URL);
$host = (new Uri($endpoint))->getHost();

$canonicalRequest = 'POST'."\n".
'/'."\n".
''."\n".
'content-type:application/json; charset=utf-8'."\n".
'host:'.self::ENDPOINT_HOST."\n\n".
'host:'.$host."\n\n".
'content-type;host'."\n".
hash('SHA256', json_encode($params));

Expand Down

0 comments on commit b97d8b7

Please sign in to comment.