feat: add otp sms
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use App\Helpers\MobileNumberHelper;
|
use App\Helpers\MobileNumberHelper;
|
||||||
use App\Jobs\SendSMSJob;
|
use App\Jobs\SendSMSJob;
|
||||||
|
use App\Jobs\SendOTPJob;
|
||||||
use App\Models\PackageName;
|
use App\Models\PackageName;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\Transaction;
|
use App\Models\Transaction;
|
||||||
@@ -392,12 +393,13 @@ public function loginOTP(Request $request)
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$verify = Str::random(8);
|
$verify = Str::random(8);
|
||||||
SendSMSJob::dispatch([
|
SendOTPJob::dispatch($data['mobile'], (string)$otpToken);
|
||||||
'mobile' => $data['mobile'],
|
// SendSMSJob::dispatch([
|
||||||
'message' => "کد ورود به برنامه: $otpToken
|
// 'mobile' => $data['mobile'],
|
||||||
@{$packageName->web_app_url} #$otpToken
|
// 'message' => "کد ورود به برنامه: $otpToken
|
||||||
لغو 11"
|
// @{$packageName->web_app_url} #$otpToken
|
||||||
]);
|
// لغو 11"
|
||||||
|
// ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$user->packageNames()->where('package_names.id', $packageName->id)->exists()) {
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+10
-1
@@ -1,5 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'url' => 'https://api.kavenegar.com/v1/' . env('KAVE_API_KEY') . '/sms/send.json'
|
'base_url' => 'https://api.kavenegar.com/v1/',
|
||||||
|
'api_key' => env('KAVE_API_KEY'),
|
||||||
|
'template' => 'loginotp'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// return [
|
||||||
|
// 'url' => 'https://api.kavenegar.com/v1/' . env('KAVE_API_KEY') . '/verify/lookup.json'
|
||||||
|
// ];
|
||||||
|
|||||||
Reference in New Issue
Block a user