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

@ -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;
/**
* 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) {
// 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.
$error = "";
$success = 1;
$request = array('messages' => array());
foreach($this->recipients as $phone) {
$request['messages'][] = array(
if(empty($this->recipients)) return false;
$data = array('messages' => array());
foreach($this->recipients as $recipient) {
$data['messages'][] = array(
'source' => 'phpservermon',
'from' => $from,
'to' => $phone,
'body' => $message
'from' => substr($this->originator,0,11),
'to' => $recipient,
'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);
$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"
),
));
$response = json_decode($result);
$this->success = $response->data->response_code == 'SUCCESS';
$this->successcount = $response->data->total_count;
$result = json_decode(curl_exec($curl),true);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
return $response;
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

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

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@
@ -39,7 +40,9 @@ 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
*

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

@ -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@
@ -30,32 +32,55 @@ namespace psm\Txtmsg;
class Smsgw extends Core {
/**
* Send a text message to one or more recipients
* Send sms using the SMSgw.NET API
*
* @param string $message
* @return boolean
* @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(
$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' => 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;
}
"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,11 +42,13 @@ 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;

View File

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

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