Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.99 KB | None | 0 0
  1. <?php
  2.     private $smsapiurl = "http://api.ebulksms.com:8080/sendsms.json";
  3.     private $username = 'voncloudy@gmail.com';
  4.     private $apikey = 'f940bec4b2301bdced007215f04a492f34da622f';
  5.     private $sendername = "Delta MLHS";
  6.  
  7.     public function sendSMS($url, $username, $apikey, $flash, $sendername, $messagetext, $recipients) {
  8.         $gsm = array();
  9.         $country_code = '234';
  10.         $arr_recipient = explode(',', $recipients);
  11.  
  12.         foreach ($arr_recipient as $recipient) {
  13.             $mobilenumber = trim($recipient);
  14.  
  15.             if (substr($mobilenumber, 0, 1) == '0'){
  16.                 $mobilenumber = $country_code . substr($mobilenumber, 1);
  17.             }
  18.             elseif (substr($mobilenumber, 0, 1) == '+'){
  19.                 $mobilenumber = substr($mobilenumber, 1);
  20.             }
  21.  
  22.             $generated_id = uniqid('int_', false);
  23.             $generated_id = substr($generated_id, 0, 30);
  24.             $gsm['gsm'][] = array('msidn' => $mobilenumber, 'msgid' => $generated_id);
  25.         }
  26.  
  27.         $message = array(
  28.             'sender' => $sendername,
  29.             'messagetext' => $messagetext,
  30.             'flash' => "{$flash}",
  31.         );
  32.  
  33.         $request = array('SMS' => array(
  34.             'auth' => array(
  35.             'username' => $username,
  36.             'apikey' => $apikey
  37.             ),
  38.             'message' => $message,
  39.             'recipients' => $gsm
  40.         ));
  41.  
  42.         //return $request;
  43.  
  44.         $json_data = json_encode($request);
  45.         //return $json_data;
  46.         if ($json_data) {
  47.             $response = $this->doPostRequest($url, $json_data, array('Content-Type: application/json'));
  48.             $result = json_decode($response);
  49.             return $result;//->response->status;
  50.         }
  51.         else{
  52.             return false;
  53.         }
  54.     }
  55.  
  56.     public function  doPostRequest($url, $data, $headers = array()) {
  57.         $php_errormsg = '';
  58.         if (is_array($data)) {
  59.             $data = http_build_query($data, '', '&');
  60.         }
  61.  
  62.         $params = array('http' => array(
  63.             'method' => 'POST',
  64.             'content' => $data)
  65.         );
  66.  
  67.         if ($headers !== null) {
  68.             $params['http']['header'] = $headers;
  69.         }
  70.        
  71.         $ctx = stream_context_create($params);
  72.         $fp = fopen($url, 'rb', false, $ctx);
  73.        
  74.         if (!$fp) {
  75.             return "Error: gateway is inaccessible";
  76.         }
  77.  
  78.         //stream_set_timeout($fp, 0, 250);
  79.         try {
  80.             $response = stream_get_contents($fp);
  81.        
  82.             if ($response === false) {
  83.                 throw new Exception("Problem reading data from $url, $php_errormsg");
  84.             }
  85.             return $response;
  86.         }
  87.         catch (Exception $e) {
  88.             $response = $e->getMessage();
  89.             return $response;
  90.         }
  91.     }
  92.  
  93.  
  94. $recipients = $this->security->xss_clean($this->input->post('gsm'));
  95.                     $message = "Welcome to FastTrack 90 by the Ministry of Lands, Housing and Survey, Delta State, Your C of O title application with File No: " .$this->security->xss_clean($this->input->post('fileno')). " has been created";
  96.                     $flash = 0;
  97.  
  98.                     if (get_magic_quotes_gpc()) {
  99.                         $message = stripslashes($message);
  100.                     }
  101.  
  102.                     $smsurl = $this->smsapiurl;
  103.                     $apiusername = $this->username;
  104.                     $smsapikey = $this->apikey;
  105.                     $smssendername = $this->sendername;
  106.  
  107.                     $api_request = $this->sendSMS($smsurl, $apiusername, $smsapikey, $flash, $smssendername, $message, $recipients);
  108.                     var_dump($api_request); exit;
  109. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement