Skip to content

Commit

Permalink
Merge pull request #10 from rtraselbd/master
Browse files Browse the repository at this point in the history
I just updated few providers latest api.
  • Loading branch information
arif98741 authored Jan 11, 2024
2 parents 098dfbb + ceeaf8e commit 04b8297
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 34 deletions.
39 changes: 28 additions & 11 deletions src/Provider/BulkSmsBD.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public function __construct(Sender $sender)
*/
public function sendRequest(): array
{
$url = "http://66.45.237.70/api.php";
$number = $this->senderObject->getMobile();
$url = "https://bulksmsbd.net/api/smsapi";
$number = $this->formatNumber($this->senderObject->getMobile());
$text = $this->senderObject->getMessage();
$config = $this->senderObject->getConfig();

$data = array(
'username' => $config['username'],
'password' => $config['password'],
$data = [
'api_key' => $config['api_key'],
'senderid' => $config['senderid'],
'number' => $number,
'message' => $text
);
];
$ch = curl_init(); // Initialize cURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
Expand All @@ -43,6 +43,23 @@ public function sendRequest(): array
return $this->generateReport($smsResult, $data);
}

/**
* For mobile number
* @param $mobile
* @return string
*/
private function formatNumber($mobile): string
{
if (mb_substr($mobile, 0, 2) == '01') {
$number = $mobile;
} elseif (mb_substr($mobile, 0, 2) == '88') {
$number = str_replace('88', '', $mobile);
} elseif (mb_substr($mobile, 0, 3) == '+88') {
$number = str_replace('+88', '', $mobile);
}
return '88' . $number;
}

/**
* @throws XenonException
*/
Expand All @@ -51,11 +68,11 @@ public function errorException()
if (!is_array($this->senderObject->getConfig())) {
throw new XenonException('Configuration is not provided. Use setConfig() in method chain');
}
if (!array_key_exists('username', $this->senderObject->getConfig())) {
throw new XenonException('username key is absent in configuration');
if (!array_key_exists('api_key', $this->senderObject->getConfig())) {
throw new XenonException('api_key key is absent in configuration');
}
if (!array_key_exists('password', $this->senderObject->getConfig())) {
throw new XenonException('password key is absent in configuration');
if (!array_key_exists('senderid', $this->senderObject->getConfig())) {
throw new XenonException('senderid key is absent in configuration');
}
if (strlen($this->senderObject->getMobile()) > 11 || strlen($this->senderObject->getMobile()) < 11) {
throw new XenonException('Invalid mobile number. It should be 11 digit');
Expand All @@ -81,4 +98,4 @@ public function generateReport($result, $data): array
'message' => $data['message']
];
}
}
}
27 changes: 13 additions & 14 deletions src/Provider/Mim.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Xenon\Multisms\Provider;


use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;

Expand All @@ -23,19 +22,19 @@ public function __construct(Sender $sender)
*/
public function sendRequest(): array
{
$url = "https://mimsms.com.bd/smsAPI";
$url = "https://api.mimsms.com/api/SmsSending/SMS";
$number = $this->formatNumber($this->senderObject->getMobile());
$text = $this->senderObject->getMessage();
$config = $this->senderObject->getConfig();

$data = [
'sendsms' => '',
'apikey' => $config['apikey'],
'apitoken' => $config['apitoken'],
'from' => $config['senderid'],
'type' => 'sms',
'to' => $number,
'text' => $text
'sendsms' => '',
'Apikey' => $config['apikey'],
'UserName' => $config['apitoken'],
'SenderName' => $config['senderid'],
'TransactionType' => 'T',
'MobileNumber' => $number,
'Message' => $text,
];
$ch = curl_init(); // Initialize cURL
curl_setopt($ch, CURLOPT_URL, $url);
Expand All @@ -56,9 +55,9 @@ private function formatNumber($mobile): string
if (mb_substr($mobile, 0, 2) == '01') {
$number = $mobile;
} elseif (mb_substr($mobile, 0, 2) == '88') {
$number = mb_substr($mobile, 2);
$number = str_replace('88', '', $mobile);
} elseif (mb_substr($mobile, 0, 3) == '+88') {
$number = mb_substr($mobile, 3);
$number = str_replace('+88', '', $mobile);
}
return '88' . $number;
}
Expand Down Expand Up @@ -97,8 +96,8 @@ public function generateReport($result, $data): array
'response' => $result,
'provider' => self::class,
'send_time' => date('Y-m-d H:i:s'),
'mobile' => $data['to'],
'message' => $data['text']
'mobile' => $data['MobileNumber'],
'message' => $data['Message'],
];
}
}
}
116 changes: 116 additions & 0 deletions src/Provider/Smsq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php


namespace Xenon\Multisms\Provider;


use Xenon\Multisms\Handler\XenonException;
use Xenon\Multisms\Sender;

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

/**
* Send Request To Api and Send Message
*/
public function sendRequest(): array
{
$url = "https://api.smsq.global/api/v2/SendSMS";
$number = $this->formatNumber($this->senderObject->getMobile());
$text = $this->senderObject->getMessage();
$config = $this->senderObject->getConfig();

$data = [
'senderId' => $config['sender_id'],
'is_Unicode' => true,
'apiKey' => $config['api_key'],
'clientId' => $config['client_id'],
'mobileNumbers' => $number,
'message' => $text
];

$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"content-type: application/json"
],
]);
$smsResult = curl_exec($curl);
curl_close($curl);
return $this->generateReport($smsResult, $data);
}

/**
* For mobile number
* @param $mobile
* @return string
*/
private function formatNumber($mobile): string
{
if (mb_substr($mobile, 0, 2) == '01') {
$number = $mobile;
} elseif (mb_substr($mobile, 0, 2) == '88') {
$number = str_replace('88', '', $mobile);
} elseif (mb_substr($mobile, 0, 3) == '+88') {
$number = str_replace('+88', '', $mobile);
}
return '88' . $number;
}

/**
* @throws XenonException
*/
public function errorException()
{
if (!is_array($this->senderObject->getConfig())) {
throw new XenonException('Configuration is not provided. Use setConfig() in method chain');
}
if (!array_key_exists('sender_id', $this->senderObject->getConfig())) {
throw new XenonException('sender_id key is absent in configuration');
}
if (!array_key_exists('api_key', $this->senderObject->getConfig())) {
throw new XenonException('api_key key is absent in configuration');
}

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

if (strlen($this->senderObject->getMobile()) > 11 || strlen($this->senderObject->getMobile()) < 11) {
throw new XenonException('Invalid mobile number. It should be 11 digit');
}
if (empty($this->senderObject->getMessage())) {
throw new XenonException('Message should not be empty');
}
}

/**
* @param $result
* @param $data
* @return array
*/
public function generateReport($result, $data): array
{
return [
'status' => 'response',
'response' => $result,
'provider' => self::class,
'send_time' => date('Y-m-d H:i:s'),
'mobile' => $data['MobileNumbers'],
'message' => $data['Message']
];
}
}
36 changes: 27 additions & 9 deletions src/Provider/Ssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,49 @@ public function __construct(Sender $sender)
*/
public function sendRequest(): array
{
$mobile = $this->senderObject->getMobile();
$mobile = $this->formatNumber($this->senderObject->getMobile());
$config = $this->senderObject->getConfig();

$apiToken = $config['api_token'];
$sid = $config['sid'];
$csms_id = $config['csms_id'];

$data = [
'number' => $mobile,
'message' => $this->senderObject->getMessage()
'api_token' => $apiToken,
'sid' => $sid,
'msisdn' => $mobile,
'sms' => $this->senderObject->getMessage(),
'csms_id' => $csms_id
];

$message = $this->senderObject->getMessage();
$url = "https://smsplus.sslwireless.com/api/v3/send-sms?api_token=$apiToken&sid=$sid&sms=$message&msisdn=$mobile&csms_id=$csms_id";
$url = "https://smsplus.sslwireless.com/api/v3/send-sms";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$smsResult = curl_exec($ch);
if ($smsResult == false) {
$smsResult = curl_error($ch);
}
curl_close($ch);
return $this->generateReport($smsResult, $data);
}

/**
* For mobile number
* @param $mobile
* @return string
*/
private function formatNumber($mobile): string
{
if (mb_substr($mobile, 0, 2) == '01') {
$number = $mobile;
} elseif (mb_substr($mobile, 0, 2) == '88') {
$number = str_replace('88', '', $mobile);
} elseif (mb_substr($mobile, 0, 3) == '+88') {
$number = str_replace('+88', '', $mobile);
}
return '88' . $number;
}

/**
Expand All @@ -71,7 +90,6 @@ public function errorException()

if (empty($this->senderObject->getMessage()))
throw new XenonException('Message should not be empty');

}

/**
Expand All @@ -86,8 +104,8 @@ public function generateReport($result, $data): array
'response' => $result,
'provider' => self::class,
'send_time' => date('Y-m-d H:i:s'),
'mobile' => $data['number'],
'message' => $data['message']
'mobile' => $data['msisdn'],
'message' => $data['sms']
];
}
}
}

0 comments on commit 04b8297

Please sign in to comment.