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

Update to #593

Co-Authored-By: Ward Pieters <wardpieters@users.noreply.github.com>
pull/612/merge
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 * 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/>. * along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
* *
* @package phpservermon * @package phpservermon
* @author Axel Wehner <mail@axelwehner.de> * @author Axel Wehner <mail@axelwehner.de>
* @copyright Copyright (c) 2008-2017 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 * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://www.phpservermonitor.org/ * @link http://www.phpservermonitor.org/
* @since phpservermon 3.2.1 * @since phpservermon 3.2.1
**/ **/
namespace psm\Txtmsg; namespace psm\Txtmsg;

View File

@ -40,8 +40,12 @@ class Callr extends Core {
* @var array $this->originator * @var array $this->originator
* @var string $recipient * @var string $recipient
* *
* @var mixed $result
* @var array $headers
*
* @var resource $curl * @var resource $curl
* @var string $err * @var string $err
*
* @var int $success * @var int $success
* @var string $error * @var string $error
* *

View File

@ -29,50 +29,68 @@
namespace psm\Txtmsg; namespace psm\Txtmsg;
class ClickSend extends Core { 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 * Send sms using the SMSgw.NET API
// https://rest.clicksend.com/v3/sms/send *
// Use your API KEY as the password ($this->password) * @var string $message
$apiurl = "https://rest.clicksend.com/v3/sms/send"; * @var string $this->password
$from = substr($this->originator,0,11); // Max 11 Char. * @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
*/
$request = array('messages' => array()); public function sendSMS($message) {
foreach($this->recipients as $phone) { $error = "";
$request['messages'][] = array( $success = 1;
'source' => 'phpservermon',
'from' => $from,
'to' => $phone,
'body' => $message
);
}
$data_string = json_encode($request); if(empty($this->recipients)) return false;
$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); $data = array('messages' => array());
$this->success = $response->data->response_code == 'SUCCESS'; foreach($this->recipients as $recipient) {
$this->successcount = $response->data->total_count; $data['messages'][] = array(
'source' => 'phpservermon',
'from' => substr($this->originator,0,11),
'to' => $recipient,
'body' => $message,
);
}
return $response; $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 * 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/>. * along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
* *
* @package phpservermon * @package phpservermon
* @author Pepijn Over <pep@mailbox.org> * @author Pepijn Over <pep@mailbox.org>
* @author Tim Zandbergen <Tim@Xervion.nl> * @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2018 Pepijn Over <pep@mailbox.org> * @copyright Copyright (c) 2008-2018 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@ * @version Release: @package_version@
* @link https://www.phpservermonitor.org/ * @link https://www.phpservermonitor.org/
**/ **/
namespace psm\Txtmsg; namespace psm\Txtmsg;
@ -37,10 +37,13 @@ class Clickatell extends Core {
* @var string $recipient * @var string $recipient
* @var string $this->password * @var string $this->password
* @var string $this->originator * @var string $this->originator
*
* @var int $success * @var int $success
* @var string $error * @var string $error
*
* @return int or string * @return int or string
*/ */
public function sendSMS($message) { public function sendSMS($message) {
$success = 1; $success = 1;
$error = ''; $error = '';

View File

@ -41,7 +41,7 @@ class FreeVoipDeal extends Core {
* @var string $err * @var string $err
* @var string $recipient * @var string $recipient
* @var string $from * @var string $from
* @var string $result * @var mixed $result
* @var int $success * @var int $success
* @var string $error * @var string $error
* *

View File

@ -24,7 +24,7 @@
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://www.phpservermonitor.org/ * @link http://www.phpservermonitor.org/
* @since phpservermon 3.2 * @since phpservermon 3.3.0
**/ **/
namespace psm\Txtmsg; namespace psm\Txtmsg;
@ -38,7 +38,8 @@ class GatewayAPI extends Core {
* @var string $this->password * @var string $this->password
* @var array $this->recipients * @var array $this->recipients
* @var array $this->originator * @var array $this->originator
* @Var string $recipient * @var string $recipient
* @var mixed $result
* *
* @var resource $curl * @var resource $curl
* @var string $err * @var string $err

View File

@ -19,6 +19,7 @@
* *
* @package phpservermon * @package phpservermon
* @author Ward Pieters <ward@wardpieters.nl> * @author Ward Pieters <ward@wardpieters.nl>
* @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2017 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 * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@ * @version Release: @package_version@
@ -39,7 +40,9 @@ class Inetworx extends Core {
* *
* @var resource $curl * @var resource $curl
* @var string $err * @var string $err
* @Var string $recipient * @var string $recipient
* @var mixed $result
*
* @var int $success * @var int $success
* @var string $error * @var string $error
* *

View File

@ -38,8 +38,13 @@ class Messagebird extends Core {
* @var array $this->originator (Max 11 characters) * @var array $this->originator (Max 11 characters)
* @var array $recipients_chunk * @var array $recipients_chunk
* @var string $this->password * @var string $this->password
*
* @var mixed $result
* @var array $headers
*
* @var int $success * @var int $success
* @var string $error * @var string $error
*
* @return int or string * @return int or string
*/ */
public function sendSMS($message) { public function sendSMS($message) {

View File

@ -38,10 +38,12 @@ class Nexmo extends Core {
* @var string $this->password * @var string $this->password
* @var array $this->recipients * @var array $this->recipients
* @var array $this->originator * @var array $this->originator
* @Var string $recipient * @var string $recipient
* *
* @var resource $curl * @var resource $curl
* @var string $err * @var string $err
* @var mixed $result
*
* @var int $success * @var int $success
* @var string $error * @var string $error
* *

View File

@ -45,7 +45,8 @@ class Octopush extends Core {
* @var string $err * @var string $err
* @var string $recipient * @var string $recipient
* @var string $smsType * @var string $smsType
* @var string $result * @var mixed $result
*
* @var int $success * @var int $success
* @var string $error * @var string $error
* *

View File

@ -82,7 +82,7 @@ class Plivo extends Core {
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($err = curl_errno($curl) || ($httpcode != '200' && $httpcode != '201' && $httpcode != '202')) { if($err = curl_errno($curl) || ($httpcode != '200' && $httpcode != '201' && $httpcode != '202')) {
$success = 0; $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); curl_close($curl);

View File

@ -41,7 +41,8 @@ class Smsglobal extends Core {
* @var string $err * @var string $err
* @var string $recipient * @var string $recipient
* @var string $from * @var string $from
* @var string $result * @var mixed $result
*
* @var int $success * @var int $success
* @var string $error * @var string $error
* *

View File

@ -19,6 +19,8 @@
* *
* @package phpservermon * @package phpservermon
* @author Daif Alotaibi <daif@daif.net> * @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> * @copyright Copyright (c) 2008-2017 Pepijn Over <pep@mailbox.org>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@ * @version Release: @package_version@
@ -29,33 +31,56 @@ namespace psm\Txtmsg;
class Smsgw extends Core { class Smsgw extends Core {
/** /**
* Send a text message to one or more recipients * Send sms using the SMSgw.NET API
* *
* @param string $message * @var string $message
* @return boolean * @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) { public function sendSMS($message) {
$url = 'http://api.smsgw.net/SendBulkSMS'; $error = "";
$post = array( $success = 1;
'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;
}
$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 resource $curl
* @var string $err * @var string $err
* @var String $recipient * @var String $recipient
* @var string $result * @var mixed $result
*
* @var int $success * @var int $success
* @var string $error * @var string $error
* *

View File

@ -42,11 +42,13 @@ class SolutionsInfini extends Core {
* *
* @var resource $curl * @var resource $curl
* @var string $err * @var string $err
*
* @var int $success * @var int $success
* @var string $error * @var string $error
* *
* @return int or string * @return int or string
*/ */
public function sendSMS($message) { public function sendSMS($message) {
$error = ""; $error = "";
$success = 1; $success = 1;

View File

@ -17,12 +17,12 @@
* You should have received a copy of the GNU General Public License * 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/>. * along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
* *
* @package phpservermon * @package phpservermon
* @author Pepijn Over <pep@mailbox.org> * @author Pepijn Over <pep@mailbox.org>
* @copyright Copyright (c) 2008-2017 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 * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://www.phpservermonitor.org/ * @link http://www.phpservermonitor.org/
**/ **/
namespace psm\Txtmsg; namespace psm\Txtmsg;
@ -36,8 +36,16 @@ class Spryng extends Core {
* @var string $this->username * @var string $this->username
* @var string $this->password * @var string $this->password
* @var string $this->originator * @var string $this->originator
* @var mixed $result
* @var array $headers
*
* @var int $success
* @var string $error
*
* @return int or string * @return int or string
*/ */
public function sendSMS($message) { public function sendSMS($message) {
$recipients = implode(",", $this->recipients); $recipients = implode(",", $this->recipients);

View File

@ -17,14 +17,14 @@
* You should have received a copy of the GNU General Public License * 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/>. * along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
* *
* @package phpservermon * @package phpservermon
* @author Perri Vardy-Mason * @author Perri Vardy-Mason
* @author Tim Zandbergen <Tim@Xervion.nl> * @author Tim Zandbergen <Tim@Xervion.nl>
* @copyright Copyright (c) 2008-2017 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 * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://www.phpservermonitor.org/ * @link http://www.phpservermonitor.org/
* @since phpservermon 2.1 * @since phpservermon 2.1
**/ **/
namespace psm\Txtmsg; namespace psm\Txtmsg;
@ -38,10 +38,15 @@ class Textmarketer extends Core {
* @var string $recipient * @var string $recipient
* @var string $this->username * @var string $this->username
* @var string $this->password * @var string $this->password
* @var mixed $result
* @var array $headers
*
* @var int $success * @var int $success
* @var string $error * @var string $error
*
* @return int or string * @return int or string
*/ */
public function sendSMS($message) { public function sendSMS($message) {
$success = 1; $success = 1;
$error = ''; $error = '';

View File

@ -38,10 +38,15 @@ class Twilio extends Core {
* @var string $this->username * @var string $this->username
* @var string $this->password * @var string $this->password
* @var string $this->originator * @var string $this->originator
* @var mixed $result
* @var array $headers
*
* @var int $success * @var int $success
* @var string $error * @var string $error
*
* @return int or string * @return int or string
*/ */
public function sendSMS($message) { public function sendSMS($message) {
$success = 1; $success = 1;
$error = ''; $error = '';