<?php
namespace App\Application\Project\SettingBundle\Service;
use App\Application\Internit\EmpresaBundle\Entity\Empresa;
use Comtele\Services\CreditService;
use Comtele\Services\TextMessageService;
use Doctrine\Persistence\ManagerRegistry;
use function Symfony\Component\Translation\t;
class ServiceComteleSMS
{
protected string $url = "https://sms.comtele.com.br/api";
protected ?string $token = null;
public function __construct(
protected ManagerRegistry $em
)
{
if($this->getEmpresa() && $this->getEmpresa()->getComteleToken())
$this->token = $this->getEmpresa()->getComteleToken();
}
public function sendSMS(string $phone, string $message)
{
if(!$this->token)
return;
$empresa = $this->getEmpresa();
$empresaNome = $empresa->getNome();
$textMessageService = new TextMessageService($this->token);
$result = $textMessageService->send(
sender: "Portal do Cliente - $empresaNome",
content: $message,
receivers: [$phone]
);
if($result->Success){
$empresa->setComteleEnvios($empresa->getComteleEnvios()+1);
$this->em->getManager()->persist($empresa);
$this->em->getManager()->flush();
}
}
public function consultarCreditos()
{
if(!$this->token)
return;
var_dump($this->token);
$creditService = new CreditService($this->token);
$result = $creditService->get_my_credits();
var_dump($result);
}
private function getEmpresa(): ?Empresa
{
return $this->em->getRepository(Empresa::class)->find(1);
}
}