Skip to content

Commit

Permalink
Merge pull request #11 from rtraselbd/master
Browse files Browse the repository at this point in the history
Update Mim SMS API Params & Formated GreenWeb Number
  • Loading branch information
arif98741 authored Jul 1, 2024
2 parents 04b8297 + c62d9e2 commit 42cef94
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
31 changes: 24 additions & 7 deletions src/Provider/GreenWeb.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ public function __construct(Sender $sender)
*/
public function sendRequest()
{
$to = $this->senderObject->getMobile();
$to = $this->formatNumber($this->senderObject->getMobile());
$config = $this->senderObject->getConfig();
$token = $config['token'];
$message = $this->senderObject->getMessage();

$url = "https://api.greenweb.com.bd/api.php?json";

$data = array(
'to' => "$to",
'message' => "$message",
'token' => "$token"
);
$data = [
'to' => $to,
'message' => $message,
'token' => $token
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_ENCODING, '');
Expand All @@ -50,6 +50,23 @@ public function sendRequest()
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;
}

/**
* @param $result
* @param $data
Expand Down Expand Up @@ -79,4 +96,4 @@ public function errorException()
throw new XenonException('token key is absent in configuration');

}
}
}
27 changes: 17 additions & 10 deletions src/Provider/Mim.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,28 @@ public function sendRequest(): array
$number = $this->formatNumber($this->senderObject->getMobile());
$text = $this->senderObject->getMessage();
$config = $this->senderObject->getConfig();

$data = [
'sendsms' => '',
'Apikey' => $config['apikey'],
'UserName' => $config['apitoken'],
'SenderName' => $config['senderid'],
'UserName' => $config['username'],
'Apikey' => $config['apikey'],
'MobileNumber' => $number,
'SenderName' => $config['senderid'],
'TransactionType' => 'T',
'MobileNumber' => $number,
'Message' => $text,
'Message' => $text
];
$ch = curl_init(); // Initialize cURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

$payload = json_encode($data);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$smsResult = curl_exec($ch);

curl_close($ch);
return $this->generateReport($smsResult, $data);
}
Expand Down

0 comments on commit 42cef94

Please sign in to comment.