| Server IP : 138.197.176.125 / Your IP : 216.73.217.54 Web Server : Apache/2.4.41 (Ubuntu) System : Linux SuiteCRM-8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/soltelcocrm/modules/SMSNotifier/providers/ |
Upload File : |
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
class SMSNotifier_Soltelco_Provider implements SMSNotifier_ISMSProvider_Model {
private $userName;
private $password;
private $parameters = array();
const SERVICE_URI = 'https://sms.mytelesom.com/index.php/Gway/sendsms';
private static $REQUIRED_PARAMETERS = array('to', 'msg','from','key');
/**
* Function to get provider name
* @return <String> provider name
*/
public function getName() {
return 'Soltelco';
}
/**
* Function to get required parameters other than (userName, password)
* @return <array> required parameters list
*/
public function getRequiredParams() {
return self::$REQUIRED_PARAMETERS;
}
/**
* Function to get service URL to use for a given type
* @param <String> $type like SEND, PING, QUERY
*/
public function getServiceURL($type = false) {
if($type) {
switch(strtoupper($type)) {
case self::SERVICE_AUTH: return self::SERVICE_URI . '/http/auth';
case self::SERVICE_SEND: return self::SERVICE_URI . '/http/sendmsg';
case self::SERVICE_QUERY: return self::SERVICE_URI . '/http/querymsg';
}
}
return false;
}
/**
* Function to set authentication parameters
* @param <String> $userName
* @param <String> $password
*/
public function setAuthParameters($userName, $password) {
$this->userName = $userName;
$this->password = $password;
}
/**
* Function to set non-auth parameter.
* @param <String> $key
* @param <String> $value
*/
public function setParameter($key, $value) {
$this->parameters[$key] = $value;
}
/**
* Function to get parameter value
* @param <String> $key
* @param <String> $defaultValue
* @return <String> value/$default value
*/
public function getParameter($key, $defaultValue = false) {
if(isset($this->parameters[$key])) {
return $this->parameters[$key];
}
return $defaultValue;
}
/**
* Function to prepare parameters
* @return <Array> parameters
*/
protected function prepareParameters() {
$params = array('username' => $this->userName, 'password' => $this->password,'to'=>$this->to,'msg'=>$this->msg,'from'=>$this->from,'key'=>$this->key);
foreach (self::$REQUIRED_PARAMETERS as $key) {
$params[$key] = $this->getParameter($key);
}
return $params;
}
/**
* Function to handle SMS Send operation
* @param <String> $message
* @param <Mixed> $toNumbers One or Array of numbers
*/
public function send($message, $toNumbers) {
if(!is_array($toNumbers)) {
$toNumbers = array($toNumbers);
}
$params = $this->prepareParameters();
$params['text'] = $message;
$message = str_ireplace(" ", "%20", $message);
$params['to'] = $toNumbers;
$to = $params['to'];
$from = $params['from'];
$curentDate=date("d/m/Y");
$key = $params['key'];
$username = $params['username'];
$password = $params['password'];
$hashkey = strtoupper(md5($username . "|" . $password . "|" . $toNumbers ."|" . $message . "|" . $from . "|" . $curentDate . "|" . $key));
$results = array();
foreach($toNumbers as $toNumber) {
if(strlen($toNumber)==13){
$str1 = substr($toNumber,0,3);
$str2 = substr($toNumber,4,13);
$toNumber=$str1.$str2;
}
if(strlen($toNumber)==9){
$toNumber="972".$toNumber;
}
if(strlen($toNumber)==10){
$toNumber=ltrim($toNumber,"0");
$toNumber="972".$toNumber;
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://sms.mytelesom.com/index.php/Gway/sendsms',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('username' => $username,'password' => $passowrd,'to' => $toNumbers,'msg' => $message,'from' => $from,'date' => $curentDate,'key' => $hashkey),
));
$response = curl_exec($curl);
$apiResponse = json_decode($response, true);
curl_close($curl);
if($apiResponse['status'] == 'success'){
$result['to'] = $toNumber;
$result['status'] = self::MSG_STATUS_DELIVERED;
$results[] = $result;
}
}
return $results;
}
/**
* Function to get query for status using messgae id
* @param <Number> $messageId
*/
/*public function query($messageId) {
$params = $this->prepareParameters();
$params['apimsgid'] = $messageId;
$serviceURL = $this->getServiceURL(self::SERVICE_QUERY);
$httpClient = new Vtiger_Net_Client($serviceURL);
$response = $httpClient->doPost($params);
$response = trim($response);
$result = array( 'error' => false, 'needlookup' => 1, 'statusmessage' => '' );
if(preg_match("/ERR: (.*)/", $response, $matches)) {
$result['error'] = true;
$result['needlookup'] = 0;
$result['statusmessage'] = $matches[0];
} else if(preg_match("/ID: ([^ ]+) Status: ([^ ]+)/", $response, $matches)) {
$result['id'] = trim($matches[1]);
$status = trim($matches[2]);
// Capture the status code as message by default.
$result['statusmessage'] = "CODE: $status";
if($status == '002' || $status == '008' || $status == '011' ) {
$result['status'] = self::MSG_STATUS_PROCESSING;
} else if($status == '003' || $status == '004') {
$result['status'] = self::MSG_STATUS_DISPATCHED;
$result['needlookup'] = 0;
} else {
$statusMessage = '';
switch($status) {
case '001': $statusMessage = 'Message unknown'; break;
case '005': $statusMessage = 'Error with message'; break;
case '006': $statusMessage = 'User cancelled message delivery'; break;
case '007': $statusMessage = 'Error delivering message'; break;
case '009': $statusMessage = 'Routing error'; break;
case '010': $statusMessage = 'Message expired'; break;
case '012': $statusMessage = 'Out of credit'; break;
}
if(!empty($statusMessage)) {
$result['error'] = true;
$result['needlookup'] = 0;
$result['statusmessage'] = $statusMessage;
}
}
}
return $result;
}*/
public function query($messageId) {
$params = $this->prepareParameters();
$params['apimsgid'] = $messageId;
$serviceURL = $this->getServiceURL(self::SERVICE_QUERY);
$httpClient = new Vtiger_Net_Client($serviceURL);
$response = $httpClient->doPost($params);
$response = trim($response);
$result = array( 'error' => false, 'needlookup' => 1 );
if(preg_match("/ERR: (.*)/", $response, $matches)) {
$result['error'] = true;
$result['needlookup'] = 0;
$result['statusmessage'] = $matches[0];
} else if(preg_match("/ID: ([^ ]+) Status: ([^ ]+)/", $response, $matches)) {
$result['id'] = trim($matches[1]);
$status = trim($matches[2]);
// Capture the status code as message by default.
$result['statusmessage'] = "CODE: $status";
if($status === '1') {
$result['status'] = self::MSG_STATUS_PROCESSING;
} else if($status === '2') {
$result['status'] = self::MSG_STATUS_DISPATCHED;
$result['needlookup'] = 0;
}
}
return $result;
}
}