Viewing file: Soniyal.php (3.38 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\VoiceCallProvider;
use App\Models\MessageLog; use Illuminate\Support\Facades\Log;
class Soniyal implements SendVoiceCallInterface {
private $credentials; private $to_numbers; private $body; private $from_number; private $mms_files; private $message; private $send_fail=[]; private $message_log;
public function __construct($credentials) { $this->credentials=$credentials; }
public function setTo($to) { $this->to_numbers = $to; return $this; }
public function setBody($body) { $this->body = $body; return $this; }
public function setFrom($from) { $this->from_number = $from; return $this; } public function setFiles($files){ $this->mms_files=$files; return $this; }
public function setMessage($message){ $this->message=$message; return $this; }
public function process() { $audioPath = asset('uploads/' . $this->mms_files); $domainName = $this->credentials->domain_name; $planId = $this->credentials->plan_id; $callerId = $this->credentials->caller_id; $userName = $this->credentials->username; $token = $this->credentials->token; if (!$audioPath || !$domainName || !$userName || !$token || !$planId ||!$callerId){ throw new \Exception('This provider is not active. Please contact with the administrator'); } $post_url = "http://$domainName/api/voice/upload_announcement.php"; $parameters = [ 'username'=> $userName, 'token'=> $token, 'announcement_path'=> $audioPath, ]; $client = new \GuzzleHttp\Client(['verify' => false]); $response = $client->post($post_url, [ 'form_params' => $parameters, ]); $responseString = $response->getBody()->getContents(); $responseStatus = json_decode($responseString); if (isset($responseStatus) && isset($responseStatus->status) && $responseStatus->status == 'success' && isset($responseStatus->data) && isset($responseStatus->data->announcement_id)){ $voiceCallUrl = "http://$domainName/api/voice/voice_broadcast.php"; $toNumbers = $this->to_numbers; if (!$toNumbers){ throw new \Exception('Invalid to numbers'); } $to = ''; foreach ($toNumbers as $toNumber){ $to .= $toNumber.","; }
$voiceCallParameters = [ 'username'=> $userName, 'token'=> $token, 'announcement_id'=> $responseStatus->data->announcement_id, 'plan_id'=> $planId, 'contact_numbers'=> $to, 'caller_id'=> $callerId, ];
$voiceCallClient = new \GuzzleHttp\Client(['verify' => false]); $voiceCallResponse = $voiceCallClient->post($voiceCallUrl, [ 'form_params' => $voiceCallParameters, ]); $voiceCallResponseString = $voiceCallResponse->getBody()->getContents(); Log::info($voiceCallResponseString); }
Log::info($responseString); }
public function getSendFail(){ return $this->send_fail; }
private function setSendFail($sendFailArray){ $this->send_fail[]=$sendFailArray; } }
|