'config_file', 'title' => 'Fichier de configuration', 'description' => 'Chemin vers le fichier de configuration que Gammu devra utilisé pour se connecter au téléphone.', 'required' => true, ], ]; } /** * Does the implemented service support flash smss */ public static function meta_support_flash() : bool { return false ; } /** * Does the implemented service support status change */ public static function meta_support_status_change() : bool { return true; } /** * Phone number using the adapter */ private $number; /** * Datas used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.). */ private $datas; /** * Adapter constructor, called when instanciated by RaspiSMS * @param string $number : Phone number the adapter is used for * @param json string $datas : JSON string of the datas to configure interaction with the implemented service */ public function __construct (string $number, string $datas) { $this->number = $number; $this->formatted_number = str_replace('+', '00', $number); $this->datas = json_decode($datas, true); $this->api = new Api( $this->datas['app_key'], $this->datas['app_secret'], $this->datas['endpoint'], $this->datas['consumer_key'] ); } /** * Method called to send a SMS to a number * @param string $destination : Phone number to send the sms to * @param string $text : Text of the SMS to send * @param bool $flash : Is the SMS a Flash SMS * @return mixed : Uid of the sended message if send, False else */ public function send (string $destination, string $text, bool $flash = false) { $command_parts = [ 'gammu', '--config', escapeshellarg($this->datas['config_file']), 'sendsms', 'TEXT', escapeshellarg($destination), '-text', escapeshellarg($text), '-validity', 'MAX', '-autolen', mb_strlen($text), ]; if ($flash) { $command_parts[] = '-flash'; } $result = $this->exec_command($command_parts); if ($result['return'] != 0) { return false; } $find_ok = $this->search_for_string('ok', $command_parts['output']); if (!$find_ok) { return false; } $uid = false; foreach ($output as $line) { $matches = []; preg_match('#reference=([0-9]+)#u', $line, $matches); if ($matches[1] ?? false) { $uid = $matches[1]; break; } } if ($uid === false) { return false; } return $uid; } /** * Method called to read SMSs of the number * @return array : Array of the sms reads */ public function read () : array { } /** * Method called to verify if the adapter is working correctly * should be use for exemple to verify that credentials and number are both valid * @return boolean : False on error, true else */ public function test () : bool { if (!file_exists($this->datas['config_file'])) { return false; } return true; } /** * Method called on reception of a status update notification for a SMS * @return mixed : False on error, else array ['uid' => uid of the sms, 'status' => New status of the sms ('unknown', 'delivered', 'failed')] */ public static function status_change_callback () { return false; } /** * Function to execute a command and transmit it to Gammu * @param array $command_parts : Commands parts to be join with a space * @return array : ['return' => int:return code of command, 'output' => array:each raw is a line of the output] */ private function exec_command (array $command_parts) : array { $command = implode(' ', $command_parts); $output = []; $return_var = null; exec($command, $output, $return_var); return ['return' => (int) $return_var, 'output' => $output]; } /** * Function to search a string in the output of an executer command * @param array $output : Text to search in where each raw is a line * @param string $search : Text to search for * @return bool : True if found, false else */ private function search_for_string (array $output, string $search) : bool { $find = false; foreach ($output as $line) { $find = mb_stristr($line, $search); if ($find !== false) { break; } } return (bool) $find; } }