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 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 ] /**
// ========================================================================= * Send sms using the SMSgw.NET API
public $gateway = 1; *
public $resultcode = null; * @var string $message
public $resultmessage = null; * @var string $this->password
public $success = false; * @var array $this->recipients
public $successcount = 0; * @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) { public function sendSMS($message) {
// Documentation: http://docs.clicksend.apiary.io/#reference/sms/send-an-sms/send-an-sms $error = "";
// https://rest.clicksend.com/v3/sms/send $success = 1;
// 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()); if(empty($this->recipients)) return false;
foreach($this->recipients as $phone) {
$request['messages'][] = array( $data = array('messages' => array());
foreach($this->recipients as $recipient) {
$data['messages'][] = array(
'source' => 'phpservermon', 'source' => 'phpservermon',
'from' => $from, 'from' => substr($this->originator,0,11),
'to' => $phone, 'to' => $recipient,
'body' => $message 'body' => $message,
); );
} }
$data_string = json_encode($request); $curl = curl_init();
$ch = curl_init($apiurl); curl_setopt_array($curl, array(
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); CURLOPT_URL => "https://rest.clicksend.com/v3/sms/send",
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); CURLOPT_RETURNTRANSFER => true,
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); CURLOPT_ENCODING => "",
curl_setopt($ch, CURLOPT_HTTPHEADER, array( CURLOPT_MAXREDIRS => 10,
'Content-Type: application/json', CURLOPT_TIMEOUT => 30,
'Content-Length: ' . strlen($data_string)) CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
); CURLOPT_CUSTOMREQUEST => "POST",
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); CURLOPT_POSTFIELDS => json_encode($data),
curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password); CURLOPT_HTTPHEADER => array(
$result = curl_exec($ch); "authorization: Basic " . base64_encode($this->username . ":" . $this->password),
"content-type: application/json"
),
));
$response = json_decode($result); $result = json_decode(curl_exec($curl),true);
$this->success = $response->data->response_code == 'SUCCESS'; $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$this->successcount = $response->data->total_count;
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 $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

@ -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@
@ -30,32 +32,55 @@ 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;
$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, 'strUserName' => $this->username,
'strPassword' => $this->password, 'strPassword' => $this->password,
'strTagName' => $this->originator, "strTagName" => $this->originator,
'strRecepientNumbers' => implode(';', $this->recipients), "strRecepientNumbers" => $recipients,
'strMessage' => $message, "strMessage" => urlencode($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;
}
$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

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

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