guzzle header authorization
public function __construct()
{
$this->client = new Client();
$this->sms_gate_url = config('app.sms_gate.url');
$this->sms_gate_username = config('app.sms_gate.username');
$this->sms_gate_password = config('app.sms_gate.password');
}
public function sendSms(string $phone, string $message)
{
try {
$this->client->post($this->sms_gate_url . 'send', [
'auth' => [$this->sms_gate_username, $this->sms_gate_password],
'json' => [
"messages" => [
[
"recipient" => $phone,
"message-id" => "itrust" . strval(time()),
"sms" => [
"originator" => "3700",
"content" => [
"text" => $message
]
]
]
]
]
]);
} catch (\Exception $ex) {
Log::error($ex);
}
}