From 1ddfbd9bc57375d55025438f9410810b83633eb4 Mon Sep 17 00:00:00 2001 From: Axel Wehner Date: Sun, 7 Jan 2018 20:14:25 +0100 Subject: [PATCH] Add "CM Telecom" Bulk SMS Gateway With support for multipart messages, JSON or XML gateway and debug output. Sends a batch message with one request to multiple recipients. Uses the SMS gateway password field as API-Token. - Add gateway class "CMBulkSMS" for handling SMS notifications - Add required translation strings to the language files - Add "cmbulksms" option to the sms gateway select field - Add "CM Telecom" to list of SMS gateways in README file - Sort the sms gateway select options ascending by title (Usability) --- README.rst | 1 + src/includes/functions.inc.php | 3 + src/lang/bg_BG.lang.php | 1 + src/lang/cs_CZ.lang.php | 1 + src/lang/da_DK.lang.php | 1 + src/lang/de_DE.lang.php | 1 + src/lang/en_US.lang.php | 1 + src/lang/es_ES.lang.php | 1 + src/lang/et_ET.lang.php | 1 + src/lang/fa_IR.lang.php | 1 + src/lang/fi_FI.lang.php | 1 + src/lang/fr_FR.lang.php | 1 + src/lang/it_IT.lang.php | 1 + src/lang/ja_JP.lang.php | 1 + src/lang/ko_KR.lang.php | 1 + src/lang/nl_NL.lang.php | 1 + src/lang/pl_PL.lang.php | 1 + src/lang/pt_BR.lang.php | 1 + src/lang/ru_RU.lang.php | 1 + src/lang/sk_SK.lang.php | 1 + src/lang/sl_SI.lang.php | 1 + src/lang/sv_SE.lang.php | 1 + src/lang/tr_TR.lang.php | 3 +- src/lang/vi_VN.lang.php | 1 + src/lang/zh_CN.lang.php | 1 + .../Config/Controller/ConfigController.php | 1 + src/psm/Txtmsg/CMBulkSMS.php | 234 ++++++++++++++++++ .../default/module/config/config.tpl.html | 27 +- 28 files changed, 277 insertions(+), 14 deletions(-) create mode 100644 src/psm/Txtmsg/CMBulkSMS.php diff --git a/README.rst b/README.rst index e76cdaab..7de8a870 100755 --- a/README.rst +++ b/README.rst @@ -55,6 +55,7 @@ The following SMS gateways are currently available: * Nexmo - * OctoPush - * FreeMobile (FR) - +* CM Telecom - diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index b509929d..cd0455c7 100644 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -545,6 +545,9 @@ function psm_build_sms() { case 'smsgw': $sms = new \psm\Txtmsg\Smsgw(); break; + case 'cmbulksms': + $sms = new \psm\Txtmsg\CMBulkSMS(); + break; } // copy login information from the config file diff --git a/src/lang/bg_BG.lang.php b/src/lang/bg_BG.lang.php index 89afc4c5..3fa3b8a9 100644 --- a/src/lang/bg_BG.lang.php +++ b/src/lang/bg_BG.lang.php @@ -200,6 +200,7 @@ $sm_lang = array( 'sms_gateway_smsglobal' => 'SMSGlobal', 'sms_gateway_octopush' => 'Octopush', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Потребител', 'sms_gateway_password' => 'Парола', 'sms_from' => 'Номер на изпращача', diff --git a/src/lang/cs_CZ.lang.php b/src/lang/cs_CZ.lang.php index bb310bbc..03f7afb6 100644 --- a/src/lang/cs_CZ.lang.php +++ b/src/lang/cs_CZ.lang.php @@ -215,6 +215,7 @@ $sm_lang = array( 'sms_gateway_freemobilesms' => 'FreeMobileSMS', 'sms_gateway_clicksend' => 'ClickSend', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Uživatelské jméno brány', 'sms_gateway_password' => 'Heslo brány', 'sms_from' => 'Telefonní číslo odesilatele', diff --git a/src/lang/da_DK.lang.php b/src/lang/da_DK.lang.php index fd1059fb..f497989a 100644 --- a/src/lang/da_DK.lang.php +++ b/src/lang/da_DK.lang.php @@ -197,6 +197,7 @@ $sm_lang = array( 'sms_gateway_octopush' => 'Octopush', 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Gateway brugernavn/apikey', 'sms_gateway_password' => 'Gateway adgangskode', 'sms_from' => 'Afsenderens navn.', diff --git a/src/lang/de_DE.lang.php b/src/lang/de_DE.lang.php index 65da7201..174bf853 100644 --- a/src/lang/de_DE.lang.php +++ b/src/lang/de_DE.lang.php @@ -201,6 +201,7 @@ $sm_lang = array( 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Gateway Benutzername', 'sms_gateway_password' => 'Gateway Passwort', 'sms_from' => 'SMS-Sendernummer', diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 99012424..6c64f6b5 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -223,6 +223,7 @@ $sm_lang = array( 'sms_gateway_clicksend' => 'ClickSend', 'sms_gateway_nexmo' => 'Nexmo', 'sms_gateway_smsgw' => 'SMSgw', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Gateway username', 'sms_gateway_password' => 'Gateway password', 'sms_from' => 'Sender\'s phone number', diff --git a/src/lang/es_ES.lang.php b/src/lang/es_ES.lang.php index 049d1f76..10f65bfb 100644 --- a/src/lang/es_ES.lang.php +++ b/src/lang/es_ES.lang.php @@ -204,6 +204,7 @@ $sm_lang = array( 'sms_gateway_username' => 'Usuario', 'sms_gateway_password' => 'Contraseña', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Gateway username', 'sms_gateway_password' => 'Gateway password', 'sms_from' => 'Número origen del SMS', diff --git a/src/lang/et_ET.lang.php b/src/lang/et_ET.lang.php index d8dfac49..cf0e35a2 100644 --- a/src/lang/et_ET.lang.php +++ b/src/lang/et_ET.lang.php @@ -198,6 +198,7 @@ $sm_lang = array( 'sms_gateway_smsglobal' => 'SMSGlobal', 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Värava kasutajanimi', 'sms_gateway_password' => 'Värava parool', 'sms_from' => 'Saatja telefoni number', diff --git a/src/lang/fa_IR.lang.php b/src/lang/fa_IR.lang.php index b69f5ee6..b20f4155 100644 --- a/src/lang/fa_IR.lang.php +++ b/src/lang/fa_IR.lang.php @@ -198,6 +198,7 @@ $sm_lang = array( 'sms_gateway_smsglobal' => 'SMSGlobal', 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'نام کاربری Gateway', 'sms_gateway_password' => 'کلمه عبور Gateway', 'sms_from' => 'شماره تلفن ارسال کننده', diff --git a/src/lang/fi_FI.lang.php b/src/lang/fi_FI.lang.php index 9d037ac8..efba3e8c 100644 --- a/src/lang/fi_FI.lang.php +++ b/src/lang/fi_FI.lang.php @@ -198,6 +198,7 @@ $sm_lang = array( 'sms_gateway_smsglobal' => 'SMSGlobal', 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Palvelun käyttäjänimi', 'sms_gateway_password' => 'Palvelun salasana', 'sms_from' => 'Lähettäjän puhelinnumero', diff --git a/src/lang/fr_FR.lang.php b/src/lang/fr_FR.lang.php index f6bc8220..190b6cc5 100644 --- a/src/lang/fr_FR.lang.php +++ b/src/lang/fr_FR.lang.php @@ -202,6 +202,7 @@ $sm_lang = array( 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_nexmo' => 'Nexmo', 'sms_gateway_freemobilesms' => 'FreeMobileSMS', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Nom utilisateur de la passerelle', 'sms_gateway_password' => 'Mot de passe de la passerelle', 'sms_from' => 'SMS de l\'expéditeur', diff --git a/src/lang/it_IT.lang.php b/src/lang/it_IT.lang.php index 4bb9f766..995790c0 100644 --- a/src/lang/it_IT.lang.php +++ b/src/lang/it_IT.lang.php @@ -200,6 +200,7 @@ $sm_lang = array( 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Nome Utente Gateway', 'sms_gateway_password' => 'Password Gateway', 'sms_from' => 'Numero di telefono del mittente', diff --git a/src/lang/ja_JP.lang.php b/src/lang/ja_JP.lang.php index ad07e962..caa3bb7a 100644 --- a/src/lang/ja_JP.lang.php +++ b/src/lang/ja_JP.lang.php @@ -220,6 +220,7 @@ $sm_lang = array( 'sms_gateway_clicksend' => 'ClickSend', 'sms_gateway_nexmo' => 'Nexmo', 'sms_gateway_smsgw' => 'SMSgw', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'ゲートウェイのユーザー名', 'sms_gateway_password' => 'ゲートウェイのパスワード', 'sms_from' => '送信者の電話番号:', diff --git a/src/lang/ko_KR.lang.php b/src/lang/ko_KR.lang.php index 99cfd94f..d74ff69a 100644 --- a/src/lang/ko_KR.lang.php +++ b/src/lang/ko_KR.lang.php @@ -200,6 +200,7 @@ $sm_lang = array( 'sms_gateway_smsglobal' => 'SMSGlobal', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_octopush' => 'Octopush', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Gateway username', 'sms_gateway_password' => 'Gateway password', 'sms_from' => 'Sender\'s phone number', diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php index 4c87982e..9a185987 100644 --- a/src/lang/nl_NL.lang.php +++ b/src/lang/nl_NL.lang.php @@ -200,6 +200,7 @@ $sm_lang = array( 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Gateway gebruikersnaam', 'sms_gateway_password' => 'Gateway wachtwoord', 'sms_from' => 'Telefoonnummer afzender', diff --git a/src/lang/pl_PL.lang.php b/src/lang/pl_PL.lang.php index c77cb7a5..998e4996 100644 --- a/src/lang/pl_PL.lang.php +++ b/src/lang/pl_PL.lang.php @@ -200,6 +200,7 @@ $sm_lang = array( 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Login do bramki', 'sms_gateway_password' => 'Hasło do bramki', 'sms_from' => 'Numer nadawcy', diff --git a/src/lang/pt_BR.lang.php b/src/lang/pt_BR.lang.php index 1f2b325a..be788219 100644 --- a/src/lang/pt_BR.lang.php +++ b/src/lang/pt_BR.lang.php @@ -203,6 +203,7 @@ $sm_lang = array( 'sms_gateway_password' => 'Senha do Gateway', 'sms_from' => 'Número de telefone de envio', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Usuário do Gateway', 'sms_gateway_password' => 'Senha do Gateway', 'sms_from' => 'Número de telefone de envio', diff --git a/src/lang/ru_RU.lang.php b/src/lang/ru_RU.lang.php index b3347012..48c49917 100644 --- a/src/lang/ru_RU.lang.php +++ b/src/lang/ru_RU.lang.php @@ -200,6 +200,7 @@ $sm_lang = array( 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Пользователь', 'sms_gateway_password' => 'Пароль', 'sms_from' => 'Номер отправителя', diff --git a/src/lang/sk_SK.lang.php b/src/lang/sk_SK.lang.php index a5a0389d..66378336 100644 --- a/src/lang/sk_SK.lang.php +++ b/src/lang/sk_SK.lang.php @@ -214,6 +214,7 @@ $sm_lang = array( 'sms_gateway_freemobilesms' => 'FreeMobileSMS', 'sms_gateway_clicksend' => 'ClickSend', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Užívateľské meno brány', 'sms_gateway_password' => 'Heslo brány', 'sms_from' => 'Telefónne číslo odosielateľa', diff --git a/src/lang/sl_SI.lang.php b/src/lang/sl_SI.lang.php index a917be97..a17cacd0 100644 --- a/src/lang/sl_SI.lang.php +++ b/src/lang/sl_SI.lang.php @@ -195,6 +195,7 @@ $sm_lang = array( 'sms_gateway_textmarketer' => 'Textmarketer', 'sms_gateway_smsglobal' => 'SMSGlobal', 'sms_gateway_smsit' => 'Smsit', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Uporabniško ime SMS prehoda', 'sms_gateway_password' => 'Geslo SMS prehoda', 'sms_from' => 'Telefonska številka pošiljatelja', diff --git a/src/lang/sv_SE.lang.php b/src/lang/sv_SE.lang.php index 0f0aa603..69639219 100644 --- a/src/lang/sv_SE.lang.php +++ b/src/lang/sv_SE.lang.php @@ -199,6 +199,7 @@ $sm_lang = array( 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Gateway användarnamn', 'sms_gateway_password' => 'Gateway lösenord', 'sms_from' => 'Avsändarens telefonnummer', diff --git a/src/lang/tr_TR.lang.php b/src/lang/tr_TR.lang.php index f3f621a8..87ea0e03 100644 --- a/src/lang/tr_TR.lang.php +++ b/src/lang/tr_TR.lang.php @@ -199,7 +199,8 @@ $sm_lang = array( 'sms_gateway_octopush' => 'Octopush', 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', - 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Servis kullanıcı adı', 'sms_gateway_password' => 'Servis şifresi', 'sms_from' => 'Gönderen numarası', diff --git a/src/lang/vi_VN.lang.php b/src/lang/vi_VN.lang.php index f051de7e..2d67478a 100644 --- a/src/lang/vi_VN.lang.php +++ b/src/lang/vi_VN.lang.php @@ -195,6 +195,7 @@ $sm_lang = array( 'sms_gateway_textmarketer' => 'Textmarketer', 'sms_gateway_smsglobal' => 'SMSGlobal', 'sms_gateway_smsit' => 'Smsit', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'Gateway username', 'sms_gateway_password' => 'Gateway password', 'sms_from' => 'Số điện thoại của người gửi', diff --git a/src/lang/zh_CN.lang.php b/src/lang/zh_CN.lang.php index 17f73ec4..01c3e617 100644 --- a/src/lang/zh_CN.lang.php +++ b/src/lang/zh_CN.lang.php @@ -216,6 +216,7 @@ $sm_lang = array( 'sms_gateway_smsit' => 'Smsit', 'sms_gateway_freevoipdeal' => 'FreeVoipDeal', 'sms_gateway_nexmo' => 'Nexmo', + 'sms_gateway_cmbulksms' => 'CM Telecom', 'sms_gateway_username' => 'SMS网关用户名', 'sms_gateway_password' => 'SMS网关密码', 'sms_from' => '发信人电话号', diff --git a/src/psm/Module/Config/Controller/ConfigController.php b/src/psm/Module/Config/Controller/ConfigController.php index b030234f..7e03f339 100644 --- a/src/psm/Module/Config/Controller/ConfigController.php +++ b/src/psm/Module/Config/Controller/ConfigController.php @@ -325,6 +325,7 @@ class ConfigController extends AbstractController { 'label_sms_gateway_spryng' => psm_get_lang('config', 'sms_gateway_spryng'), 'label_sms_gateway_inetworx' => psm_get_lang('config', 'sms_gateway_inetworx'), 'label_sms_gateway_clickatell' => psm_get_lang('config', 'sms_gateway_clickatell'), + 'label_sms_gateway_cmbulksms' => psm_get_lang('config', 'sms_gateway_cmbulksms'), 'label_sms_gateway_textmarketer' => psm_get_lang('config', 'sms_gateway_textmarketer'), 'label_sms_gateway_smsit' => psm_get_lang('config', 'sms_gateway_smsit'), 'label_sms_gateway_freevoipdeal' => psm_get_lang('config', 'sms_gateway_freevoipdeal'), diff --git a/src/psm/Txtmsg/CMBulkSMS.php b/src/psm/Txtmsg/CMBulkSMS.php new file mode 100644 index 00000000..07d06631 --- /dev/null +++ b/src/psm/Txtmsg/CMBulkSMS.php @@ -0,0 +1,234 @@ +. + * + * @package phpservermon + * @author Axel Wehner + * @copyright Copyright (c) 2008-2017 Pepijn Over + * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 + * @version Release: @package_version@ + * @link http://www.phpservermonitor.org/ + * @since phpservermon 3.2.1 + **/ + +namespace psm\Txtmsg; + +/** + * CMBulkSMS - Class for CM Telecom's Bulk SMS Gateway API + * + * Sending SMS notifications via the CM Telecom Bulk SMS Gateway + * Please use the gateway password field in your configuration for the CM API-Token + * + * Requirements: cURL v7.18.1+ and OpenSSL 0.9.8j+ + */ +class CMBulkSMS extends Core { + /** @var bool|null True when cURL request succeeded */ + public $result; + + /** @var string|null Contains error message if cURL request failed */ + public $error; + + /** @var bool Set to true for debug output/logging */ + protected $debug = false; + + /** @var bool Set to false if your operator isn't able to handle multipart messages */ + protected $multipartMessage = true; + + /** @var string|null Gateway API URL uses const GATEWAY_URL_XML or GATEWAY_URL_JSON */ + protected $apiUrl; + + /** @var string Gateway API Type: Use 'json' (default) or 'xml' */ + protected $apiType = 'json'; + + /** @var string|null JSON or XML message for cURL request */ + protected $request; + + /** @var string|null HTTP Content-Type for cURL request */ + protected $contentType; + + /** @var string|null Raw sms text message */ + protected $messageBody; + + /** @var string JSON Gateway API URL */ + const GATEWAY_URL_JSON = "https://gw.cmtelecom.com/v1.0/message"; + + /** @var string XML Gateway API URL */ + const GATEWAY_URL_XML = "https://sgw01.cm.nl/gateway.ashx"; + + /** + * Build the message and send cURL request to the sms gateway + * + * @see https://docs.cmtelecom.com/bulk-sms/v1.0#/send_a_message%7Csample_requests + * @param string $message Your text message + * @return boolean True when cURL request was successful + */ + public function sendSMS($message) { + // Check if recipient and text message are available + if(count($this->recipients) < 1 || empty($message)) { + return false; + } + + // Set message text + $this->messageBody = $message; + + // Prepare the message in CM's XML or JSON format + switch($this->apiType) { + case 'xml': + $this->request = $this->buildMessageXml(); + $this->contentType = 'Content-Type: application/xml'; + $this->apiUrl = self::GATEWAY_URL_XML; + break; + + case 'json': + default: + $this->request = $this->buildMessageJson(); + $this->contentType = 'Content-Type: application/json'; + $this->apiUrl = self::GATEWAY_URL_JSON; + break; + } + + $request = $this->executeCurlRequest(); + + return $request; + } + + /** + * Create a JSON batch sms message using CM's format + * + * @see https://docs.cmtelecom.com/bulk-sms/v1.0#/send_a_message%7Cbatch_messages + * @see https://docs.cmtelecom.com/bulk-sms/v1.0#/send_a_message%7Csample_requests + * @see https://docs.cmtelecom.com/bulk-sms/v1.0#/send_a_message%7Cmultipart + * @return string JSON message object + */ + protected function buildMessageJson() { + // Prepare recipient array for batch message + $recipients = array(); + foreach($this->recipients as $recipient) { + $recipients[] = array('number' => $recipient); + } + + // Build message array in CM's Bulk SMS format + $msgArray = array( + 'messages' => array( + 'authentication' => array( + 'producttoken' => $this->password + ), + 'msg' => array( + array( + 'from' => substr($this->originator, 0, 11), + 'to' => $recipients, + 'body' => array( + 'content' => $this->messageBody + ) + ) + ) + ) + ); + + // Multipart message + if($this->multipartMessage) { + $msgArray['messages']['msg'][0]['minimumNumberOfMessageParts'] = 1; + $msgArray['messages']['msg'][0]['maximumNumberOfMessageParts'] = 8; + } + + // Convert array in JSON object + return json_encode($msgArray); + } + + /** + * Create a XML batch sms message in CM's format + * + * @see https://docs.cmtelecom.com/bulk-sms/v1.0#/send_a_message%7Cbatch_messages + * @see https://docs.cmtelecom.com/bulk-sms/v1.0#/send_a_message%7Csample_requests + * @see https://docs.cmtelecom.com/bulk-sms/v1.0#/send_a_message%7Cmultipart + * @return string XML message + */ + protected function buildMessageXml() { + // Create XML string + $xml = new \SimpleXMLElement(''); + + // API-Token + $auth = $xml->addChild('AUTHENTICATION'); + $auth->addChild('PRODUCTTOKEN', $this->password); + + // Message + $msg = $xml->addChild('MSG'); + + // From + $msg->addChild('FROM', substr($this->originator, 0, 11)); + + // Recipients + foreach($this->recipients as $recipient) { + $msg->addChild('TO', $recipient); + } + + // Multipart message + if($this->multipartMessage) { + $msg->addChild('MINIMUMNUMBEROFMESSAGEPARTS', 1); + $msg->addChild('MAXIMUMNUMBEROFMESSAGEPARTS', 8); + } + + // Add body text + $msg->addChild('BODY', $this->messageBody); + + return $xml->asXML(); + } + + /** + * Create and execute the curl request + * + * @return boolean True if message is sent + */ + protected function executeCurlRequest() { + $cr = curl_init(); + curl_setopt_array($cr, array( + CURLOPT_URL => $this->apiUrl, + CURLOPT_HTTPHEADER => array($this->contentType), + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $this->request, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_FAILONERROR => true + ) + ); + + // execute curl request and fetch the response/error + $cResponse = curl_exec($cr); + $cError = curl_error($cr); + $cErrorCode = curl_errno($cr); + curl_close($cr); + + // set result and log error if needed + if($cError) { + $this->error = 'Response: CM SMS API:' . $cResponse . ' cURL Error Code: ' . $cErrorCode . '"' . $cError . '"'; + error_log($this->error, E_USER_ERROR); + $this->result = false; + } else { + $this->result = true; + } + + // Debug output + // Note: CM's XML gateway gives no response when message is sent successfully :/ + if($this->debug || PSM_DEBUG) { + $debug = '
Request: '. $this->request . '
Response: ' . $cResponse.'
'; + error_log("Request: $this->request\r\nResponse: $cResponse", E_USER_NOTICE); + echo $debug; + } + + return $this->result; + } +} diff --git a/src/templates/default/module/config/config.tpl.html b/src/templates/default/module/config/config.tpl.html index ff994718..0d4cb0b4 100644 --- a/src/templates/default/module/config/config.tpl.html +++ b/src/templates/default/module/config/config.tpl.html @@ -187,21 +187,22 @@
+