diff --git a/src/Provider/GreenWeb.php b/src/Provider/GreenWeb.php index a14b03e..9f99097 100644 --- a/src/Provider/GreenWeb.php +++ b/src/Provider/GreenWeb.php @@ -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, ''); @@ -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 @@ -79,4 +96,4 @@ public function errorException() throw new XenonException('token key is absent in configuration'); } -} \ No newline at end of file +} diff --git a/src/Provider/Mim.php b/src/Provider/Mim.php index f7a59fc..e231ae0 100644 --- a/src/Provider/Mim.php +++ b/src/Provider/Mim.php @@ -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); }