<?php
require 'vendor/autoload.php'; // Ensure you've installed Africa's Talking SDK via Composer

use AfricasTalking\SDK\AfricasTalking;

// Set your Africa's Talking API credentials
$username = 'your_username';
$apiKey = 'your_api_key';

// Initialize the SDK
$AT = new AfricasTalking($username, $apiKey);

// Get the phone number from the request
$phone = $_GET['phone'];

// Generate a new random password
$newPassword = bin2hex(random_bytes(4)); // 8 characters long

// Here, you should update the password in your MikroTik Hotspot system
// Assuming you have a function to update the password
updateUserPassword($phone, $newPassword);

// Define the message
$message = "Your new password is: $newPassword";

// Use the SMS service
$sms = $AT->sms();

// Send the message
try {
    $result = $sms->send([
        'to' => $phone,
        'message' => $message
    ]);
    echo "New password sent successfully!";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

// Function to update user password in MikroTik Hotspot system
function updateUserPassword($phone, $newPassword) {
    // Add your MikroTik Hotspot password update logic here
    // This might involve using MikroTik API or directly accessing the database
}
?>
