src/Application/Project/SettingBundle/Service/ServiceComteleSMS.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Application\Project\SettingBundle\Service;
  3. use App\Application\Internit\EmpresaBundle\Entity\Empresa;
  4. use Comtele\Services\CreditService;
  5. use Comtele\Services\TextMessageService;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use function Symfony\Component\Translation\t;
  8. class ServiceComteleSMS
  9. {
  10.     protected string $url "https://sms.comtele.com.br/api";
  11.     protected ?string $token null;
  12.     public function __construct(
  13.         protected ManagerRegistry $em
  14.     )
  15.     {
  16.         if($this->getEmpresa() && $this->getEmpresa()->getComteleToken())
  17.             $this->token $this->getEmpresa()->getComteleToken();
  18.     }
  19.     public function sendSMS(string $phonestring $message)
  20.     {
  21.         if(!$this->token)
  22.             return;
  23.         $empresa $this->getEmpresa();
  24.         $empresaNome $empresa->getNome();
  25.         $textMessageService = new TextMessageService($this->token);
  26.         $result $textMessageService->send(
  27.             sender"Portal do Cliente - $empresaNome",
  28.             content$message,
  29.             receivers: [$phone]
  30.         );
  31.         if($result->Success){
  32.             $empresa->setComteleEnvios($empresa->getComteleEnvios()+1);
  33.             $this->em->getManager()->persist($empresa);
  34.             $this->em->getManager()->flush();
  35.         }
  36.     }
  37.     public function consultarCreditos()
  38.     {
  39.         if(!$this->token)
  40.             return;
  41.         var_dump($this->token);
  42.         $creditService = new CreditService($this->token);
  43.         $result $creditService->get_my_credits();
  44.         var_dump($result);
  45.     }
  46.     private function getEmpresa(): ?Empresa
  47.     {
  48.         return $this->em->getRepository(Empresa::class)->find(1);
  49.     }
  50. }