<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SMSController extends Controller
{
    //
    public function send($message, $to)
    {
        $apiKey  = env('SMS_API_KEY');
        $clientID = env('SMS_CLIENT_ID');
        $sid = env('SMS_SID');
        $fl = env('SMS_FL');
        $gwid = env('SMS_GWID');
        $msisdn = str_replace("+", "", $to);
        $msisdn = substr($msisdn, -10); // with new API, only

        $url = env('SMS_URL');


        $data = array('mobileNumbers' => $msisdn, 'SenderId' => $sid, 'Message' => $message, 'Is_Flash' => $fl, 'clientid' => $clientID, 'apiKey' => $apiKey);
        $data = http_build_query($data);

        // dd($data);

        $getURL = $url . 'SendSMS?' . $data;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $getURL);
        $result = curl_exec($ch);
        curl_close($ch);
        dd($result, $data);
        return $result;
    }
}
