| Server IP : 188.114.96.2 / Your IP : 104.23.197.231 Web Server : Apache/2.4.59 (Debian) System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : edlftp ( 1002) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/git/sms.edl.codes.solutions/application/models/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sms_model extends CI_Model {
public function __construct() {
parent::__construct();
}
//COMMON FUNCTION FOR SENDING SMS
function send_sms($message = '' , $reciever_phone = '')
{
$active_sms_service = $this->db->get_where('settings' , array(
'type' => 'active_sms_service'
))->row()->description;
if ($active_sms_service == '' || $active_sms_service == 'disabled')
return;
if ($active_sms_service == 'clickatell') {
$this->send_sms_via_clickatell($message , $reciever_phone );
}
if ($active_sms_service == 'twilio') {
$this->send_sms_via_twilio($message , $reciever_phone );
}
if ($active_sms_service == 'msg91') {
$this->send_sms_via_msg91($message , $reciever_phone );
}
}
// SEND SMS VIA CLICKATELL API
function send_sms_via_clickatell($message = '' , $reciever_phone = '') {
$clickatell_user = $this->db->get_where('settings', array('type' => 'clickatell_user'))->row()->description;
$clickatell_password = $this->db->get_where('settings', array('type' => 'clickatell_password'))->row()->description;
$clickatell_api_id = $this->db->get_where('settings', array('type' => 'clickatell_api_id'))->row()->description;
$clickatell_baseurl = "http://api.clickatell.com";
$text = urlencode($message);
$to = $reciever_phone;
// auth call
$url = "$clickatell_baseurl/http/auth?user=$clickatell_user&password=$clickatell_password&api_id=$clickatell_api_id";
// do auth call
$ret = file($url);
// explode our response. return string is on first line of the data returned
$sess = explode(":",$ret[0]);
print_r($sess);echo '<br>';
if ($sess[0] == "OK") {
$sess_id = trim($sess[1]); // remove any whitespace
$url = "$clickatell_baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$text";
// do sendmsg call
$ret = file($url);
$send = explode(":",$ret[0]);
print_r($send);echo '<br>';
if ($send[0] == "ID") {
echo "successnmessage ID: ". $send[1];
} else {
echo "send message failed";
}
} else {
echo "Authentication failure: ". $ret[0];
}
}
// SEND SMS VIA TWILIO API
function send_sms_via_twilio($message = '' , $reciever_phone = '') {
// LOAD TWILIO LIBRARY
require_once(APPPATH . 'libraries/twilio_library/Twilio.php');
$account_sid = $this->db->get_where('settings', array('type' => 'twilio_account_sid'))->row()->description;
$auth_token = $this->db->get_where('settings', array('type' => 'twilio_auth_token'))->row()->description;
$client = new Services_Twilio($account_sid, $auth_token);
$client->account->messages->create(array(
'To' => $reciever_phone,
'From' => $this->db->get_where('settings', array('type' => 'twilio_sender_phone_number'))->row()->description,
'Body' => $message
));
}
//SMS via msg91
function send_sms_via_msg91($message = '' , $reciever_phone = '') {
$authKey = $this->db->get_where('settings', array('type' => 'msg91_authentication_key'))->row()->description;
$senderId = $this->db->get_where('settings', array('type' => 'msg91_sender_ID'))->row()->description;
$country_code = $this->db->get_where('settings', array('type' => 'msg91_country_code'))->row()->description;
$route = $this->db->get_where('settings', array('type' => 'msg91_route'))->row()->description;
//Multiple mobiles numbers separated by comma
$mobileNumber = $reciever_phone;
//Your message to send, Add URL encoding here.
$message = urlencode($message);
//Prepare you post parameters
$postData = array(
'authkey' => $authKey,
'mobiles' => $mobileNumber,
'message' => $message,
'sender' => $senderId,
'route' => $route,
'country' => $country_code
);
//API URL
$url="http://api.msg91.com/api/sendhttp.php";
// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData
//,CURLOPT_FOLLOWLOCATION => true
));
//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//get response
$output = curl_exec($ch);
//Print error if any
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
}
}