Sms verification ok
This commit is contained in:
51
app/Helpers/helpers.php
Normal file
51
app/Helpers/helpers.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use App\Models\System\Verification;
|
||||
use Illuminate\Http\Client\Client;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Send a sms
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function sendSMS(string|int $phone, string|int $message)
|
||||
{
|
||||
$client = new Client();
|
||||
$headers = [
|
||||
'Content-Type' => 'application/json;charset=utf-8;',
|
||||
'Charset' => 'UTF-8'
|
||||
];
|
||||
$body = '{
|
||||
"SendRequest": {
|
||||
"TerminalID": "Online_PANEL",
|
||||
"Version": "1",
|
||||
"Lang": "EN",
|
||||
"MobilePhone": "993'.$phone.'",
|
||||
"Text": "'. $message .'"
|
||||
}
|
||||
}';
|
||||
$request = new Request('POST', 'http://10.3.158.103:8080/kpsmsroute/online.request', $headers, $body);
|
||||
|
||||
try {
|
||||
$res = $client->sendAsync($request, $options)->wait();
|
||||
|
||||
return $res->getBody();
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a sms verification code
|
||||
*/
|
||||
function sendSMSVerification(string|int $phone_number): ?Verification
|
||||
{
|
||||
$phone_code = rand(10000, 99999);
|
||||
$verification = Verification::where(['username' => $phone_number])->first();
|
||||
$verification ? $verification->update(['code' => $phone_code]) : Verification::create(['username' => $phone_number, 'code' => $phone_code]);
|
||||
|
||||
sendSMS($phone_number, 'Tassyklaýyş belgi: '.$phone_code);
|
||||
|
||||
return $verification;
|
||||
}
|
||||
Reference in New Issue
Block a user