src/Fonctions/Fonctions.php line 28

Open in your IDE?
  1. <?php 
  2. namespace App\Fonctions;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use App\Entity\AffectationFonctionnalite;
  5. use App\Entity\Log;
  6. use App\Entity\Client;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use App\Repository\AffectationFonctionnaliteRepository;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  14. class Fonctions
  15. {
  16.     
  17.   private $urlGenerator;
  18.   private $url;
  19.      public function __construct(EntityManagerInterface $em,AffectationFonctionnaliteRepository $AffectationFonctionnaliteRepository,?UserInterface $user,SessionInterface $session,RequestStack $requestStack,UrlGeneratorInterface $urlGenerator)
  20.     {
  21.         $this->em $em;
  22.         $this->session $session;
  23.         $this->getUser $user;
  24.         $this->AffectationFonctionnaliteRepository $AffectationFonctionnaliteRepository;
  25.         
  26.         $this->urlGenerator $urlGenerator;
  27.         $this->requestStack $requestStack;
  28.         $this->url "https://sandbox.crmgarbal.com/";
  29.     }
  30.      public function Menuactive()
  31.      {  
  32.          $i=$this->session->get('select');
  33.          return $i;   
  34.      }
  35.      public function SousMenuactive()
  36.      {  
  37.       $i=$this->session->get('Sousselect');
  38.       return $i;   
  39.      }
  40.     public function MessageBienvenue($imageUrl,$var1,$var2$number
  41.     {
  42.         $data json_encode([
  43.         "messaging_product" => "whatsapp",
  44.         "to" => $number,
  45.         "type" => "template",
  46.         "template" => [
  47.             "name" => "bienvenu_3",
  48.             "language" => [
  49.                 "code" => "fr"
  50.             ],
  51.             "components" => [
  52.                 [
  53.                     "type" => "header",
  54.                     "parameters" => [
  55.                         [
  56.                             "type" => "image",
  57.                             "image" => [
  58.                                 "link" => $imageUrl
  59.                             ]
  60.                         ]
  61.                     ]
  62.                 ],
  63.                 [
  64.                     "type" => "body",
  65.                     "parameters" => [
  66.                         [
  67.                             "type" => "text",
  68.                             "text" => $var1
  69.                         ],
  70.                         [
  71.                             "type" => "text",
  72.                             "text" => $var2
  73.                         ],
  74.                     ]
  75.                 ],
  76.                 [
  77.                     "type"=> "button",
  78.                     "sub_type"=> "quick_reply",
  79.                     "index"=> "0",
  80.                     "parameters"=> [
  81.                         [
  82.                             "type"=> "payload",
  83.                             "payload"=> "001"
  84.                         ]
  85.                     ]
  86.                 ],
  87.                 [
  88.                     "type"=> "button",
  89.                     "sub_type"=> "quick_reply",
  90.                     "index"=> "1",
  91.                     "parameters"=> [
  92.                         [
  93.                             "type"=> "payload",
  94.                             "payload"=> "002"
  95.                         ]
  96.                     ]
  97.                 ],
  98.             ]
  99.         ]
  100.         ]);
  101.         return $data;
  102.     }
  103. //     public function MessageChoixService($text,$number) 
  104. //     {
  105. //         $data = json_encode([
  106. //             "messaging_product" => "whatsapp",
  107. //             "to" => $number,
  108. //             "type" => "interactive",
  109. //             "interactive" => [
  110. //                 "type" => "list",
  111. //                 "body" => [
  112. //                     "text" => $text
  113. //                 ],
  114. //                 "footer" => [
  115. //                     "text" => "Pour arrêter le processus de commande tapez bye ou au revoir"
  116. //                 ],
  117. //                 "action" => [
  118. //                     "button" => "Choisir un service",
  119. //                     "sections" => [
  120. //                         [
  121. //                             "title" => "Services disponibles",
  122. //                             "rows" => [
  123. //                                 [
  124. //                                     "id" => "Sc_001",
  125. //                                     "title" => "AGRO METEO",
  126. //                                     "description" => "Rechercher les prevission metéorologique d'une localité du niger"
  127. //                                 ],
  128. //                                 [
  129. //                                     "id" => "Sc_002",
  130. //                                     "title" => "APPUIS CONSEIL",
  131. //                                     "description" => "Rechercher des conseil et assistance dans les differentes donnaine"
  132. //                                 ],
  133.                                 
  134. //                                 [
  135. //                                     "id" => "Sc_003",
  136. //                                     "title" => "PRIX",
  137. //                                     "description" => "Rechercher le prix des animaux et des produit agricole dans les differentes marche du niger"
  138. //                                 ]
  139. //                             ]
  140. //                         ]
  141. //                     ]
  142. //                 ]
  143. //             ]
  144. //         ]);
  145. //         return $data;
  146. //   }
  147.     public function execPost($token,$chemin,$dataPost)
  148.     {
  149.         $curl curl_init();
  150.         curl_setopt_array($curl, array(
  151.         CURLOPT_URL => $this->url.$chemin,
  152.         CURLOPT_RETURNTRANSFER => true,
  153.         CURLOPT_ENCODING => '',
  154.         CURLOPT_MAXREDIRS => 10,
  155.         CURLOPT_TIMEOUT => 0,
  156.         CURLOPT_FOLLOWLOCATION => true,
  157.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  158.         CURLOPT_CUSTOMREQUEST => 'POST',
  159.         CURLOPT_POSTFIELDS => $dataPost,
  160.         CURLOPT_HTTPHEADER => array(
  161.             'Content-Type: application/json',
  162.             'Authorization: Bearer '.$token
  163.         ),
  164.         ));
  165.         $response curl_exec($curl);
  166.         curl_close($curl);
  167.             // dd($this->url.$chemin,$response,$dataPost);
  168.         $response json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$response), true);
  169.         if ($response!=null && $response['status']==401){
  170.         $this->logoutAndRedirect();
  171.         }else {
  172.             # code...
  173.             return $response;
  174.         }
  175.     }
  176.     public function execGet($token,$chemin)
  177.     {
  178.         $curl curl_init();
  179.         curl_setopt_array($curl, array(
  180.         CURLOPT_URL => $this->url.$chemin,
  181.         CURLOPT_RETURNTRANSFER => true,
  182.         CURLOPT_ENCODING => '',
  183.         CURLOPT_MAXREDIRS => 10,
  184.         CURLOPT_TIMEOUT => 0,
  185.         CURLOPT_FOLLOWLOCATION => true,
  186.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  187.         CURLOPT_CUSTOMREQUEST => 'GET',
  188.         CURLOPT_HTTPHEADER => array(
  189.             'Authorization: Bearer '.$token
  190.         ),
  191.         ));
  192.         $response curl_exec($curl);
  193.         curl_close($curl);
  194.         $response json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$response), true);
  195.         if ($response!=null && $response['status']==401){
  196.             $this->logoutAndRedirect();
  197.         }else {
  198.             # code...
  199.             return $response;
  200.         }
  201.     }
  202.     public function SendMessageWhatsApp($data) {
  203.         $curl curl_init();
  204.         curl_setopt_array($curl, array(
  205.         CURLOPT_URL => 'https://graph.facebook.com/v22.0/628049967062357/messages',
  206.         CURLOPT_RETURNTRANSFER => true,
  207.         CURLOPT_ENCODING => '',
  208.         CURLOPT_MAXREDIRS => 10,
  209.         CURLOPT_TIMEOUT => 0,
  210.         CURLOPT_FOLLOWLOCATION => true,
  211.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  212.         CURLOPT_CUSTOMREQUEST => 'POST',
  213.         CURLOPT_POSTFIELDS =>$data,
  214.         CURLOPT_HTTPHEADER => array(
  215.             'Content-Type: application/json',
  216.             'Authorization: Bearer EAAeUKx29ZAJEBO0wEB81b06PMLqfumpzgDeG8ED7HtiZBYpR9sb5WKjZBj0p9awOhFkEZC5c0ZCZB5OHXw3kHcC7vpKuIyVwmStc50Ta1xSzcbnMPbqKihbkXHZCzSgB0ZBZA6BZBTcdhTGkfdbDR7Hyf3L5llK03lcsykML7USw5L2lZBflSeCEfA8NAu6NZBlp9LfGrwZDZD'
  217.            
  218.         ),
  219.         ));
  220.         $response curl_exec($curl);
  221.         curl_close($curl);
  222.         return $response;
  223.         
  224.     }
  225.     public function MessageCommandeValide($imageUrl,$var1,$var2$number)
  226.     {
  227.         $data json_encode([
  228.             "messaging_product" => "whatsapp",
  229.             "to" => $number,
  230.             "type" => "template",
  231.             "template" => [
  232.                 "name" => "resume_ordre",
  233.                 "language" => [
  234.                     "code" => "fr"
  235.                 ],
  236.                 "components" => [
  237.                     [
  238.                         "type" => "header",
  239.                         "parameters" => [
  240.                             [
  241.                                 "type" => "image",
  242.                                 "image" => [
  243.                                     "link" => $imageUrl
  244.                                 ]
  245.                             ]
  246.                         ]
  247.                     ],
  248.                     [
  249.                         "type" => "body",
  250.                         "parameters" => [
  251.                             [
  252.                                 "type" => "text",
  253.                                 "text" => $var1
  254.                             ],
  255.                             [
  256.                                 "type" => "text",
  257.                                 "text" => $var2
  258.                             ],
  259.                         ]
  260.                     ]
  261.                 ]
  262.             ]
  263.         ]);
  264.         return $data;
  265.     }
  266.      public function log($user,$action,$statut,$msg,$entity,$identity,$old_v,$new_v)
  267.       {
  268.        $log=new Log();
  269.        $date= new \DateTime('now');
  270.        $log->setIdUser($user);
  271.        $log->setAction($action);
  272.        $log->setStatutAction($statut);
  273.        $log->setMessage($msg);
  274.        $log->setEntity($entity);
  275.        $log->setIdEntity($identity);
  276.        $log->setAncienValeur($old_v);
  277.        $log->setNouvelleValeur($new_v);;
  278.        return $log;
  279.       }
  280.         // public function client($entityManager, $telephone, $nomprenom, $adresse)
  281.         // {
  282.         //     $client = new Client();
  283.         //     $client->setNomPrenom($nomprenom);
  284.         //     $client->setTelephone($telephone);
  285.         //     $client->setAdresse($adresse);
  286.         //     $client->setStatut(1); // obligatoire si utilisé dans la recherche
  287.         //     $entityManager->persist($client);
  288.         //     $entityManager->flush();
  289.         //     return $client;
  290.         // }
  291.     //   public function client($entityManager,$telephone,$nomprenom,$adresse)
  292.     //   {
  293.     //    $client=new Client();
  294.     //    $client->setNomPrenom($nomprenom);
  295.     //    $client->setTelephone($telephone);
  296.     //    $client->setAdresse($adresse);
  297.     //    $entityManager->persist($client);
  298.     //    $entityManager->flush();
  299.     // //    return $client;
  300.     //   }
  301.      function envoi_sms($numero,$msg)
  302.      {
  303.         $login='zamoha';
  304.         $pass='zamoha@2030';
  305.         $sigle='zamoha';
  306.         $sigle1='GARBAL';
  307.         $code='227';
  308.         //$numero = urlencode($numero);
  309.         $numero $numero;
  310.         $numero1 $code.$numero;
  311.         $msg=$msg;
  312.         
  313.         //$msg=urlencode($msg);
  314.         
  315.                     
  316.         // SMPP AIRTEL
  317.           $url="http://localhost:13102/cgi-bin/sendsms?username=lolo100&password=lolopw100&from=$sigle1&to=$numero1&text=".urlencode($msg);
  318.         
  319.         // SMPP ZAMOHA
  320.         //$url="https://appssms.zamoha.com/notification.php?login=$login&pass=$pass&sigle=$sigle&number=$numero&message=".urlencode($msg)."&code=$code";
  321.         
  322.         $raw file_get_contents($url);
  323.         $json json_decode($raw);
  324.         return $json//  [0];
  325.      }
  326.     
  327.      
  328.      
  329. }