示例#1
0
 function __construct()
 {
     require_once 'topfile.php';
     if (isset($_REQUEST['gmidentity']) && isset($_REQUEST['gmmessage'])) {
         #sanitization
         $this->gmidentity = $db->real_escape_string($_REQUEST['gmidentity']);
         $this->gmmessage = $db->real_escape_string($_REQUEST['gmmessage']);
         #check empty
         if (!empty($this->gmidentity) && !empty($this->gmmessage)) {
             if ($group_msg == 1) {
                 # GET PHONE NUMBERS AND GROUP DATA
                 $gd = $db->query("SELECT * FROM `sms_group_members` WHERE `group`='{$this->gmidentity}'");
                 while ($userdata = $gd->fetch_array()) {
                     $user_id = $userdata['member'];
                     # get phone number
                     $user_tbl_check = $db->query("SELECT * FROM `sms_contacts` WHERE `id`='{$user_id}'");
                     $data_nos = $user_tbl_check->fetch_array();
                     $listNos .= $data_nos['phone_number'] . ",";
                 }
                 $grd = $db->query("SELECT * FROM `sms_groups` WHERE `id`='{$this->gmidentity}'");
                 $group_data = $grd->fetch_array();
                 $groupName = $group_data['group_name'];
                 # SMS Code
                 $username = $as_username;
                 $apikey = $as_key;
                 if ($as_sender_id == "") {
                     $from = "SMSLEOPARD";
                 } else {
                     $from = $as_sender_id;
                 }
                 $recipients = $listNos;
                 $message = $this->gmmessage;
                 $gateway = new AfricasTalkingGateway($username, $apikey);
                 try {
                     $results = $gateway->sendMessage($recipients, $message, $from);
                     if ($results) {
                         $date = date('d-M-Y H:i:s');
                         //save record
                         $saveRecord = $db->query("INSERT INTO `sms_logs`(`sent_to`,`message`,`date`,`by`)\n\t\t\t\t\t\t\t\t\t                                       VALUES('{$groupName}','{$this->gmmessage}','{$date}','{$_SESSION['bulkadmin']}')");
                         if ($mybalance < $setminimum) {
                             $savemin = $db->query("INSERT INTO `sms_activity`(`activity_log`)\n\t\t\t\t\t\t\t\t\t                                        VALUES('lowcredit')");
                         }
                     }
                     if ($saveRecord) {
                         echo '<p style="color:green"><i class="fa fa-check-square"></i> Message sent</p>';
                     }
                 } catch (AfricasTalkingGatewayException $e) {
                     echo "Encountered an error while sending: " . $e->getMessage();
                 }
             } else {
                 echo '<p style="color:orange"><i class="fa fa-lock"></i> Sorry, you do not have permissions to send open messages</p>';
             }
         } else {
             echo '<p style="color:orange">Please provide phone number and message</p>';
         }
     }
 }
示例#2
0
 function __construct()
 {
     require_once 'topfile.php';
     if (isset($_REQUEST['inlineno']) && isset($_REQUEST['inlinemsg'])) {
         #sanitization
         $this->inlineno = $db->real_escape_string($_REQUEST['inlineno']);
         $this->inlinemsg = $db->real_escape_string($_REQUEST['inlinemsg']);
         #check empty
         if (!empty($this->inlineno) && !empty($this->inlinemsg)) {
             if ($open_msg == 1) {
                 if (strpos($this->inlineno, '+') !== false) {
                     # SMS Code
                     $username = $as_username;
                     $apikey = $as_key;
                     if ($as_sender_id == "") {
                         $from = "SMSLEOPARD";
                     } else {
                         $from = $as_sender_id;
                     }
                     $recipients = $this->inlineno;
                     $message = $this->inlinemsg;
                     $gateway = new AfricasTalkingGateway($username, $apikey);
                     try {
                         $results = $gateway->sendMessage($recipients, $message, $from);
                         if ($results) {
                             $date = date('d-M-Y H:i:s');
                             //save record
                             $saveRecord = $db->query("INSERT INTO `sms_logs`(`sent_to`,`message`,`date`,`by`)\n\t\t\t\t\t\t\t\t\t                                       VALUES('{$recipients}','{$message}','{$date}','{$_SESSION['bulkadmin']}')");
                             if ($mybalance < $setminimum) {
                                 $savemin = $db->query("INSERT INTO `sms_activity`(`activity_log`)\n\t\t\t\t\t\t\t\t\t                                        VALUES('lowcredit')");
                             }
                         }
                         if ($saveRecord) {
                             echo '<p style="color:green"><i class="fa fa-check-square"></i> Message sent</p>';
                         }
                     } catch (AfricasTalkingGatewayException $e) {
                         echo "Encountered an error while sending: " . $e->getMessage();
                     }
                 } else {
                     echo '<p style="color:orange">Phone number should be in full international format (+25478*****)</p>';
                 }
             } else {
                 echo '<p style="color:orange"><i class="fa fa-lock"></i> Sorry, you do not have permissions to send open messages</p>';
             }
         } else {
             echo '<p style="color:orange">Please provide phone number and message</p>';
         }
     }
 }
示例#3
0
 public function sendSMSFromArray($to, $message)
 {
     // Be sure to include the file you've just downloaded
     $recipients = array();
     foreach ($to as $key => $value) {
         $to = substr($value, -9);
         $to_end = '+254' . $to;
         array_push($recipients, $to_end);
     }
     if (count($recipients) > 0) {
         $recpts = implode(',', $recipients);
         // require_once('../libraries/AfricasTalkingGateway.php');
         // Specify your login credentials
         $username = "******";
         $apikey = "abbfa09e621a6ece272a254e3fcd910657ff46e88f82db205499603d06dda908";
         // Specify the numbers that you want to send to in a comma-separated list
         // Please ensure you include the country code (+254 for Kenya in this case)
         $recipients = '+254' . $to;
         //can be comma separeted
         $from = '20151';
         // Create a new instance of our awesome gateway class
         $gateway = new AfricasTalkingGateway($username, $apikey);
         // Any gateway errors will be captured by our custom Exception class below,
         // so wrap the call in a try-catch block
         try {
             // Thats it, hit send and we'll take care of the rest.
             $results = $gateway->sendMessage($recpts, $message, $from);
             if ($results) {
                 return $results;
             } else {
                 return 0;
             }
             // foreach($results as $result) {
             // // Note that only the Status "Success" means the message was sent
             // echo " Number: " .$result->number;
             // echo " Status: " .$result->status;
             // echo " MessageId: " .$result->messageId;
             // echo " Cost: "   .$result->cost."\n";
             // }
         } catch (AfricasTalkingGatewayException $e) {
             echo "Encountered an error while sending: " . $e->getMessage();
         }
     } else {
         return 0;
     }
     // DONE!!!
 }
示例#4
0
文件: Sms.php 项目: normanmunge/cf
 public function sendSms($recipients, $message)
 {
     $gateway = new AfricasTalkingGateway($this->username, $this->apikey);
     // Any gateway errors will be captured by our custom Exception class below,
     // so wrap the call in a try-catch block
     try {
         // Thats it, hit send and we'll take care of the rest.
         $results = $gateway->sendMessage($recipients, $message);
         foreach ($results as $result) {
             $newSend = new SentMessages();
             $newSend->number = $result->number;
             $newSend->message_id = $result->messageId;
             $newSend->status = $result->status;
             $newSend->save();
             // Note that only the Status "Success" means the message was sent
             echo " Number: " . $result->number;
             echo " Status: " . $result->status;
             echo " MessageId: " . $result->messageId;
             echo " Cost: " . $result->cost . "\n";
         }
     } catch (AfricasTalkingGatewayException $e) {
         echo "Encountered an error while sending: " . $e->getMessage();
     }
 }
function sendSMS($recipient, $message)
{
    require_once 'AfricasTalkingGateway.php';
    // Specify your login credentials
    $username = "******";
    $apikey = "";
    $recipients = $recipient;
    $gateway = new AfricasTalkingGateway($username, $apikey);
    try {
        // Thats it, hit send and we'll take care of the rest.
        $results = $gateway->sendMessage($recipients, $message);
        foreach ($results as $result) {
            // status is either "Success" or "error message"
            echo " Number: " . $result->number;
            echo " Status: " . $result->status;
            echo " MessageId: " . $result->messageId;
            echo " Cost: " . $result->cost . "\n";
        }
    } catch (AfricasTalkingGatewayException $e) {
        echo "Encountered an error while sending: " . $e->getMessage();
    }
}
示例#6
0
function sms($to, $msg)
{
    // Create a new instance of our awesome gateway class
    $gateway = new AfricasTalkingGateway(getenv('SMS_USER'), getenv('SMS_KEY'));
    try {
        // Thats it, hit send and we'll take care of the rest.
        $results = $gateway->sendMessage($to, $msg);
        if ($results) {
            return true;
        }
        return false;
    } catch (AfricasTalkingGatewayException $e) {
        echo "Encountered an error while sending: " . $e->getMessage();
    }
}
示例#7
0
 public function sendSMS($phone_number, $output, $shortcode = 20151, $sms_gateway_id = null)
 {
     // echo "hapa";
     // exit;
     //$phone_number = "+254728355429";
     //invalidating stuff
     //$phone_number = "+254728355429dfsdg";
     $shortcode = 20151;
     if ($shortcode > 1) {
         $username = "******";
         $apiKey = "abbfa09e621a6ece272a254e3fcd910657ff46e88f82db205499603d06dda908";
         $gateway = new AfricasTalkingGateway($username, $apiKey);
         //print_r(is_array($output));
         //exit;
         if (is_array($output)) {
             //print_r($output);
             //exit;
             foreach ($output as $key => $value) {
                 //print_r($shortcode);
                 //exit;
                 $value = $value;
                 try {
                     // Send a response originating from the short code that received the message
                     $results = $gateway->sendMessage($phone_number, $value, $shortcode);
                     //$results = $gateway -> sendMessage("+254728355429", $value, $shortcode);
                     // Read in the gateway response and persist if necessary
                     $response = $results[0];
                     $status = $response->status;
                     $cost = $response->cost;
                     //print_r($value);
                     //print_r($status);
                     //exit;
                 } catch (AfricasTalkingGatewayException $e) {
                     // Log the error
                     $errorMessage = $e->getMessage();
                     //print_r($errorMessage);
                     //exit;
                 }
                 //print_r($value);
                 //exit;
             }
             //exit;
         } else {
             try {
                 //Send a response originating from the short code that received the message
                 //$results = $gateway -> sendMessage('+254728355429', $output, $shortcode);
                 $output = $output;
                 //print_r($append);
                 //exit;
                 $results = $gateway->sendMessage($phone_number, $output, $shortcode);
                 // Read in the gateway response and persist if necessary
                 $response = $results[0];
                 $status = $response->status;
                 $cost = $response->cost;
                 //print_r($output);
                 //print_r($status);
                 //exit ;
             } catch (AfricasTalkingGatewayException $e) {
                 // Log the error
                 $errorMessage = $e->getMessage();
             }
         }
     } elseif ($sms_gateway_id = 3) {
         //telerivet magic over here
         //require_once ('AfricasTalkingGateway.php');
         header("Content-Type: application/json");
         echo json_encode(array('messages' => array(array('content' => $output))));
         //echo "tel".$output;
         exit;
     } else {
         //$output = json_decode($output);
         if (is_array($output)) {
             foreach ($output as $key => $value) {
                 print_r("array " . $value);
                 exit;
             }
         } else {
             //echo "hapa";
             //print_r($output);
             //exit ;
         }
     }
     //exit;
 }
// Be sure to include the file you've just downloaded
require_once 'AfricasTalkingGateway.php';
// Specify your login credentials
$username = "******";
$apikey = "b363386c84d13496370e9a4b8ba60d8daa98e4a6a41289d392e08b2ee7996f41";
// Specify the numbers that you want to send to in a comma-separated list
// Please ensure you include the country code (+254 for Kenya in this case)
$recipients = "+255674852612";
// $recipients = "+254725813847";
// And of course we want our recipients to know what we really do
// $message    = "I'm a lumberjack and its ok, I sleep all night and I work all day";
$message = "Sema, huyu ni Amina. This is a test. Jibu kwa whatsapp kama umepata hii message.";
// Create a new instance of our awesome gateway class
$gateway = new AfricasTalkingGateway($username, $apikey);
// Any gateway error will be captured by our custom Exception class below,
// so wrap the call in a try-catch block
try {
    // Thats it, hit send and we'll take care of the rest.
    $results = $gateway->sendMessage($recipients, $message);
    foreach ($results as $result) {
        // status is either "Success" or "error message"
        echo " Number: " . $result->number;
        echo " Status: " . $result->status;
        echo " MessageId: " . $result->messageId;
        echo " Cost: " . $result->cost . "\n";
    }
} catch (AfricasTalkingGatewayException $e) {
    echo "Encountered an error while sending: " . $e->getMessage();
}
// DONE!!!
<?php

require_once 'AfricasTalkingGateway.php';
$username = "******";
$apikey = "MyAfricasTalkingAPIKey";
$recipients = "+254711XXXYYY,+254722YYYZZZ";
// Specify your premium shortCode and keyword
$shortCode = "XXXXX";
$keyword = "premiumKeyword";
// Set the bulkSMSMode flag to 0 so that the subscriber gets charged
$bulkSMSMode = 0;
// Create an array which would hold the following parameters:
// keyword: Your premium keyword,
// retryDurationInHours: The numbers of hours our API should retry to send the message
// incase it doesn't go through. It is optional
$options = array('keyword' => $keyword, 'retryDurationInHours' => "No of hours to retry");
$message = "Get your daily message and thats how we roll.";
$gateway = new AfricasTalkingGateway($username, $apikey);
try {
    $results = $gateway->sendMessage($recipients, $message, $shortCode, $bulkSMSMode, $options);
    foreach ($results as $result) {
        echo " Number: " . $result->number;
        echo " Status: " . $result->status;
        echo " MessageId: " . $result->messageId . "\n";
    }
} catch (AfricasTalkingGatewayException $e) {
    echo "Encountered an error while sending: " . $e->getMessage();
}
示例#10
0
function sendSMS($msg, $recipient)
{
    require_once 'AfricasTalkingGateway.php';
    // Specify your login credentials
    $username = "";
    $apikey = "";
    // Specify the numbers that you want to send to in a comma-separated list
    // Please ensure you include the country code (+254 for Kenya in this case)
    $recipients = "+254718931397";
    //$recipients = $recipient;
    // And of course we want our recipients to know what we really do
    //$message    = "I'm a lumberjack and its ok, I sleep all night and I work all day";
    $message = $msg;
    // Create a new instance of our awesome gateway class
    $gateway = new AfricasTalkingGateway($username, $apikey);
    // Any gateway errors will be captured by our custom Exception class below,
    // so wrap the call in a try-catch block
    try {
        // Thats it, hit send and we'll take care of the rest.
        $results = $gateway->sendMessage($recipients, $message, $from);
        foreach ($results as $result) {
            // Note that only the Status "Success" means the message was sent
            echo " Number: " . $result->number;
            echo " Status: " . $result->status;
            echo " MessageId: " . $result->messageId;
            echo " Cost: " . $result->cost . "\n";
        }
    } catch (AfricasTalkingGatewayException $e) {
        echo "Encountered an error while sending: " . $e->getMessage();
    }
    // DONE!!!
}
示例#11
0
 function __construct()
 {
     if (isset($_REQUEST['loginusername']) && isset($_REQUEST['loginpassword'])) {
         require_once 'config.php';
         #sanitization
         $this->dbo_ = $db;
         $this->username = $this->dbo_->real_escape_string($_REQUEST['loginusername']);
         $this->password = $this->dbo_->real_escape_string($_REQUEST['loginpassword']);
         #check empty
         if (!empty($this->username) && !empty($this->password)) {
             #convert password
             $passhash = md5($this->password);
             #check against database for record
             $login = $this->dbo_->query("SELECT * from `sms_users` WHERE `username`='{$this->username}' && `password`='{$passhash}'");
             if ($login->num_rows > 0) {
                 # get some user data
                 $userdata = $login->fetch_array();
                 $userphone = $userdata['phone'];
                 # check login pass type
                 $passtype = "SELECT * FROM `sms_settings`";
                 if ($passtype_run = $this->dbo_->query($passtype)) {
                     $passtype_data = $passtype_run->fetch_array();
                     # fetch needed data, in our case 2 factor login,as_username,as_pass and as_sender
                     $allow2factor = $passtype_data['security_2_factor'];
                     $as_username = $passtype_data['as_username'];
                     $as_key = $passtype_data['as_key'];
                     $as_sender_id = $passtype_data['as_sender_id'];
                     if ($allow2factor == 2) {
                         # Generate two factor code
                         $remote_access_code = rand(1000, 9999);
                         $this->dbo_->query("UPDATE `sms_users` SET `login_pass`='{$remote_access_code}' WHERE `username`='{$this->username}'");
                         # SMS Code
                         $username = $as_username;
                         $apikey = $as_key;
                         if ($as_sender_id == "") {
                             $from = "SMSLEOPARD";
                         } else {
                             $from = $as_sender_id;
                         }
                         $recipients = $userphone;
                         $message = "Your login code is " . $remote_access_code;
                         $gateway = new AfricasTalkingGateway($username, $apikey);
                         try {
                             $results = $gateway->sendMessage($recipients, $message, $from);
                             if ($results) {
                                 $_SESSION['sandbox'] = $this->username;
                                 echo $this->json_encoder("runsteptwo");
                             }
                         } catch (AfricasTalkingGatewayException $e) {
                             echo "Encountered an error while sending: " . $e->getMessage();
                         }
                     } else {
                         $_SESSION['bulkadmin'] = $this->username;
                         echo $this->json_encoder("successlogin");
                     }
                 } else {
                     echo '<p style="color:orange;"> Something went wrong</p>';
                 }
             } else {
                 echo '<p style="color:orange;"> Wrong Username or Password</p>';
             }
         } else {
             echo '<p style="color:orange;">Please fill all fields</p>';
         }
     }
 }
 public function sendSms($recipients, $message)
 {
     // Be sure to include the file you've just downloaded
     require_once 'AfricasTalkingGateway.php';
     // Specify your login credentials
     $username = "******";
     $apikey = "b363386c84d13496370e9a4b8ba60d8daa98e4a6a41289d392e08b2ee7996f41";
     // $recipients = "+254725813847";
     // $recipients;
     // echo $message    = "This is a test. This is victor.";
     // $message;
     // Create a new instance of our awesome gateway class
     $gateway = new AfricasTalkingGateway($username, $apikey);
     // Any gateway error will be captured by our custom Exception class below,
     // so wrap the call in a try-catch block
     try {
         // Thats it, hit send and we'll take care of the rest.
         $results = $gateway->sendMessage($recipients, $message);
         foreach ($results as $result) {
             // status is either "Success" or "error message"
             // echo " Number: " .$result->number;
             // echo " Status: " .$result->status;
             // echo " MessageId: " .$result->messageId;
             // echo " Cost: "   .$result->cost."\n";
             return $result->status;
         }
     } catch (AfricasTalkingGatewayException $e) {
         return "Encountered an error while sending: " . $e->getMessage();
     }
 }