Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- private $smsapiurl = "http://api.ebulksms.com:8080/sendsms.json";
- private $username = 'voncloudy@gmail.com';
- private $apikey = 'f940bec4b2301bdced007215f04a492f34da622f';
- private $sendername = "Delta MLHS";
- public function sendSMS($url, $username, $apikey, $flash, $sendername, $messagetext, $recipients) {
- $gsm = array();
- $country_code = '234';
- $arr_recipient = explode(',', $recipients);
- foreach ($arr_recipient as $recipient) {
- $mobilenumber = trim($recipient);
- if (substr($mobilenumber, 0, 1) == '0'){
- $mobilenumber = $country_code . substr($mobilenumber, 1);
- }
- elseif (substr($mobilenumber, 0, 1) == '+'){
- $mobilenumber = substr($mobilenumber, 1);
- }
- $generated_id = uniqid('int_', false);
- $generated_id = substr($generated_id, 0, 30);
- $gsm['gsm'][] = array('msidn' => $mobilenumber, 'msgid' => $generated_id);
- }
- $message = array(
- 'sender' => $sendername,
- 'messagetext' => $messagetext,
- 'flash' => "{$flash}",
- );
- $request = array('SMS' => array(
- 'auth' => array(
- 'username' => $username,
- 'apikey' => $apikey
- ),
- 'message' => $message,
- 'recipients' => $gsm
- ));
- //return $request;
- $json_data = json_encode($request);
- //return $json_data;
- if ($json_data) {
- $response = $this->doPostRequest($url, $json_data, array('Content-Type: application/json'));
- $result = json_decode($response);
- return $result;//->response->status;
- }
- else{
- return false;
- }
- }
- public function doPostRequest($url, $data, $headers = array()) {
- $php_errormsg = '';
- if (is_array($data)) {
- $data = http_build_query($data, '', '&');
- }
- $params = array('http' => array(
- 'method' => 'POST',
- 'content' => $data)
- );
- if ($headers !== null) {
- $params['http']['header'] = $headers;
- }
- $ctx = stream_context_create($params);
- $fp = fopen($url, 'rb', false, $ctx);
- if (!$fp) {
- return "Error: gateway is inaccessible";
- }
- //stream_set_timeout($fp, 0, 250);
- try {
- $response = stream_get_contents($fp);
- if ($response === false) {
- throw new Exception("Problem reading data from $url, $php_errormsg");
- }
- return $response;
- }
- catch (Exception $e) {
- $response = $e->getMessage();
- return $response;
- }
- }
- $recipients = $this->security->xss_clean($this->input->post('gsm'));
- $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";
- $flash = 0;
- if (get_magic_quotes_gpc()) {
- $message = stripslashes($message);
- }
- $smsurl = $this->smsapiurl;
- $apiusername = $this->username;
- $smsapikey = $this->apikey;
- $smssendername = $this->sendername;
- $api_request = $this->sendSMS($smsurl, $apiusername, $smsapikey, $flash, $smssendername, $message, $recipients);
- var_dump($api_request); exit;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement