<?php
namespace App\Fonctions;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\AffectationFonctionnalite;
use App\Entity\Log;
use App\Entity\Client;
use Symfony\Component\Security\Core\User\UserInterface;
use App\Repository\AffectationFonctionnaliteRepository;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class Fonctions
{
private $urlGenerator;
private $url;
public function __construct(EntityManagerInterface $em,AffectationFonctionnaliteRepository $AffectationFonctionnaliteRepository,?UserInterface $user,SessionInterface $session,RequestStack $requestStack,UrlGeneratorInterface $urlGenerator)
{
$this->em = $em;
$this->session = $session;
$this->getUser = $user;
$this->AffectationFonctionnaliteRepository = $AffectationFonctionnaliteRepository;
$this->urlGenerator = $urlGenerator;
$this->requestStack = $requestStack;
$this->url = "https://sandbox.crmgarbal.com/";
}
public function Menuactive()
{
$i=$this->session->get('select');
return $i;
}
public function SousMenuactive()
{
$i=$this->session->get('Sousselect');
return $i;
}
public function MessageBienvenue($imageUrl,$var1,$var2, $number)
{
$data = json_encode([
"messaging_product" => "whatsapp",
"to" => $number,
"type" => "template",
"template" => [
"name" => "bienvenu_3",
"language" => [
"code" => "fr"
],
"components" => [
[
"type" => "header",
"parameters" => [
[
"type" => "image",
"image" => [
"link" => $imageUrl
]
]
]
],
[
"type" => "body",
"parameters" => [
[
"type" => "text",
"text" => $var1
],
[
"type" => "text",
"text" => $var2
],
]
],
[
"type"=> "button",
"sub_type"=> "quick_reply",
"index"=> "0",
"parameters"=> [
[
"type"=> "payload",
"payload"=> "001"
]
]
],
[
"type"=> "button",
"sub_type"=> "quick_reply",
"index"=> "1",
"parameters"=> [
[
"type"=> "payload",
"payload"=> "002"
]
]
],
]
]
]);
return $data;
}
// public function MessageChoixService($text,$number)
// {
// $data = json_encode([
// "messaging_product" => "whatsapp",
// "to" => $number,
// "type" => "interactive",
// "interactive" => [
// "type" => "list",
// "body" => [
// "text" => $text
// ],
// "footer" => [
// "text" => "Pour arrêter le processus de commande tapez bye ou au revoir"
// ],
// "action" => [
// "button" => "Choisir un service",
// "sections" => [
// [
// "title" => "Services disponibles",
// "rows" => [
// [
// "id" => "Sc_001",
// "title" => "AGRO METEO",
// "description" => "Rechercher les prevission metéorologique d'une localité du niger"
// ],
// [
// "id" => "Sc_002",
// "title" => "APPUIS CONSEIL",
// "description" => "Rechercher des conseil et assistance dans les differentes donnaine"
// ],
// [
// "id" => "Sc_003",
// "title" => "PRIX",
// "description" => "Rechercher le prix des animaux et des produit agricole dans les differentes marche du niger"
// ]
// ]
// ]
// ]
// ]
// ]
// ]);
// return $data;
// }
public function execPost($token,$chemin,$dataPost)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->url.$chemin,
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 => $dataPost,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer '.$token
),
));
$response = curl_exec($curl);
curl_close($curl);
// dd($this->url.$chemin,$response,$dataPost);
$response = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $response), true);
if ($response!=null && $response['status']==401){
$this->logoutAndRedirect();
}else {
# code...
return $response;
}
}
public function execGet($token,$chemin)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->url.$chemin,
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',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$token
),
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $response), true);
if ($response!=null && $response['status']==401){
$this->logoutAndRedirect();
}else {
# code...
return $response;
}
}
public function SendMessageWhatsApp($data) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://graph.facebook.com/v22.0/628049967062357/messages',
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 =>$data,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer EAAeUKx29ZAJEBO0wEB81b06PMLqfumpzgDeG8ED7HtiZBYpR9sb5WKjZBj0p9awOhFkEZC5c0ZCZB5OHXw3kHcC7vpKuIyVwmStc50Ta1xSzcbnMPbqKihbkXHZCzSgB0ZBZA6BZBTcdhTGkfdbDR7Hyf3L5llK03lcsykML7USw5L2lZBflSeCEfA8NAu6NZBlp9LfGrwZDZD'
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
public function MessageCommandeValide($imageUrl,$var1,$var2, $number)
{
$data = json_encode([
"messaging_product" => "whatsapp",
"to" => $number,
"type" => "template",
"template" => [
"name" => "resume_ordre",
"language" => [
"code" => "fr"
],
"components" => [
[
"type" => "header",
"parameters" => [
[
"type" => "image",
"image" => [
"link" => $imageUrl
]
]
]
],
[
"type" => "body",
"parameters" => [
[
"type" => "text",
"text" => $var1
],
[
"type" => "text",
"text" => $var2
],
]
]
]
]
]);
return $data;
}
public function log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v)
{
$log=new Log();
$date= new \DateTime('now');
$log->setIdUser($user);
$log->setAction($action);
$log->setStatutAction($statut);
$log->setMessage($msg);
$log->setEntity($entity);
$log->setIdEntity($identity);
$log->setAncienValeur($old_v);
$log->setNouvelleValeur($new_v);;
return $log;
}
// public function client($entityManager, $telephone, $nomprenom, $adresse)
// {
// $client = new Client();
// $client->setNomPrenom($nomprenom);
// $client->setTelephone($telephone);
// $client->setAdresse($adresse);
// $client->setStatut(1); // obligatoire si utilisé dans la recherche
// $entityManager->persist($client);
// $entityManager->flush();
// return $client;
// }
// public function client($entityManager,$telephone,$nomprenom,$adresse)
// {
// $client=new Client();
// $client->setNomPrenom($nomprenom);
// $client->setTelephone($telephone);
// $client->setAdresse($adresse);
// $entityManager->persist($client);
// $entityManager->flush();
// // return $client;
// }
function envoi_sms($numero,$msg)
{
$login='zamoha';
$pass='zamoha@2030';
$sigle='zamoha';
$sigle1='GARBAL';
$code='227';
//$numero = urlencode($numero);
$numero = $numero;
$numero1 = $code.$numero;
$msg=$msg;
//$msg=urlencode($msg);
// SMPP AIRTEL
$url="http://localhost:13102/cgi-bin/sendsms?username=lolo100&password=lolopw100&from=$sigle1&to=$numero1&text=".urlencode($msg);
// SMPP ZAMOHA
//$url="https://appssms.zamoha.com/notification.php?login=$login&pass=$pass&sigle=$sigle&number=$numero&message=".urlencode($msg)."&code=$code";
$raw = file_get_contents($url);
$json = json_decode($raw);
return $json; // [0];
}
}