prestation/Cron/Cronenvoisms.php
2025-12-01 18:54:33 +00:00

718 lines
17 KiB
PHP
Executable File

<?php
require_once 'Functions.php';
class Cronenvoisms
{
public function __construct() {
}
public function charger_les_sms($nbSms)
{
require_once 'Envoismscron.php';
$this->smscron = new Envoismscron();
$this->lesSms = $this->smscron->get_les_smsaenvoyer($nbSms);
$this->lesSmswha = $this->smscron->get_les_smsaenvoyerwhatsapp($nbSms);
}
public function chargersociete()
{
require_once 'Societeuser.php';
$this->societe = new Societeuser();
$societe = $this->societe->getparametressociete();
$this->fournisseurSms = $societe['fournisseurSms'];
$this->devise = $societe['devise'];
$this->nbSmsParCron = $societe['nbSmsParCron'];
$this->nomProduitSante = $societe['nomProduitSante'];
$this->titreSms = $societe['titreSms'];
$this->compteSms = $societe['compteSms'];
$this->loginSms = $societe['loginSms'];
$this->motPassSms = $societe['motPassSms'];
// WhatsApp
/*
$this->tokenWhatsapp = $societe['tokenWhatsapp'];
$this->instanceWhatsapp = $societe['instanceWhatsapp'];
*/
$this->tokenWhatsapp = $_SESSION['tokenWhatsapp'];
$this->instanceWhatsapp = $_SESSION['instanceWhatsapp'];
$this->codePays = $societe['codePays'];
}
public function marquersms($idSms, $etat)
{
require_once 'Envoismscron.php';
$this->smscron = new Envoismscron();
$smsaenvoyer = $this->smscron->marquersms($idSms, $etat);
}
public function envoyer_les_sms()
{
$lesSms = $this->lesSms;
foreach ($lesSms as $un_sms)
{
$this->idSms = $un_sms['idSms'];
$this->destinataires = $un_sms['destinataires'];
$this->message = $un_sms['message'];
$this->envoyer_un_des_sms();
// sleep(1);
usleep(2000); // Stoppe pour 2 millisecondes
}
}
public function envoyer_un_des_sms()
{
$destinataires = $this->destinataires;
$message = $this->message;
$fournisseurSms = $this->fournisseurSms;
$nomProduitSante = $this->nomProduitSante;
$titreSms = $this->titreSms;
$fournisseurSms = $this->fournisseurSms;
$dest = explode(',', $destinataires);
foreach ($dest as $tel)
{
if($fournisseurSms=="esicia")
{
$this->envoyersmsesicia($tel, $message, $titreSms);
}
elseif($fournisseurSms=="blive")
{
$this->envoyersmsbliive($tel, $message, $titreSms);
}
elseif($fournisseurSms=="hooza")
{
$this->envoyersmshooza($tel, $message, $titreSms);
}
elseif($fournisseurSms=="skysms")
{
$this->envoyersmsskysms($tel, $message, $titreSms);
}
elseif($fournisseurSms=="satelcom")
{
$this->envoyersmssatelcom($tel, $message, $titreSms);
}
elseif($fournisseurSms=="noah")
{
$this->envoyersmsnoah($tel, $message, $titreSms);
}
elseif($fournisseurSms=="nerhysms")
{
$this->envoyersmsnerhysms($tel, $message, $titreSms);
}
elseif($fournisseurSms=="emisms")
{
$this->envoyersmsemisms($tel, $message, $titreSms);
}
elseif($fournisseurSms=="erling")
{
$this->envoyersmserling($tel, $message, $titreSms);
}
elseif($fournisseurSms=="ovh")
{
$this->envoyersmsovh($tel, $message, $titreSms);
}
elseif($fournisseurSms=="afriksms")
{
$this->envoyersmsafriksms($tel, $message, $titreSms);
}
elseif($fournisseurSms=="ekotech")
{
$this->envoyersmsekotech($tel, $message, $titreSms);
}
// sleep(1);
usleep(2000); // Stoppe pour 2 millisecondes
}
}
public function envoyersmsbliive($destinataires_c, $message_c, $titreSms_c)
{
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$url = "https://app.blive.bi/bridge-ws/ws/send";
$get = array
(
'id' =>$loginSms,
'from' =>$titreSms_c,
'to' =>$destinataires_c,
'text' =>$message_c
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $motPassSms);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $get);
$result = curl_exec($ch);
if (curl_errno($ch))
{
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$this->marquersms($this->idSms, "1");
}
public function envoyersmsesicia($destinataires_c, $message_c, $titreSms_c)
{
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$url = "http://gateway.esicia.com/sendsms/?";
$postFields = array
(
'ohereza' =>$titreSms_c,
'kuri' =>$destinataires_c,
'ubutumwa' =>$message_c,
'client' =>$loginSms,
'password' =>$motPassSms,
'msgid' =>'kanesin'
);
$post = http_build_query($postFields);
$url .= $post;
$result = file_get_contents($url);
$this->marquersms($this->idSms, "1");
}
public function envoyersmshooza($destinataires_c, $message_c, $titreSms_c)
{
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$url = "http://rslr.connectbind.com/bulksms/bulksms";
$get = array
(
'username' =>$loginSms,
'password' =>$motPassSms,
'type' =>'0',
'dlr' =>'1',
'destination' =>$destinataires_c,
'source' =>$titreSms_c,
'message' =>$message_c
);
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 10
);
$ch = curl_init();
curl_setopt_array($ch, ($defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
$this->marquersms($this->idSms, "1");
}
public function envoyersmsskysms($destinataires_c, $message_c, $titreSms_c)
{
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$url = "http://137.74.43.214:9000/api/public/sendsms/v2/output=text?";
$postFields = array
(
'user' => $loginSms,
'password' => $motPassSms,
'sender' => $titreSms_c,
'phone' => $destinataires_c,
'message' => $message_c
);
$post = http_build_query($postFields);
$url .= $post;
$result = file_get_contents($url);
$this->marquersms($this->idSms, "1");
}
public function envoyersmssatelcom($destinataires_c, $message_c, $titreSms_c)
{
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$url = "http://satelsms.satelcom.cd:8080/bulksms/bulksms?";
$postFields = array
(
'username' => $loginSms,
'password' => $motPassSms,
'type' => '0',
'dlr' => '1',
'destination' => $destinataires_c,
'source' => $titreSms_c,
'message' => $message_c
);
$post = http_build_query($postFields);
$url .= $post;
$result = file_get_contents($url);
$this->marquersms($this->idSms, "1");
}
public function envoyersmsnoah($destinataires_c, $message_c, $titreSms_c)
{
$apiId = 'R1CU5E98NHGNZP7ER8GKSVJ11AEVL1';
$suid = '5164CR45MTKYZ9';
$curl = curl_init();
$post = array(
"apiId" => $apiId,
"suid" => $suid,
"message" => $message_c,
"numbers" => [$destinataires_c],
"country" => "ci"
);
$postjson = json_encode($post);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://texto.noahmobile.com/api/v1/send',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>$postjson,
CURLOPT_HTTPHEADER => array(
'NOMO-API-KEY: 8C537744BA5B5BB5BFFBA064E853FB16A7A6F002B775C',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
$this->marquersms($this->idSms, "1");
}
public function envoyersmsnerhysms($destinataires_c, $message_c, $titreSms_c)
{
$post = array(
"from" => $titreSms_c,
"content"=> $message_c,
"to" => [$destinataires_c]
);
$postjson = json_encode($post);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://app.nerhysms.com/api/send/multiple',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>$postjson,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer 97e9dab8fa04aad831b1f41b80',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
$this->marquersms($this->idSms, "1");
}
public function envoyersmsemisms($destinataires_c, $message_c, $titreSms_c)
{
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$url = "https://app.emisms.com/sms/api?";
$postFields = array
(
'action' => $loginSms,
'api_key' => $motPassSms,
'to' => $destinataires_c,
'from' => $titreSms_c,
'sms' => $message_c
);
$post = http_build_query($postFields);
$url .= $post;
$result = file_get_contents($url);
$this->marquersms($this->idSms, "1");
}
public function envoyersmserling($destinataires_c, $message_c, $titreSms_c)
{
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$url = "http://erling.vavasms.com/api/v1/text/single";
$get = array
(
'api_key' =>$motPassSms,
'sender_id' =>$titreSms_c,
'phone' =>$destinataires_c,
'message' =>$message_c
);
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 10
);
$ch = curl_init();
curl_setopt_array($ch, ($defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
$this->marquersms($this->idSms, "1");
}
public function envoyersmsovh($destinataires_c, $message_c, $titreSms_c)
{
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$titreSms = $this->titreSms;
$compteSms = $this->compteSms;
$url = "https://www.ovh.com/cgi-bin/sms/http2sms.cgi?";
$get = array
(
'account' => $compteSms,
'login' => $loginSms,
'password' => $motPassSms,
// 'from' => 'INTERSANTE',
'from' => $titreSms,
'to' => $destinataires_c,
'message' => $message_c
);
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 10
);
$ch = curl_init();
curl_setopt_array($ch, ($defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
$this->marquersms($this->idSms, "1");
}
public function envoyersmsafriksms($destinataires_c, $message_c, $titreSms_c)
{
$curl = curl_init();
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$titreSms = $this->titreSms;
$compteSms = $this->compteSms;
$url = "https://api.afriksms.com/api/web/web_v1/outbounds/send?";
$postFields = array
(
'ClientId' => $loginSms,
'ApiKey' => $motPassSms,
'SenderId' => $titreSms,
'Message' => $message_c,
'MobileNumbers' => $destinataires_c
);
$post = http_build_query($postFields);
$url .= $post;
curl_setopt_array
(
$curl,
array
(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
)
);
$response = curl_exec($curl);
// var_dump($response);
curl_close($curl);
$this->marquersms($this->idSms, "1");
}
public function envoyersmsekotech($destinataires_c, $message_c, $titreSms_c)
{
$curl = curl_init();
$loginSms = $this->loginSms;
$motPassSms = $this->motPassSms;
$titreSms = $this->titreSms;
$url = "https://api-public.ekotech.cm/messages";
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "username=$loginSms&password=$motPassSms&msisdn=$destinataires_c&msg=$message_c&sender=$titreSms"
));
$response = curl_exec($curl);
// var_dump($response);
curl_close($curl);
$this->marquersms($this->idSms, "1");
}
public function marquersmswhatsapp($idSmswha, $etat)
{
require_once 'Envoismscron.php';
$this->smscron = new Envoismscron();
$smsaenvoyerwha = $this->smscron->marquersmswhatsapp($idSmswha, $etat);
}
public function envoyer_les_sms_wha($fournisseurWhatsApp)
{
$lesSmswha = $this->lesSmswha;
foreach ($lesSmswha as $un_smswha)
{
$this->idSmswha = $un_smswha['idSms'];
$this->destinataireswha = $un_smswha['destinataires'];
$this->messagewha = $un_smswha['message'];
$this->envoyer_un_des_sms_wha($fournisseurWhatsApp);
// sleep(1);
usleep(2000); // Stoppe pour 2 millisecondes
}
}
public function envoyer_un_des_sms_wha($fournisseurWhatsApp)
{
$destinataires = $this->destinataireswha;
$message = $this->messagewha;
$titreSms = $this->titreSms;
$dest = explode(',', $destinataires);
foreach ($dest as $tel)
{
if($fournisseurWhatsApp=="ultramsg")
{
$this->envoyerwhatsappultramsg($tel, $message, $titreSms);
}
elseif($fournisseurWhatsApp=="waapi")
{
$this->envoyerwhatsappwaapi($tel, $message, $titreSms);
}
// sleep(1);
usleep(2000); // Stoppe pour 2 millisecondes
}
}
public function envoyerwhatsappultramsg($tel, $message, $titreSms)
{
$tokenWhatsapp = $this->tokenWhatsapp;
$instanceWhatsapp = $this->instanceWhatsapp;
$url = "https://api.ultramsg.com/instance$instanceWhatsapp/messages/chat";
$params=array
(
'token' => $tokenWhatsapp,
'to' => $tel,
'body' => $message,
'priority' => '0',
'referenceId' => '',
'msgId' => '',
'mentions' => $titreSms
);
$curl = curl_init();
curl_setopt_array
(
$curl, array
(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($params),
CURLOPT_HTTPHEADER => array
(
"content-type: application/x-www-form-urlencoded"
),
)
);
$response = curl_exec($curl);
// $err = curl_error($curl);
// var_dump($response);
// var_dump($err);
curl_close($curl);
$this->marquersmswhatsapp($this->idSmswha, "1");
}
public function envoyerwhatsappwaapi($tel, $message, $titreSms)
{
$tokenWhatsapp = $this->tokenWhatsapp;
$instanceWhatsapp = $this->instanceWhatsapp;
$codePays = $this->codePays;
$destinataires_c = $tel;
/*
$debutTel = substr($tel, 0, 5);
if(($codePays=="CI" or str_contains($debutTel, '225')) && strlen($tel)>11)
{
$destinataires_c_new = substr($destinataires_c, -8);
$destinataires_c_new = '225'.$destinataires_c_new;
$destinataires_c = $destinataires_c_new;
}
*/
$url = "https://waapi.app/api/v1/instances/$instanceWhatsapp/client/action/send-message";
$curl = curl_init();
curl_setopt_array
(
$curl,
[
CURLOPT_URL => $url,
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
(
[
'chatId' => "$destinataires_c@c.us",
'message' => $message
]
),
CURLOPT_HTTPHEADER =>
[
"accept: application/json",
"authorization: Bearer $tokenWhatsapp",
"content-type: application/json"
],
]
);
$response = curl_exec($curl);
// $err = curl_error($curl);
// var_dump($response);
// var_dump($err);
curl_close($curl);
$this->marquersmswhatsapp($this->idSmswha, "1");
}
}