Skip to content

Commit

Permalink
Merge pull request #79 from arif98741/dev
Browse files Browse the repository at this point in the history
Wintext Gateway Added
  • Loading branch information
arif98741 authored Sep 18, 2024
2 parents 48c2ba0 + 8ff9cde commit 922d559
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ echo $status = $sender->send();
| TwentyFourBulkSmsBD | customer_id, api_key | - | Done | - | - |
| Trubosms | api_token, sender_id | - | Done | - | - |
| Viatech | api_key, mask | - | Done | - | - |
| WinText | token, messagetype, ismasking, masking | - | Done | - | - |
| ZamanIT | api_key, senderid,type | - | Done | - | - |


Expand Down
7 changes: 7 additions & 0 deletions src/Config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
use Xenon\LaravelBDSms\Provider\Twenty4BulkSms;
use Xenon\LaravelBDSms\Provider\TwentyFourBulkSmsBD;
use Xenon\LaravelBDSms\Provider\Viatech;
use Xenon\LaravelBDSms\Provider\WinText;
use Xenon\LaravelBDSms\Provider\ZamanIt;

return [
Expand Down Expand Up @@ -309,6 +310,12 @@
'user_email' => env('SMS_TWENTYFOUR_BULKSMS_USER_EMAIL', ''),
'api_key' => env('SMS_TWENTYFOUR_BULKSMS_APP_KEY', ''),
],
WinText::class => [
'token' => env('SMS_WINTEXT_TOKEN', ''),
'messagetype' => env('SMS_WINTEXT_MESSAGE_TYPE', ''),
'ismasking' => env('SMS_WINTEXT_IS_MASKING', ''),
'masking' => env('SMS_WINTEXT_MASKING',''),
],
ZamanIt::class => [
'api_key' => env('SMS_ZAMANIT_API_KEY', ''),
'type' => env('SMS_ZAMANIT_TYPE', ''),
Expand Down
88 changes: 88 additions & 0 deletions src/Provider/WinText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Xenon\LaravelBDSms\Provider;

use Xenon\LaravelBDSms\Handler\RenderException;
use Xenon\LaravelBDSms\Helper\Helper;
use Xenon\LaravelBDSms\Request;
use Xenon\LaravelBDSms\Sender;

class WinText extends AbstractProvider
{
private string $apiEndpoint = 'https://api.wintextbd.com/SingleSms';

/**
* WinText Constructor
* @param Sender $sender
* @version v1.0.32
* @since v1.0.31
*/
public function __construct(Sender $sender)
{
$this->senderObject = $sender;
}

/**
* @return false|string
* @throws RenderException
* @version v1.0.32
* @since v1.0.31
*/
public function sendRequest()
{
$mobile = $this->senderObject->getMobile();
$text = $this->senderObject->getMessage();
$config = $this->senderObject->getConfig();
$queue = $this->senderObject->getQueue();
$queueName = $this->senderObject->getQueueName();
$tries = $this->senderObject->getTries();
$backoff = $this->senderObject->getBackoff();

$formParams = [
"token" => $config['token'],
"messagetype" => $config['messagetype'] ?? 1,
"ismasking" => $config['ismasking'] ?? 'false',
"masking" => $config['masking'] ?? 'null',
"SMSText" => $text,
];

if (!is_array($mobile)) {
$formParams['mobileno'] = Helper::ensureNumberStartsWith88($mobile);
} else {
/*foreach ($mobile as $element) {
$tempMobile[] = Helper::ensureNumberStartsWith88($element);
}
$formParams['mobileno'] = implode(',', $tempMobile);*/
}

//dd($this->apiEndpoint, $formParams);
$requestObject = new Request($this->apiEndpoint, [], $queue, [], $queueName, $tries, $backoff);
$requestObject->setFormParams($formParams);
$response = $requestObject->post(false, 60);
if ($queue) {
return true;
}


$body = $response->getBody();
$smsResult = $body->getContents();

$data['number'] = $mobile;
$data['message'] = $text;
return $this->generateReport($smsResult, $data)->getContent();
}

/**
* @throws RenderException
* @version v1.0.32
* @since v1.0.31
*/
public function errorException()
{
$config = $this->senderObject->getConfig();

if (!array_key_exists('token', $config)) {
throw new RenderException('token key is absent in configuration');
}
}
}

0 comments on commit 922d559

Please sign in to comment.