digihub

Set up CodeIgniter

-> Make sure you have CodeIgniter installed and configured properly.

Create a Controller:

-> Create a new controller in CodeIgniter, e.g., NotificationController.php. This controller will handle the API request.

Create a Function:

-> Inside your NotificationController, create a function to send the OTP and notifications using the provided API.

defined('BASEPATH') OR exit('No direct script access allowed');

class NotificationController extends CI_Controller {

    public function sendNotification() {
        // Get the input data
        $number = $this->input->post('number');
        $message = $this->input->post('message');
        $instance_id = $this->input->post('instance_id');
        $access_token = $this->input->post('access_token');

        // Prepare the data for the API request
        $data = array(
            'number' => $number,
            'type' => 'text',
            'message' => $message,
            'instance_id' => $instance_id,
            'access_token' => $access_token,
        );

        // Convert data to JSON
        $json_data = json_encode($data);

        // Set the API URL
        $api_url = 'https://wosocial.com/api/send';

        // Initialize cURL session
        $ch = curl_init($api_url);

        // Set cURL options
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($json_data)
        ));

        // Execute cURL session
        $response = curl_exec($ch);

        // Close cURL session
        curl_close($ch);

        // Handle the API response (you can customize this part)
        if ($response) {
            // Successful response from the API
            echo "Notification sent successfully!";
        } else {
            // Error occurred
            echo "Failed to send notification.";
        }
    }
}
Create a Form:

-> Create a form in your view to collect the necessary information, such as the phone number, message, instance_id, and access_token. Make sure the form submits a POST request to the sendNotification function in your NotificationController.

Route the URL:

-> Configure CodeIgniter routes to map a URL to the sendNotification function in your NotificationController.

Now, when you submit the form with the required data, it will send a POST request to the sendNotification function, which will, in turn, make a POST request to the provided API to send the OTP and notification.

Please note that you should implement proper error handling, validation, and security measures in your code as needed for a production application.