Skip to content

Commit

Permalink
Merge pull request #48 from sim8568X/feat-lpeek-sms-gateway
Browse files Browse the repository at this point in the history
Feat lpeek sms gateway
  • Loading branch information
sim8568X authored Sep 14, 2023
2 parents 791f043 + 84f60bc commit 1f0f447
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
custom: https://www.buymeacoffee.com/arif98741
13 changes: 8 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ php artisan config:cache && php artisan migrate

## Usage

### Simply use the facade
### Simply use the facade
`Note: For sending message using facade you must have to set .env credentials. Find .env credentials for different providers from inside config/sms.php)`
<pre>
use Xenon\LaravelBDSms\Facades\SMS;

Expand Down Expand Up @@ -182,18 +183,20 @@ $status = $sender->send();
| DianaSMS | ApiKey, ClientId, SenderId | Done | - | - |
| Esms | api_token, sender_id | Done | - | - |
| ElitBuzz | api_key, type, senderid | Done | not tested yet in live | - |
| Grameenphone | username, password, messagetype | Done | not tested yet in live | - |
| Infobip | user, password | Done | not tested yet in live | - |
| Lpeek | acode, apiKey, requestID, masking | Done | - | - |
| MDL | api_key, type, senderid | Done | not tested yet in live | - |
| Metronet | api_key, mask | Done | - | - |
| MimSms | api_key, type, senderid | Done | - | - |
| Mobireach | Username,Password, From | Done | - | - |
| NovocomBD | ApiKey , ClientId , SenderId | Done | - | - |
| OnnoRokomSMS | userName, userPassword, type, maskName, campaignName | Done | not tested yet in live | - |
| RedmoITSms | api_token, sender_id | Support closed | - |
| RedmoITSms | api_token, sender_id | Support closed | - |
| SmartLabSMS | user, password, sender | Done | - | - |
| SmsinBD | api_token, senderid | Done | 01777-333677 | - |
| SmsQ | sender_id, client_id, api_key | Done | | - |
| SMSNet24 | user_id, user_password, route_id(optional), sms_type_id(optional) | Done | - | admin2@digitallabbd.com, +880 1705 691269, +880 1733393 712 |
| SmsinBD | api_token, senderid | Done | | - |
| SmsQ | sender_id, client_id, api_key | Done | | - |
| SMSNet24 | user_id, user_password, route_id(optional), sms_type_id(optional) | Done | - | |
| SmsNoc | sender_id, bearer_token | Done | - | |
| Sslsms | api_token, sid, csms_id | Done | - | - |
| Tense | user, password, campaign, masking | Done | - | - |
Expand Down
15 changes: 15 additions & 0 deletions src/Config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
use Xenon\LaravelBDSms\Provider\DnsBd;
use Xenon\LaravelBDSms\Provider\ElitBuzz;
use Xenon\LaravelBDSms\Provider\Esms;
use Xenon\LaravelBDSms\Provider\Grameenphone;
use Xenon\LaravelBDSms\Provider\GreenWeb;
use Xenon\LaravelBDSms\Provider\Infobip;
use Xenon\LaravelBDSms\Provider\Lpeek;
use Xenon\LaravelBDSms\Provider\MDL;
use Xenon\LaravelBDSms\Provider\Metronet;
use Xenon\LaravelBDSms\Provider\MimSms;
Expand Down Expand Up @@ -122,6 +124,11 @@
'sender_id' => env('SMS_ESMS_SENDER_ID', ''),
'api_token' => env('SMS_ESMS_API_TOKEN', ''),
],
Grameenphone::class => [
'username' => env('SMS_GRAMEENPHONE_USERNAME', ''),
'password' => env('SMS_GRAMEENPHONE_PASSWORD', ''),
'messagetype' => env('SMS_GRAMEENPHONE_MESSAGETYPE', 1),
],
GreenWeb::class => [
'token' => env('SMS_GREEN_WEB_TOKEN', ''),
],
Expand All @@ -131,6 +138,14 @@
'password' => env('SMS_INFOBIP_PASSWORD', ''),
'from' => env('SMS_INFOBIP_FROM', ''),
],
Lpeek::class => [
'acode' => env('SMS_LPEEK_ACODE', ''),
'apiKey' => env('SMS_LPEEK_APIKEY', ''),
'requestID' => env('SMS_LPEEK_REQUESTID', ''),
'masking' => env('SMS_LPEEK_MASKING', ''),
'is_unicode' => env('SMS_LPEEK_IS_UNICODE', '0'),
'transactionType' => env('SMS_LPEEK_TRANSACTIONTYPE', 'T'),
],
MDL::class => [
'senderid' => env('SMS_MDL_SENDER_ID', ''),
'api_key' => env('SMS_MDL_API_KEY', ''),
Expand Down
13 changes: 13 additions & 0 deletions src/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,17 @@ public static function checkMobileNumberPrefixExistence($mobile)
}
return '88' . $mobile;
}

/**
* @param string $text
* @return string
* @since v1.0.52.0-beta
* @version v1.0.52.0-beta
*/
public static function ensureNumberStartsWith88(string $text): string {
if (!str_starts_with($text, '88')) {
$text = '88' . $text;
}
return $text;
}
}
101 changes: 101 additions & 0 deletions src/Provider/Grameenphone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/*
* Last Modified: 6/29/21, 12:06 AM
* Copyright (c) 2021
* -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\ParameterException;
use Xenon\LaravelBDSms\Handler\RenderException;
use Xenon\LaravelBDSms\Request;
use Xenon\LaravelBDSms\Sender;

/**
* Grameenphone Corporate Bulk SMS
* Grameenphone is introducing Corporate Bulk SMS for the first time in Bangladesh, a dynamic SMS based communication
* solution targeted towards the Business Clients by which they can send SMS from their own location integrated with
* their applications with high speed modality.
*/
class Grameenphone extends AbstractProvider
{
private string $apiEndpoint = 'https://gpcmp.grameenphone.com/ecmapigw/webresources/ecmapigw.v2';

/**
* Grameenphone constructor.
* @param Sender $sender
*/
public function __construct(Sender $sender)
{
$this->senderObject = $sender;
}

/**
* Send Request To Api and Send Message
* @throws RenderException
*/
public function sendRequest()
{
$number = $this->senderObject->getMobile();
$text = $this->senderObject->getMessage();
$config = $this->senderObject->getConfig();
$queue = $this->senderObject->getQueue();

$formParams = [
'username' => $config['username'],
'password' => $config['password'],
'apicode' => 1, //1 – For Sending, 2 – Check CLI, 3 - For check credit balance, 4 – For Delivery report status, 5 - for SMS submit with delivery request, 6 - for SMS submit without delivery
'msisdn' => $number,
'countrycode' => "880", //880 for Bangladesh
'cli' => 2222, //2222 cli code
'messagetype' => $config['messagetype'], //1 – for Text, 3 – for Unicode(Bangla), 2 – for Flash
'messageid' => 0,
'message' => $text,
];

$requestObject = new Request($this->apiEndpoint, $formParams, $queue);
$requestObject->setContentTypeJson(true);
$response = $requestObject->post();
if ($queue) {
return true;
}

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

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

/**
* @throws ParameterException
*/
public function errorException()
{
if (!array_key_exists('username', $this->senderObject->getConfig())) {
throw new ParameterException('username key is absent in configuration');
}

if (!array_key_exists('password', $this->senderObject->getConfig())) {
throw new ParameterException('password key is absent in configuration');
}

if (!array_key_exists('messagetype', $this->senderObject->getConfig())) {
throw new ParameterException('messagetype key is absent in configuration. 1 for Text, 2 for Flash, 3 for Unicode(Bangla)');
}

$configMessageType = $this->senderObject->getConfig()['messagetype'];
$validMessageTypes = [1,2,3];

if (!in_array($configMessageType, $validMessageTypes)) {
throw new ParameterException('Invalid messagetype. Set value 1 for Text, 2 for Flash, 3 for Unicode(Bangla)');
}

}
}
93 changes: 93 additions & 0 deletions src/Provider/Lpeek.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/*
* Last Modified: 6/29/21, 12:06 AM
* Copyright (c) 2021
* -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\ParameterException;
use Xenon\LaravelBDSms\Handler\RenderException;
use Xenon\LaravelBDSms\Helper\Helper;
use Xenon\LaravelBDSms\Request;
use Xenon\LaravelBDSms\Sender;

class Lpeek extends AbstractProvider
{
/**
* Lpeek constructor.
* @param Sender $sender
*/
public function __construct(Sender $sender)
{
$this->senderObject = $sender;
}

/**
* Send Request To Api and Send Message
* @throws RenderException
*/
public function sendRequest()
{
$number = Helper::ensureNumberStartsWith88($this->senderObject->getMobile());

$text = $this->senderObject->getMessage();
$config = $this->senderObject->getConfig();
$queue = $this->senderObject->getQueue();

$data = [
'auth' => [
'acode' => $config['acode'],
'apiKey' => $config['apiKey'],
],
'smsInfo' => [
'requestID' => $config['requestID'],
'message' => $text,
'is_unicode' => $config['is_unicode'] ?? 0,
'masking' => $config['masking'],
'msisdn' => $number,
'transactionType' => $config['transactionType'] ?? 'T',
],
];

$requestObject = new Request('https://sms.lpeek.com/API/sendSMS', $data, $queue);
$requestObject->setContentTypeJson(true);
$response = $requestObject->post();
if ($queue) {
return true;
}

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

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

/**
* @throws ParameterException
*/
public function errorException()
{
if (!array_key_exists('acode', $this->senderObject->getConfig())) {
throw new ParameterException('acode is absent in configuration');
}

if (!array_key_exists('apiKey', $this->senderObject->getConfig())) {
throw new ParameterException('apiKey key is absent in configuration');
}
if (!array_key_exists('requestID', $this->senderObject->getConfig())) {
throw new ParameterException('requestID key is absent in configuration');
}
if (!array_key_exists('masking', $this->senderObject->getConfig())) {
throw new ParameterException('masking key is absent in configuration');
}
}

}

0 comments on commit 1f0f447

Please sign in to comment.