805 lines
20 KiB
PHP
Executable File
805 lines
20 KiB
PHP
Executable File
<?php
|
|
require_once 'Framework/Controleur.php';
|
|
require_once 'Modele/Societeuser.php';
|
|
require_once 'Modele/Societeusercentral.php';
|
|
|
|
class ControleurAjaxtesterdisponiblitesms extends Controleur {
|
|
private $societeuser;
|
|
private $societeusercentral;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->societeuser = new Societeuser();
|
|
$this->societeusercentral = new Societeusercentral();
|
|
|
|
$codeSociete = $_SESSION['codeSociete'];
|
|
$societe = $this->societeuser->getSocieteSimple($codeSociete);
|
|
$paramwhatsapp = $this->societeusercentral->getSocieteusersWhatsapp($codeSociete);
|
|
|
|
$this->loginSms = $societe['loginSms'];
|
|
$this->motPassSms = $societe['motPassSms'];
|
|
$this->titreSms = $societe['titreSms'];
|
|
/*
|
|
$this->tokenWhatsapp = $societe['tokenWhatsapp'];
|
|
$this->instanceWhatsapp = $societe['instanceWhatsapp'];
|
|
*/
|
|
$this->tokenWhatsapp = $paramwhatsapp['tokenWhatsapp'];
|
|
$this->instanceWhatsapp = $paramwhatsapp['instanceWhatsapp'];
|
|
|
|
$this->codePays = $societe['codePays'];
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
}
|
|
|
|
public function envoyerlesms()
|
|
{
|
|
$destinataires = $this->requete->getParametreFormulaire("destinataires");
|
|
$message = $this->requete->getParametreFormulaire("message");
|
|
$fournisseurSms = $this->requete->getParametreFormulaire("fournisseurSms");
|
|
|
|
$dest = explode(',', $destinataires);
|
|
|
|
foreach ($dest as $tel)
|
|
{
|
|
if($fournisseurSms=="esicia")
|
|
{
|
|
$this->envoyersmsesicia($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="blive")
|
|
{
|
|
$this->envoyersmsbliive($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="hooza")
|
|
{
|
|
$this->envoyersmshooza($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="skysms")
|
|
{
|
|
$this->envoyersmsskysms($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="satelcom")
|
|
{
|
|
$this->envoyersmssatelcom($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="noah")
|
|
{
|
|
$this->envoyersmsnoah($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="nerhysms")
|
|
{
|
|
$this->envoyersmsnerhysms($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="emisms")
|
|
{
|
|
$this->envoyersmsemisms($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="acimsms")
|
|
{
|
|
$this->envoyersmsacimsms($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="erling")
|
|
{
|
|
$this->envoyersmserling($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="ovh")
|
|
{
|
|
$this->envoyersmsovh($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="afriksms")
|
|
{
|
|
$this->envoyersmsafriksms($tel, $message);
|
|
}
|
|
elseif($fournisseurSms=="ekotech")
|
|
{
|
|
$this->envoyersmsekotech($tel, $message);
|
|
}
|
|
else
|
|
{
|
|
echo "Fournissuer SMS $fournisseurSms introuvable!";
|
|
}
|
|
}
|
|
}
|
|
|
|
public function envoyersmsbliive($destinataires_c, $message_c)
|
|
{
|
|
$loginSms = $this->loginSms;
|
|
$motPassSms = $this->motPassSms;
|
|
|
|
$url = "https://app.blive.bi/bridge-ws/ws/send";
|
|
|
|
$get = array
|
|
(
|
|
'id' =>$loginSms,
|
|
'from' =>'INTERSANTE',
|
|
'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);
|
|
exit();
|
|
}
|
|
|
|
$info = curl_getinfo($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
var_dump($result);
|
|
}
|
|
|
|
|
|
public function envoyersmsovh($destinataires_c, $message_c)
|
|
{
|
|
$loginSms = $this->loginSms;
|
|
$motPassSms = $this->motPassSms;
|
|
|
|
/*
|
|
https://www.ovh.com/cgi-bin/sms/http2sms.cgi?&account=XXXXXXX&login=XXXXXXX&password=XXXXXXX&from=XXXXXXX&to=XXXXXXX&message=XXXXXXX
|
|
|
|
https://www.ovh.com/cgi-bin/sms/http2sms.cgi?&account=sms-kl66872-1&login=intersante&password=1trSante&from=INTERSANTE&to=2250506802339&message=TESTSMSOVH
|
|
|
|
account = sms-kl66872-1
|
|
login = intersante
|
|
password = 1trSante
|
|
from = INTERSANTE
|
|
to = 2250506802339
|
|
message = TESTSMSOVH
|
|
*/
|
|
|
|
$url = "https://www.ovh.com/cgi-bin/sms/http2sms.cgi?";
|
|
|
|
$postFields = array
|
|
(
|
|
'account' => 'sms-kl66872-1',
|
|
'login' => 'intersante',
|
|
// 'login' => $loginSms,
|
|
'password' => '1trSante',
|
|
// 'password' => $motPassSms,
|
|
'from' => 'INTERSANTE',
|
|
'to' => $destinataires_c,
|
|
'message' => $message_c
|
|
);
|
|
|
|
$post = http_build_query($postFields);
|
|
|
|
$url .= $post;
|
|
|
|
$result = file_get_contents($url);
|
|
|
|
var_dump($result);
|
|
}
|
|
|
|
public function envoyersmsesicia($destinataires_c, $message_c)
|
|
{
|
|
$loginSms = $this->loginSms;
|
|
$motPassSms = $this->motPassSms;
|
|
|
|
$url = "http://gateway.esicia.com/sendsms/?";
|
|
|
|
$postFields = array
|
|
(
|
|
'ohereza' =>'INTERSANTE',
|
|
'kuri' =>$destinataires_c,
|
|
'ubutumwa' =>$message_c,
|
|
'client' =>$loginSms,
|
|
'password' =>$motPassSms,
|
|
'msgid' =>'kanesin'
|
|
);
|
|
|
|
$post = http_build_query($postFields);
|
|
|
|
$url .= $post;
|
|
|
|
$result = file_get_contents($url);
|
|
|
|
var_dump($result);
|
|
}
|
|
|
|
public function envoyersmshooza($destinataires_c, $message_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' =>'INTERSANTE',
|
|
'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);
|
|
|
|
var_dump($result);
|
|
}
|
|
|
|
public function envoyersmsskysms($destinataires_c, $message_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' => 'INTERSANTE',
|
|
'phone' => $destinataires_c,
|
|
'message' => $message_c
|
|
);
|
|
|
|
$post = http_build_query($postFields);
|
|
|
|
$url .= $post;
|
|
|
|
$result = file_get_contents($url);
|
|
|
|
var_dump($result);
|
|
}
|
|
|
|
public function envoyersmssatelcom($destinataires_c, $message_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' => 'INTERSANTE',
|
|
'message' => $message_c
|
|
);
|
|
|
|
$post = http_build_query($postFields);
|
|
|
|
$url .= $post;
|
|
|
|
$result = file_get_contents($url);
|
|
|
|
var_dump($result);
|
|
}
|
|
|
|
public function envoyersmsnoah($destinataires_c, $message_c)
|
|
{
|
|
//$titreSms_c = "NOAH"
|
|
$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);
|
|
|
|
|
|
//$this->marquersms($this->idSms, "1");
|
|
|
|
}
|
|
|
|
public function envoyersmsnerhysms($destinataires_c, $message_c)
|
|
{
|
|
$titreSms_c = "VITALIS";
|
|
|
|
$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;
|
|
}
|
|
|
|
public function envoyersmsemisms($destinataires_c, $message_c)
|
|
{
|
|
$url = "https://app.emisms.com/sms/api?";
|
|
|
|
$postFields = array
|
|
(
|
|
'action' => 'send-sms',
|
|
'api_key' => 'Um9nZXIwMjU6cm9nZWFmcmF6YTA1',
|
|
'to' => $destinataires_c,
|
|
'from' => 'VITALIS',
|
|
'sms' => $message_c
|
|
);
|
|
|
|
$post = http_build_query($postFields);
|
|
|
|
$url .= $post;
|
|
|
|
$result = file_get_contents($url);
|
|
|
|
var_dump($result);
|
|
}
|
|
|
|
public function envoyersmsacimsms($destinataires_c, $message_c)
|
|
{
|
|
|
|
|
|
/*
|
|
$url = "https://app.emisms.com/sms/api?";
|
|
|
|
$postFields = array
|
|
(
|
|
'action' => 'send-sms',
|
|
'api_key' => 'Um9nZXIwMjU6cm9nZWFmcmF6YTA1',
|
|
'to' => $destinataires_c,
|
|
'from' => 'VITALIS',
|
|
'sms' => $message_c
|
|
);
|
|
|
|
$post = http_build_query($postFields);
|
|
|
|
$url .= $post;
|
|
|
|
$result = file_get_contents($url);
|
|
|
|
var_dump($result);
|
|
*/
|
|
|
|
|
|
/*
|
|
$url = "http://sms.acim-ci.net:8080/api/addFullSms";
|
|
$postFields = array
|
|
(
|
|
"Username"=>"vitalis-api",
|
|
"Token"=>"$2a$10$/0BMjY.AvsVfZafcDJxTIOzDpWTA5AigV6VeU2qiuKtYhiGcyXECi",
|
|
"Sender"=> "VITALIS",
|
|
"Sms"=> "Hello World",
|
|
"Contact" => $destinataires_c
|
|
|
|
);
|
|
|
|
$post = http_build_query($postFields);
|
|
|
|
$url .= $post;
|
|
|
|
$result = file_get_contents($url);
|
|
|
|
var_dump($result);
|
|
*/
|
|
}
|
|
|
|
public function envoyersmserling($destinataires_c, $message_c)
|
|
{
|
|
// var_dump($destinataires_c);
|
|
|
|
$url = "http://erling.vavasms.com/api/v1/text/single";
|
|
|
|
$get = array
|
|
(
|
|
'api_key' =>'3c5e0974b1662b1f3caec62c6247e8c68ad83ff7beaf133a48bc6c6606b3271e',
|
|
'sender_id' =>'MCICARE CI',
|
|
'phone' =>$destinataires_c,
|
|
'message' =>$message_c
|
|
);
|
|
|
|
$defaults = array(
|
|
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
|
|
// CURLOPT_URL => $url,
|
|
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);
|
|
|
|
// A SUPPRIMER
|
|
var_dump($result);
|
|
}
|
|
|
|
public function envoyersmsafriksms($destinataires_c, $message_c)
|
|
{
|
|
$curl = curl_init();
|
|
|
|
$loginSms = $this->loginSms;
|
|
$motPassSms = $this->motPassSms;
|
|
$titreSms = $this->titreSms;
|
|
|
|
$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);
|
|
}
|
|
|
|
public function envoyersmsekotech($destinataires_c, $message_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);
|
|
$err = curl_error($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
if ($err) {
|
|
echo "cURL Error #:" . $err;
|
|
} else {
|
|
echo $response;
|
|
}
|
|
}
|
|
|
|
public function envoyerlewhatsapp()
|
|
{
|
|
$societeusercentral = $this->societeusercentral->getSocieteuserSaas();
|
|
$fournisseurWhatsApp = $societeusercentral['fournisseurWhatsApp'];
|
|
|
|
if($fournisseurWhatsApp>" ")
|
|
{
|
|
$destinataires = $this->requete->getParametreFormulaire("destinataires");
|
|
$message = "TESTS WHATSAPP INTER-SANTE Fournisseur : $fournisseurWhatsApp";
|
|
|
|
$dest = explode(',', $destinataires);
|
|
|
|
foreach ($dest as $tel)
|
|
{
|
|
if($fournisseurWhatsApp=="ultramsg")
|
|
{
|
|
$this->envoyerwhatsappultramsg($tel, $message);
|
|
}
|
|
elseif($fournisseurWhatsApp=="waapi")
|
|
{
|
|
$this->envoyerwhatsappwaapi($tel, $message);
|
|
// $this->envoyerwhatsapptwilio($tel, $message);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
echo "Pas de fournissuer WhatsApp";
|
|
}
|
|
}
|
|
|
|
public function envoyerwhatsappultramsg($destinataires_c, $message_c)
|
|
{
|
|
$curl = curl_init();
|
|
|
|
$tokenWhatsapp = $this->tokenWhatsapp;
|
|
$instanceWhatsapp = $this->instanceWhatsapp;
|
|
|
|
/*
|
|
var_dump
|
|
(
|
|
array
|
|
(
|
|
"tokenWhatsapp" => $tokenWhatsapp,
|
|
"instanceWhatsapp" => $instanceWhatsapp,
|
|
)
|
|
);
|
|
exit();
|
|
*/
|
|
|
|
if($instanceWhatsapp>" " && $tokenWhatsapp>" ")
|
|
{
|
|
$titreSms = $this->titreSms;
|
|
|
|
$url = "https://api.ultramsg.com/instance$instanceWhatsapp/messages/chat";
|
|
|
|
$params=array
|
|
(
|
|
'token' => $tokenWhatsapp,
|
|
'to' => $destinataires_c,
|
|
'body' => $message_c,
|
|
'priority' => '0',
|
|
'referenceId' => '',
|
|
'msgId' => '',
|
|
'mentions' => $titreSms
|
|
);
|
|
|
|
// var_dump($params);
|
|
// exit();
|
|
|
|
$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);
|
|
|
|
var_dump($response);
|
|
|
|
curl_close($curl);
|
|
}
|
|
else
|
|
{
|
|
echo "Instance WhatsApp introuvable!";
|
|
}
|
|
}
|
|
|
|
public function envoyerwhatsappwaapi($destinataires_c, $message_c)
|
|
{
|
|
|
|
$tokenWhatsapp = $this->tokenWhatsapp;
|
|
$instanceWhatsapp = $this->instanceWhatsapp;
|
|
|
|
if($instanceWhatsapp>" " && $tokenWhatsapp>" ")
|
|
{
|
|
$curl = curl_init();
|
|
|
|
$titreSms = $this->titreSms;
|
|
$codePays = $this->codePays;
|
|
|
|
/*
|
|
$debutTel = substr($destinataires_c, 0, 5);
|
|
if(($codePays=="CI" or str_contains($debutTel, '225')) && strlen($destinataires_c)>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_c
|
|
]
|
|
),
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
echo "Instance WhatsApp introuvable!";
|
|
}
|
|
}
|
|
|
|
|
|
public function envoyerwhatsapptwilio($destinataires_c, $message_c)
|
|
{
|
|
|
|
$tokenWhatsapp = $this->tokenWhatsapp;
|
|
$instanceWhatsapp = $this->instanceWhatsapp;
|
|
|
|
if($instanceWhatsapp>" " && $tokenWhatsapp>" ")
|
|
{
|
|
$curl = curl_init();
|
|
|
|
$titreSms = $this->titreSms;
|
|
$codePays = $this->codePays;
|
|
|
|
/*
|
|
$debutTel = substr($destinataires_c, 0, 5);
|
|
if(($codePays=="CI" or str_contains($debutTel, '225')) && strlen($destinataires_c)>11)
|
|
{
|
|
$destinataires_c_new = substr($destinataires_c, -8);
|
|
$destinataires_c_new = '225'.$destinataires_c_new;
|
|
$destinataires_c = $destinataires_c_new;
|
|
}
|
|
*/
|
|
|
|
|
|
// Identifiants Twilio
|
|
$account_sid = "ACfc1e0d76680718e60d5254cf0dd0f298"; // ton SID
|
|
$auth_token = "d76457b63f91cb9d7b0631734bf4cb10"; // ton token
|
|
// $twilio_whatsapp = "whatsapp:+14155238886"; // numéro WhatsApp Twilio (fixe)
|
|
$twilio_whatsapp = "whatsapp:+12672146906"; // numéro WhatsApp Twilio (fixe)
|
|
// $to_number = "whatsapp:+22506802339"; // destinataire WhatsApp (format E.164)
|
|
// $to_number = "whatsapp:+22500867369"; // destinataire WhatsApp (format E.164)
|
|
// $to_number = "whatsapp:+22594052346"; // destinataire WhatsApp (format E.164)
|
|
// $to_number = "whatsapp:+250788439348"; // destinataire WhatsApp (format E.164)
|
|
$to_number = "whatsapp:+22506802339"; // destinataire WhatsApp (format E.164)
|
|
|
|
//+14155238886
|
|
//+12672146906 => Prod
|
|
|
|
// Message à envoyer
|
|
$message = "Bonjour 👋, ceci est un message WhatsApp envoyé via Twilio API sans SDK. Saly No Court";
|
|
|
|
// Initialiser cURL
|
|
$ch = curl_init();
|
|
|
|
// Configurer l'appel API Twilio
|
|
curl_setopt($ch, CURLOPT_URL, "https://api.twilio.com/2010-04-01/Accounts/$account_sid/Messages.json");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
|
|
"From" => $twilio_whatsapp,
|
|
"To" => $to_number,
|
|
"Body" => $message
|
|
]));
|
|
curl_setopt($ch, CURLOPT_USERPWD, $account_sid . ":" . $auth_token);
|
|
|
|
$response = curl_exec($ch);
|
|
// $err = curl_error($curl);
|
|
var_dump($response);
|
|
// var_dump($err);
|
|
|
|
curl_close($ch);
|
|
}
|
|
else
|
|
{
|
|
echo "Instance WhatsApp introuvable!";
|
|
}
|
|
}
|
|
|
|
} |