mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-13 00:01:04 +03:30
add rahyab notification service
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Notification\Batch;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class BatchTransmitter
|
||||
{
|
||||
|
||||
protected Collection $collection;
|
||||
protected mixed $config;
|
||||
protected $message;
|
||||
|
||||
public function __construct( Collection $collection )
|
||||
{
|
||||
$this->collection = $collection;
|
||||
$this->config = config( 'notification.drivers.rahyab_advertise' );
|
||||
$this->client = new \SoapClient( $this->config[ 'url' ] );
|
||||
}
|
||||
|
||||
public function send( string $message )
|
||||
{
|
||||
$this->message = $message;
|
||||
if ( $this->collection->count() <= config( 'notification.max_phone_size.do_send_sms' ) ) {
|
||||
return $result = $this->client->doSendSMS( $this->payload() );
|
||||
}
|
||||
}
|
||||
|
||||
protected function getPhones()
|
||||
{
|
||||
$phones = [];
|
||||
foreach ( $this->collection as $key => $item ) {
|
||||
$phones[] = $item->getPhone();
|
||||
}
|
||||
return array_unique( $phones );
|
||||
}
|
||||
|
||||
protected function payload()
|
||||
{
|
||||
return array(
|
||||
'uUsername' => $this->config[ 'username' ] ,
|
||||
'uPassword' => $this->config[ 'password' ] ,
|
||||
'uNumber' => $this->config[ 'from' ] ,
|
||||
'uCellphones' => implode( ';' , $this->getPhones() ) ,
|
||||
'uMessage' => $this->message ,
|
||||
'uFarsi' => true ,
|
||||
'uTopic' => false ,
|
||||
'uFlash' => false ,
|
||||
'uUDH' => ''
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user