-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Xenon\LaravelBDSms\Provider; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\ClientException; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use Illuminate\Http\JsonResponse; | ||
use Xenon\LaravelBDSms\Handler\RenderException; | ||
use Xenon\LaravelBDSms\Sender; | ||
|
||
class BoomCast extends AbstractProvider | ||
{ | ||
/** | ||
* BoomCast Constructor | ||
* @param Sender $sender | ||
* @version v1.0.32 | ||
* @since v1.0.31 | ||
*/ | ||
public function __construct(Sender $sender) | ||
{ | ||
$this->senderObject = $sender; | ||
} | ||
|
||
/** | ||
* @return JsonResponse | ||
* @throws GuzzleException | ||
* @throws RenderException | ||
* @version v1.0.37 | ||
* @since v1.0.31 | ||
*/ | ||
public function sendRequest() | ||
{ | ||
$mobile = $this->senderObject->getMobile(); | ||
$text = $this->senderObject->getMessage(); | ||
$config = $this->senderObject->getConfig(); | ||
|
||
|
||
$client = new Client([ | ||
'base_uri' => 'https://api.boom-cast.com/boomcast/WebFramework/boomCastWebService/OTPMessage.php', | ||
'timeout' => 10.0, | ||
'verify' => false, | ||
]); | ||
|
||
try { | ||
$response = $client->request('GET', '', [ | ||
'query' => [ | ||
"masking" => $config['masking'], | ||
"userName" => $config['username'], | ||
"password" => $config['password'], | ||
"MsgType" => "TEXT", | ||
"receiver" => $mobile, | ||
"message" => $text, | ||
], | ||
'timeout' => 60, | ||
'read_timeout' => 60, | ||
'connect_timeout' => 60 | ||
]); | ||
} catch (ClientException|GuzzleException $e) { | ||
throw new RenderException($e->getMessage()); | ||
} | ||
|
||
|
||
$response = $response->getBody()->getContents(); | ||
|
||
$data['number'] = $mobile; | ||
$data['message'] = $text; | ||
return $this->generateReport($response, $data); | ||
} | ||
|
||
/** | ||
* @throws RenderException | ||
* @version v1.0.32 | ||
* @since v1.0.31 | ||
*/ | ||
public function errorException() | ||
{ | ||
$config = $this->senderObject->getConfig(); | ||
|
||
|
||
if (!array_key_exists('masking', $config)) | ||
throw new RenderException('masking key is absent in configuration'); | ||
|
||
if (!array_key_exists('username', $config)) | ||
throw new RenderException('username key is absent in configuration'); | ||
|
||
if (!array_key_exists('password', $config)) | ||
throw new RenderException('password key is absent in configuration'); | ||
} | ||
} |