diff --git a/src/psm/Txtmsg/CMBulkSMS.php b/src/psm/Txtmsg/CMBulkSMS.php index 1851af23..977d94ad 100644 --- a/src/psm/Txtmsg/CMBulkSMS.php +++ b/src/psm/Txtmsg/CMBulkSMS.php @@ -17,13 +17,13 @@ * You should have received a copy of the GNU General Public License * along with PHP Server Monitor. If not, see . * - * @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 + * @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; diff --git a/src/psm/Txtmsg/Callr.php b/src/psm/Txtmsg/Callr.php index d69da71b..927ef4bd 100644 --- a/src/psm/Txtmsg/Callr.php +++ b/src/psm/Txtmsg/Callr.php @@ -40,8 +40,12 @@ class Callr extends Core { * @var array $this->originator * @var string $recipient * + * @var mixed $result + * @var array $headers + * * @var resource $curl * @var string $err + * * @var int $success * @var string $error * diff --git a/src/psm/Txtmsg/ClickSend.php b/src/psm/Txtmsg/ClickSend.php index 59415c1d..869fea43 100644 --- a/src/psm/Txtmsg/ClickSend.php +++ b/src/psm/Txtmsg/ClickSend.php @@ -29,50 +29,68 @@ namespace psm\Txtmsg; class ClickSend extends Core { - // ========================================================================= - // [ Fields ] - // ========================================================================= - public $gateway = 1; - public $resultcode = null; - public $resultmessage = null; - public $success = false; - public $successcount = 0; - - public function sendSMS($message) { - // Documentation: http://docs.clicksend.apiary.io/#reference/sms/send-an-sms/send-an-sms - // https://rest.clicksend.com/v3/sms/send - // Use your API KEY as the password ($this->password) - $apiurl = "https://rest.clicksend.com/v3/sms/send"; - $from = substr($this->originator,0,11); // Max 11 Char. - - $request = array('messages' => array()); - foreach($this->recipients as $phone) { - $request['messages'][] = array( - 'source' => 'phpservermon', - 'from' => $from, - 'to' => $phone, - 'body' => $message - ); - } - - $data_string = json_encode($request); - $ch = curl_init($apiurl); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); - curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Content-Length: ' . strlen($data_string)) - ); - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password); - $result = curl_exec($ch); - - $response = json_decode($result); - $this->success = $response->data->response_code == 'SUCCESS'; - $this->successcount = $response->data->total_count; - - return $response; - } - -} + + /** + * Send sms using the SMSgw.NET API + * + * @var string $message + * @var string $this->password + * @var array $this->recipients + * @var array $this->originator + * @var string $recipients + * + * @var resource $curl + * @var string $err + * @var mixed $result + * + * @var int $success + * @var string $error + * + * @return int or string + */ + + public function sendSMS($message) { + $error = ""; + $success = 1; + + if(empty($this->recipients)) return false; + + $data = array('messages' => array()); + foreach($this->recipients as $recipient) { + $data['messages'][] = array( + 'source' => 'phpservermon', + 'from' => substr($this->originator,0,11), + 'to' => $recipient, + 'body' => $message, + ); + } + + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => "https://rest.clicksend.com/v3/sms/send", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => json_encode($data), + CURLOPT_HTTPHEADER => array( + "authorization: Basic " . base64_encode($this->username . ":" . $this->password), + "content-type: application/json" + ), + )); + + $result = json_decode(curl_exec($curl),true); + $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + + if($err = curl_errno($curl) || ($httpcode != '200' && $httpcode != '201' && $httpcode != '202' && $result['response_code'] != "SUCCESS")) { + $success = 0; + $error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". Result: ".$result.""; + } + curl_close($curl); + + if($success) return 1; + return $error; + } +} \ No newline at end of file diff --git a/src/psm/Txtmsg/Clickatell.php b/src/psm/Txtmsg/Clickatell.php index 1b66a99b..a4a3487c 100644 --- a/src/psm/Txtmsg/Clickatell.php +++ b/src/psm/Txtmsg/Clickatell.php @@ -17,13 +17,13 @@ * You should have received a copy of the GNU General Public License * along with PHP Server Monitor. If not, see . * - * @package phpservermon - * @author Pepijn Over - * @author Tim Zandbergen - * @copyright Copyright (c) 2008-2018 Pepijn Over - * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 - * @version Release: @package_version@ - * @link https://www.phpservermonitor.org/ + * @package phpservermon + * @author Pepijn Over + * @author Tim Zandbergen + * @copyright Copyright (c) 2008-2018 Pepijn Over + * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 + * @version Release: @package_version@ + * @link https://www.phpservermonitor.org/ **/ namespace psm\Txtmsg; @@ -37,10 +37,13 @@ class Clickatell extends Core { * @var string $recipient * @var string $this->password * @var string $this->originator + * * @var int $success * @var string $error + * * @return int or string */ + public function sendSMS($message) { $success = 1; $error = ''; diff --git a/src/psm/Txtmsg/FreeVoipDeal.php b/src/psm/Txtmsg/FreeVoipDeal.php index c1b2d80d..76d02fb4 100755 --- a/src/psm/Txtmsg/FreeVoipDeal.php +++ b/src/psm/Txtmsg/FreeVoipDeal.php @@ -41,7 +41,7 @@ class FreeVoipDeal extends Core { * @var string $err * @var string $recipient * @var string $from - * @var string $result + * @var mixed $result * @var int $success * @var string $error * diff --git a/src/psm/Txtmsg/GatewayAPI.php b/src/psm/Txtmsg/GatewayAPI.php index 86a867c6..6fc80e01 100644 --- a/src/psm/Txtmsg/GatewayAPI.php +++ b/src/psm/Txtmsg/GatewayAPI.php @@ -24,7 +24,7 @@ * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 * @version Release: @package_version@ * @link http://www.phpservermonitor.org/ - * @since phpservermon 3.2 + * @since phpservermon 3.3.0 **/ namespace psm\Txtmsg; @@ -38,7 +38,8 @@ class GatewayAPI extends Core { * @var string $this->password * @var array $this->recipients * @var array $this->originator - * @Var string $recipient + * @var string $recipient + * @var mixed $result * * @var resource $curl * @var string $err @@ -47,40 +48,40 @@ class GatewayAPI extends Core { * * @return int or string */ - + public function sendSMS($message) { $error = ""; $success = 1; - + if(empty($this->recipients)) return false; - + $json = [ 'sender' => isset($this->originator) ? $this->originator : "PHPServerMon", 'message' => $message, 'recipients' => [], ]; - + foreach($this->recipients as $recipient) { $json['recipients'][] = ['msisdn' => $recipient]; } - + $curl = curl_init(); curl_setopt($curl,CURLOPT_URL, "https://gatewayapi.com/rest/mtsms"); curl_setopt($curl,CURLOPT_HTTPHEADER, array("Content-Type: application/json")); curl_setopt($curl,CURLOPT_USERPWD, $this->password . ":"); curl_setopt($curl,CURLOPT_POSTFIELDS, json_encode($json)); curl_setopt($curl,CURLOPT_RETURNTRANSFER, true); - + $result = json_decode(curl_exec($curl),true); $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); $err = curl_error($curl); curl_close($curl); - + if($err || $httpcode != 200) { $success = 0; $error = $result['code']." - ".$result['message']; } - + if($success) return 1; return $error; } diff --git a/src/psm/Txtmsg/Inetworx.php b/src/psm/Txtmsg/Inetworx.php index 18ee538f..1710cd0e 100644 --- a/src/psm/Txtmsg/Inetworx.php +++ b/src/psm/Txtmsg/Inetworx.php @@ -19,6 +19,7 @@ * * @package phpservermon * @author Ward Pieters + * @author Tim Zandbergen * @copyright Copyright (c) 2008-2017 Pepijn Over * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 * @version Release: @package_version@ @@ -28,7 +29,7 @@ namespace psm\Txtmsg; class Inetworx extends Core { - + /** * Send sms using the Inetworx API * @@ -39,20 +40,22 @@ class Inetworx extends Core { * * @var resource $curl * @var string $err - * @Var string $recipient + * @var string $recipient + * @var mixed $result + * * @var int $success * @var string $error * * @return int or string */ - + public function sendSMS($message) { $error = ""; $success = 1; - + foreach($this->recipients as $recipient) { $curl = curl_init(); - + curl_setopt_array($curl, array( CURLOPT_URL => "https://sms.inetworx.ch/smsapp/sendsms.php", CURLOPT_RETURNTRANSFER => true, @@ -85,7 +88,7 @@ class Inetworx extends Core { } curl_close($curl); } - + if($success) return 1; return $error; } diff --git a/src/psm/Txtmsg/Messagebird.php b/src/psm/Txtmsg/Messagebird.php index 5445d5f9..8e93c921 100644 --- a/src/psm/Txtmsg/Messagebird.php +++ b/src/psm/Txtmsg/Messagebird.php @@ -38,8 +38,13 @@ class Messagebird extends Core { * @var array $this->originator (Max 11 characters) * @var array $recipients_chunk * @var string $this->password + * + * @var mixed $result + * @var array $headers + * * @var int $success * @var string $error + * * @return int or string */ public function sendSMS($message) { diff --git a/src/psm/Txtmsg/Nexmo.php b/src/psm/Txtmsg/Nexmo.php index b5f9eba2..a10c0e69 100644 --- a/src/psm/Txtmsg/Nexmo.php +++ b/src/psm/Txtmsg/Nexmo.php @@ -38,10 +38,12 @@ class Nexmo extends Core { * @var string $this->password * @var array $this->recipients * @var array $this->originator - * @Var string $recipient + * @var string $recipient * * @var resource $curl * @var string $err + * @var mixed $result + * * @var int $success * @var string $error * diff --git a/src/psm/Txtmsg/Octopush.php b/src/psm/Txtmsg/Octopush.php index cdb5725e..099b7287 100644 --- a/src/psm/Txtmsg/Octopush.php +++ b/src/psm/Txtmsg/Octopush.php @@ -45,7 +45,8 @@ class Octopush extends Core { * @var string $err * @var string $recipient * @var string $smsType - * @var string $result + * @var mixed $result + * * @var int $success * @var string $error * diff --git a/src/psm/Txtmsg/Plivo.php b/src/psm/Txtmsg/Plivo.php index 5441ed8d..9591e167 100644 --- a/src/psm/Txtmsg/Plivo.php +++ b/src/psm/Txtmsg/Plivo.php @@ -30,7 +30,7 @@ namespace psm\Txtmsg; class Plivo extends Core { - + /** * Send sms using the Plivo API * @@ -82,7 +82,7 @@ class Plivo extends Core { $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if($err = curl_errno($curl) || ($httpcode != '200' && $httpcode != '201' && $httpcode != '202')) { $success = 0; - $error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". Result: ".$result.""; + $error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". Result: ".$result.""; } curl_close($curl); diff --git a/src/psm/Txtmsg/Smsglobal.php b/src/psm/Txtmsg/Smsglobal.php index 906950da..fcfa7fc6 100644 --- a/src/psm/Txtmsg/Smsglobal.php +++ b/src/psm/Txtmsg/Smsglobal.php @@ -41,7 +41,8 @@ class Smsglobal extends Core { * @var string $err * @var string $recipient * @var string $from - * @var string $result + * @var mixed $result + * * @var int $success * @var string $error * diff --git a/src/psm/Txtmsg/Smsgw.php b/src/psm/Txtmsg/Smsgw.php index 3eaa8f80..8c7b145d 100644 --- a/src/psm/Txtmsg/Smsgw.php +++ b/src/psm/Txtmsg/Smsgw.php @@ -19,6 +19,8 @@ * * @package phpservermon * @author Daif Alotaibi + * @author Ward Pieters + * @author Tim Zandbergen * @copyright Copyright (c) 2008-2017 Pepijn Over * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 * @version Release: @package_version@ @@ -29,33 +31,56 @@ namespace psm\Txtmsg; class Smsgw extends Core { - /** - * Send a text message to one or more recipients - * - * @param string $message - * @return boolean - */ + /** + * Send sms using the SMSgw.NET API + * + * @var string $message + * @var string $this->password + * @var array $this->recipients + * @var array $this->originator + * @var string $recipients + * + * @var resource $curl + * @var string $err + * @var int $success + * @var string $error + * + * @return int or string + */ - public function sendSMS($message) { - $url = 'http://api.smsgw.net/SendBulkSMS'; - $post = array( - 'strUserName' => $this->username, - 'strPassword' => $this->password, - 'strTagName' => $this->originator, - 'strRecepientNumbers' => implode(';', $this->recipients), - 'strMessage' => $message, - ); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($ch, CURLOPT_HEADER, FALSE); - curl_setopt($ch, CURLOPT_POST, TRUE); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post); - $data = curl_exec($ch); - if($data == '1') { - $this->success = true; - } - return $this->success; - } + public function sendSMS($message) { + $error = ""; + $success = 1; + $recipients = join(';', $this->recipients); + + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => "https://api.smsgw.net/SendBulkSMS", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => array( + 'strUserName' => $this->username, + 'strPassword' => $this->password, + "strTagName" => $this->originator, + "strRecepientNumbers" => $recipients, + "strMessage" => urlencode($message), + ), + )); + + $result = curl_exec($curl); + $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + if($err = curl_errno($curl) || ($httpcode != '200' && $httpcode != '201' && $httpcode != '202' && $result != "1")) { + $success = 0; + $error = "HTTP_code: ".$httpcode.".\ncURL error (".$err."): ".curl_strerror($err).". Result: ".$result.""; + } + curl_close($curl); + + if($success) return 1; + return $error; + } } diff --git a/src/psm/Txtmsg/Smsit.php b/src/psm/Txtmsg/Smsit.php index 58b626c8..feef8feb 100644 --- a/src/psm/Txtmsg/Smsit.php +++ b/src/psm/Txtmsg/Smsit.php @@ -41,7 +41,8 @@ class Smsit extends Core { * @var resource $curl * @var string $err * @var String $recipient - * @var string $result + * @var mixed $result + * * @var int $success * @var string $error * diff --git a/src/psm/Txtmsg/SolutionsInfini.php b/src/psm/Txtmsg/SolutionsInfini.php index b4cb09a5..10a5fb2a 100644 --- a/src/psm/Txtmsg/SolutionsInfini.php +++ b/src/psm/Txtmsg/SolutionsInfini.php @@ -42,19 +42,21 @@ class SolutionsInfini extends Core { * * @var resource $curl * @var string $err + * * @var int $success * @var string $error * * @return int or string */ + public function sendSMS($message) { $error = ""; $success = 1; - + $message = urlencode($message); - + $recipients = join(',', $this->recipients); - + $curl = curl_init(); curl_setopt($curl,CURLOPT_URL, "https://api-alerts.solutionsinfini.com/v4/?" . http_build_query( array( @@ -68,7 +70,7 @@ class SolutionsInfini extends Core { ); curl_setopt($curl,CURLOPT_RETURNTRANSFER, true); $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); - + $result = json_decode(curl_exec($curl), true); $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); diff --git a/src/psm/Txtmsg/Spryng.php b/src/psm/Txtmsg/Spryng.php index 6b929f1e..c85abf46 100644 --- a/src/psm/Txtmsg/Spryng.php +++ b/src/psm/Txtmsg/Spryng.php @@ -17,12 +17,12 @@ * You should have received a copy of the GNU General Public License * along with PHP Server Monitor. If not, see . * - * @package phpservermon - * @author Pepijn Over - * @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/ + * @package phpservermon + * @author Pepijn Over + * @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/ **/ namespace psm\Txtmsg; @@ -36,8 +36,16 @@ class Spryng extends Core { * @var string $this->username * @var string $this->password * @var string $this->originator + + * @var mixed $result + * @var array $headers + * + * @var int $success + * @var string $error + * * @return int or string */ + public function sendSMS($message) { $recipients = implode(",", $this->recipients); diff --git a/src/psm/Txtmsg/Textmarketer.php b/src/psm/Txtmsg/Textmarketer.php index d55b17e4..ac8f9cf9 100644 --- a/src/psm/Txtmsg/Textmarketer.php +++ b/src/psm/Txtmsg/Textmarketer.php @@ -17,14 +17,14 @@ * You should have received a copy of the GNU General Public License * along with PHP Server Monitor. If not, see . * - * @package phpservermon - * @author Perri Vardy-Mason - * @author Tim Zandbergen - * @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 2.1 + * @package phpservermon + * @author Perri Vardy-Mason + * @author Tim Zandbergen + * @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 2.1 **/ namespace psm\Txtmsg; @@ -38,10 +38,15 @@ class Textmarketer extends Core { * @var string $recipient * @var string $this->username * @var string $this->password + * @var mixed $result + * @var array $headers + * * @var int $success * @var string $error + * * @return int or string */ + public function sendSMS($message) { $success = 1; $error = ''; diff --git a/src/psm/Txtmsg/Twilio.php b/src/psm/Txtmsg/Twilio.php index 4b73e39a..6133f362 100644 --- a/src/psm/Txtmsg/Twilio.php +++ b/src/psm/Txtmsg/Twilio.php @@ -38,10 +38,15 @@ class Twilio extends Core { * @var string $this->username * @var string $this->password * @var string $this->originator + * @var mixed $result + * @var array $headers + * * @var int $success * @var string $error + * * @return int or string */ + public function sendSMS($message) { $success = 1; $error = '';