feat: add otp sms
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Helpers\MobileNumberHelper;
|
||||
use App\Jobs\SendSMSJob;
|
||||
use App\Jobs\SendOTPJob;
|
||||
use App\Models\PackageName;
|
||||
use App\Models\Product;
|
||||
use App\Models\Transaction;
|
||||
@@ -392,12 +393,13 @@ public function loginOTP(Request $request)
|
||||
]);
|
||||
|
||||
$verify = Str::random(8);
|
||||
SendSMSJob::dispatch([
|
||||
'mobile' => $data['mobile'],
|
||||
'message' => "کد ورود به برنامه: $otpToken
|
||||
@{$packageName->web_app_url} #$otpToken
|
||||
لغو 11"
|
||||
]);
|
||||
SendOTPJob::dispatch($data['mobile'], (string)$otpToken);
|
||||
// SendSMSJob::dispatch([
|
||||
// 'mobile' => $data['mobile'],
|
||||
// 'message' => "کد ورود به برنامه: $otpToken
|
||||
// @{$packageName->web_app_url} #$otpToken
|
||||
// لغو 11"
|
||||
// ]);
|
||||
}
|
||||
|
||||
if (!$user->packageNames()->where('package_names.id', $packageName->id)->exists()) {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\KavenegarService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SendOTPJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
private string $mobile,
|
||||
private string $token
|
||||
) {}
|
||||
|
||||
public function handle(KavenegarService $service)
|
||||
{
|
||||
$response = $service->sendVerify($this->mobile, $this->token);
|
||||
|
||||
logger()->info('Kavenegar response', $response);
|
||||
|
||||
if (!isset($response['return']) || $response['return']['status'] != 200) {
|
||||
logger()->error('Kavenegar failed', $response);
|
||||
throw new \Exception(json_encode($response));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class KavenegarService
|
||||
{
|
||||
public function sendVerify(string $mobile, string $token)
|
||||
{
|
||||
$apiKey = config('kave.api_key');
|
||||
|
||||
if (!$apiKey) {
|
||||
throw new \Exception('KAVE_API_KEY is null');
|
||||
}
|
||||
|
||||
$url = "https://api.kavenegar.com/v1/{$apiKey}/verify/lookup.json";
|
||||
|
||||
$response = Http::timeout(5)->get($url, [
|
||||
'receptor' => $mobile,
|
||||
'token' => $token,
|
||||
'template' => config('kave.template'),
|
||||
]);
|
||||
|
||||
logger()->info('Kavenegar raw', [
|
||||
'url' => $url,
|
||||
'status' => $response->status(),
|
||||
'body' => $response->body(),
|
||||
]);
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user