-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from arif98741/dev
Merge Request to Add Quick Sms Gateway
- Loading branch information
Showing
3 changed files
with
93 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
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
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,85 @@ | ||
<?php | ||
/* | ||
* Last Modified: 26/10/23, 10:40 PM | ||
* Copyright (c) 2023 | ||
* -created by Ariful Islam | ||
* -All Rights Preserved By | ||
* -If you have any query then knock me at | ||
* arif98741@gmail.com | ||
* See my profile @ https://github.com/arif98741 | ||
*/ | ||
|
||
namespace Xenon\LaravelBDSms\Provider; | ||
|
||
use Xenon\LaravelBDSms\Handler\RenderException; | ||
use Xenon\LaravelBDSms\Request; | ||
use Xenon\LaravelBDSms\Sender; | ||
|
||
class QuickSms extends AbstractProvider | ||
{ | ||
/** | ||
* QuickSms constructor. | ||
* @param Sender $sender | ||
*/ | ||
public function __construct(Sender $sender) | ||
{ | ||
$this->senderObject = $sender; | ||
} | ||
|
||
/** | ||
* Send Request To Api and Send Message | ||
* @throws RenderException | ||
*/ | ||
public function sendRequest() | ||
{ | ||
$mobile = $this->senderObject->getMobile(); | ||
$text = $this->senderObject->getMessage(); | ||
$config = $this->senderObject->getConfig(); | ||
$queue = $this->senderObject->getQueue(); | ||
|
||
$query = [ | ||
'api_key' => $config['api_key'], | ||
'senderid' => $config['senderid'], | ||
'contacts' => $mobile, | ||
'msg' => $text, | ||
]; | ||
|
||
if (array_key_exists('type', $config)) { | ||
$query ['type'] = $config['type']; | ||
} | ||
|
||
if (array_key_exists('scheduledDateTime', $config)) { | ||
$query ['scheduledDateTime'] = $config['scheduledDateTime']; | ||
} | ||
|
||
if (is_array($mobile)) { | ||
$query['contacts'] = implode(',', $mobile); | ||
} | ||
|
||
$requestObject = new Request('https://server1.quicksms.xyz/smsapi', $query, $queue); | ||
$requestObject->setContentTypeJson(true); | ||
|
||
$response = $requestObject->post(); | ||
if ($queue) { | ||
return true; | ||
} | ||
$body = $response->getBody(); | ||
$smsResult = $body->getContents(); | ||
$data['number'] = $mobile; | ||
$data['message'] = $text; | ||
return $this->generateReport($smsResult, $data)->getContent(); | ||
} | ||
|
||
/** | ||
* @throws RenderException | ||
*/ | ||
public function errorException(): void | ||
{ | ||
if (!array_key_exists('api_key', $this->senderObject->getConfig())) { | ||
throw new RenderException('api_key key is absent in configuration'); | ||
} | ||
if (!array_key_exists('senderid', $this->senderObject->getConfig())) { | ||
throw new RenderException('senderid key is absent in configuration'); | ||
} | ||
} | ||
} |