SMS: ClickSend and SMSgw updated, fixed small things in the others

Update to #593

Co-Authored-By: Ward Pieters <wardpieters@users.noreply.github.com>
This commit is contained in:
TimZ99 2018-05-30 23:01:13 +02:00
parent 57f4c369e9
commit 62254a534b
No known key found for this signature in database
GPG Key ID: 4D8268DC68E8339D
18 changed files with 213 additions and 129 deletions

View File

@ -17,13 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Axel Wehner <mail@axelwehner.de>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @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 <mail@axelwehner.de>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @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;

View File

@ -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
*

View File

@ -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;
}
}

View File

@ -17,13 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Pepijn Over <pep@mailbox.org>
* @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2018 Pepijn Over <pep@mailbox.org>
* @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 <pep@mailbox.org>
* @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2018 Pepijn Over <pep@mailbox.org>
* @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 = '';

View File

@ -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
*

View File

@ -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;
}

View File

@ -19,6 +19,7 @@
*
* @package phpservermon
* @author Ward Pieters <ward@wardpieters.nl>
* @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @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;
}

View File

@ -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) {

View File

@ -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
*

View File

@ -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
*

View File

@ -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);

View File

@ -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
*

View File

@ -19,6 +19,8 @@
*
* @package phpservermon
* @author Daif Alotaibi <daif@daif.net>
* @author Ward Pieters <ward@wardpieters.nl>
* @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @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;
}
}

View File

@ -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
*

View File

@ -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);

View File

@ -17,12 +17,12 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Pepijn Over <pep@mailbox.org>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @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 <pep@mailbox.org>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @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);

View File

@ -17,14 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Perri Vardy-Mason
* @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @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 <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @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 = '';

View File

@ -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 = '';