|
|
|
@ -5,22 +5,20 @@
|
|
|
|
|
|
|
|
|
|
class SendSMSclass
|
|
|
|
|
{
|
|
|
|
|
//input parameters ---------------------
|
|
|
|
|
var $username; //your username
|
|
|
|
|
var $password; //your password
|
|
|
|
|
var $option = array(); // sender...
|
|
|
|
|
var $message; //message text
|
|
|
|
|
var $inputgsmnumbers = array(); //destination gsm numbers
|
|
|
|
|
//--------------------------------------
|
|
|
|
|
|
|
|
|
|
var $host;
|
|
|
|
|
var $token;
|
|
|
|
|
var $optional_headers;
|
|
|
|
|
var $fomatedGSM = array();
|
|
|
|
|
var $formatedMessage = array();
|
|
|
|
|
var $request_data;
|
|
|
|
|
var $response;
|
|
|
|
|
|
|
|
|
|
//input parameters ----------------
|
|
|
|
|
var $username; //your username
|
|
|
|
|
var $password; //your password
|
|
|
|
|
var $option = []; // sender...
|
|
|
|
|
var $message; //message text
|
|
|
|
|
var $inputgsmnumbers = []; //destination gsm numbers
|
|
|
|
|
// variables ne servant que dans la classe, on met leurs propriétés en privé.
|
|
|
|
|
private string $host;
|
|
|
|
|
private string $token;
|
|
|
|
|
private array $optional_headers;
|
|
|
|
|
private array $fomatedGSM = [];
|
|
|
|
|
private array $formatedMessage = [];
|
|
|
|
|
private string $request_data;
|
|
|
|
|
private string $response;
|
|
|
|
|
|
|
|
|
|
function SendSMS($username, $password, $options, $message, $inputgsmnumbers)
|
|
|
|
|
{
|
|
|
|
@ -29,13 +27,13 @@ class SendSMSclass
|
|
|
|
|
$this->password = $password;
|
|
|
|
|
$this->sender = $options['sender'];
|
|
|
|
|
$this->token = $options['token'] ? TRUE : FALSE;
|
|
|
|
|
if ($options['type_sms'] == 'simulate'){
|
|
|
|
|
if ($options['type_sms'] === 'simulate'){
|
|
|
|
|
$dir = '/send/simulate'; // l'API accueillera la demande mais le SMS ne sera pas envoyé
|
|
|
|
|
} else {
|
|
|
|
|
$dir = '/send';
|
|
|
|
|
}
|
|
|
|
|
// definir un header pour accueillir le json et, si besoin, donner le token
|
|
|
|
|
$headers = array('Content-Type: application/json', 'Accept: application/json');
|
|
|
|
|
$headers = ['Content-Type: application/json', 'Accept: application/json'];
|
|
|
|
|
if ($options['token']){
|
|
|
|
|
$headers = array_merge($headers,["Authorization: Bearer " . $options['token']]);
|
|
|
|
|
}
|
|
|
|
@ -53,15 +51,15 @@ class SendSMSclass
|
|
|
|
|
return $this->response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatGSM()
|
|
|
|
|
private function formatGSM(): void
|
|
|
|
|
{
|
|
|
|
|
foreach ($this->inputgsmnumbers as $cle => $n) {
|
|
|
|
|
$fomatedGSM[] = array('value' => $n);
|
|
|
|
|
$fomatedGSM[] = ['value' => $n];
|
|
|
|
|
}
|
|
|
|
|
$this->fomatedGSM = $fomatedGSM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatMessage()
|
|
|
|
|
private function formatMessage(): void
|
|
|
|
|
{
|
|
|
|
|
$formated = [
|
|
|
|
|
'sms' => [
|
|
|
|
@ -83,7 +81,7 @@ class SendSMSclass
|
|
|
|
|
$this->request_data = json_encode($this->formatedMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function do_post_request($url, $postdata, $optional_headers = null)
|
|
|
|
|
private function do_post_request($url, $postdata, $optional_headers = null)
|
|
|
|
|
{
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
@ -114,9 +112,9 @@ class SendSMSclass
|
|
|
|
|
private function texte_avec_liens_courts() {
|
|
|
|
|
// Masque
|
|
|
|
|
$regex = '@([http|ftp|https]+://[a-z0-9?=:&\./+,%#_-]+)@i';
|
|
|
|
|
$links = array();
|
|
|
|
|
$links = [];
|
|
|
|
|
$text = $this->message;
|
|
|
|
|
preg_match_all($regex,$text,$trouvaille,PREG_SET_ORDER);
|
|
|
|
|
preg_match_all($regex, $text, $trouvaille,PREG_SET_ORDER);
|
|
|
|
|
if ($trouvaille){
|
|
|
|
|
foreach ($trouvaille as $key => $value) {
|
|
|
|
|
$links[] = $value[0];
|
|
|
|
|