Here is Laravel sample code that sends an OTP and a notification using the Wosocial API (https://wosocial.com/api/send), you can follow these steps:
composer create-project --prefer-dist laravel/laravel laravel-otp-notification cd laravel-otp-notification
php artisan make:controller OtpNotificationController
namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; class OtpNotificationController extends Controller { public function sendOtpAndNotification(Request $request) { // Replace these values with your actual credentials $instanceId = 'your_instance_id'; $accessToken = 'your_access_token'; // Generate a random OTP (you can use a more secure method) $otp = rand(1000, 9999); // Define the API endpoint and data to be sent $apiUrl = 'https://wosocial.com/api/send'; $apiData = [ 'number' => $request->input('number'), 'type' => 'text', 'message' => "Your OTP is: $otp", 'instance_id' => $instanceId, 'access_token' => $accessToken, ]; // Send the OTP and notification using the API $response = Http::post($apiUrl, $apiData); // Check if the API request was successful if ($response->successful()) { return response()->json(['message' => 'OTP and notification sent successfully']); } else { return response()->json(['error' => 'Failed to send OTP and notification'], 500); } } }
use Illuminate\Support\Facades\Route; use App\Http\Controllers\OtpNotificationController; Route::post('/send-otp-notification', [OtpNotificationController::class, 'sendOtpAndNotification']);
{ "number": "1234567890", // Replace with the recipient's phone number "type": "text", "message": "Your OTP is: 1234", // Replace with the desired OTP message }
Replace your_instance_id and your_access_token in the controller with your actual API credentials provided by the service.
This code will send an OTP and a notification to the specified phone number using the provided API. Make sure to handle error cases and implement appropriate error handling as per your project's requirements.