Beispiel #1
0
 public function configSms()
 {
     $response['title'] = '';
     $smsBalance = getSmsBalance();
     if ($smsBalance) {
         $response['sms_balance'] = $smsBalance;
     }
     $smsConfigSettings = getSmsConfig();
     if (isset($smsConfigSettings['config_settings'])) {
         $response['config_settings'] = $smsConfigSettings['config_settings'];
     }
     $this->load->view('controlcentre/configurations/sms/sms_settings', $response);
 }
 function sendSms($data)
 {
     $CI =& get_instance();
     $smsConfig = getSmsConfig();
     if (isset($smsConfig['no_sms_config_settings']) && $smsConfig['no_sms_config_settings']) {
         $demo_config_settings = $smsConfig['demo_config_settings'];
         $username = $demo_config_settings['username'];
         $password = $demo_config_settings['password'];
         $url = $demo_config_settings['url'];
     } else {
         $username = $smsConfig['config_settings']->account_holder;
         $password = $CI->encrypt->decode(trim($smsConfig['config_settings']->account_password));
         $url = $smsConfig['config_settings']->api_base_url . '' . $smsConfig['config_settings']->single_sms_url;
     }
     $string = $username . ":" . $password;
     $encodedString = "Basic " . base64_encode($string);
     $payload = json_encode(array('from' => $data['sender'], 'to' => $data['recipient'], 'text' => $data['message']));
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'authorization: ' . $encodedString));
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     // Make it so the data coming back is put into a string
     try {
         // Send the request
         $result = curl_exec($curl);
     } catch (Exception $ex) {
         $result['status'] = 'failure';
     }
     if (!empty($result)) {
         $responseArray = json_decode($result);
         //$responseArray = $responseArray['balance'];
     } else {
         $responseArray = false;
     }
     // Free up the resources $curl is using
     curl_close($curl);
     return $responseArray;
 }