|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Last Modified: 6/29/21, 12:06 AM |
| 4 | + * Copyright (c) 2021 |
| 5 | + * -created by Ariful Islam |
| 6 | + * -All Rights Preserved By |
| 7 | + * -If you have any query then knock me at |
| 8 | + * arif98741@gmail.com |
| 9 | + * See my profile @ https://github.com/arif98741 |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Xenon\LaravelBDSms\Provider; |
| 13 | + |
| 14 | +use GuzzleHttp\Client; |
| 15 | +use GuzzleHttp\Exception\GuzzleException; |
| 16 | +use Xenon\LaravelBDSms\Handler\ParameterException; |
| 17 | +use Xenon\LaravelBDSms\Sender; |
| 18 | + |
| 19 | +class TwentyFourSmsBD extends AbstractProvider |
| 20 | +{ |
| 21 | + /** |
| 22 | + * TwenforSmsBD constructor. |
| 23 | + * @param Sender $sender |
| 24 | + */ |
| 25 | + public function __construct(Sender $sender) |
| 26 | + { |
| 27 | + $this->senderObject = $sender; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Send Request To Api and Send Message |
| 32 | + * @throws GuzzleException |
| 33 | + */ |
| 34 | + public function sendRequest() |
| 35 | + { |
| 36 | + $number = $this->senderObject->getMobile(); |
| 37 | + $text = $this->senderObject->getMessage(); |
| 38 | + $config = $this->senderObject->getConfig(); |
| 39 | + |
| 40 | + $client = new Client([ |
| 41 | + 'base_uri' => 'https://24smsbd.com/api/bulkSmsApi', |
| 42 | + 'timeout' => 10.0, |
| 43 | + 'verify' => false, |
| 44 | + ]); |
| 45 | + |
| 46 | + |
| 47 | + $response = $client->request('POST', '', [ |
| 48 | + 'query' => [ |
| 49 | + 'apiKey' => $config['apiKey'], |
| 50 | + 'sender_id' => $config['sender_id'], |
| 51 | + 'mobileNo' => $number, |
| 52 | + 'message' => $text, |
| 53 | + ] |
| 54 | + ]); |
| 55 | + |
| 56 | + $body = $response->getBody(); |
| 57 | + $smsResult = $body->getContents(); |
| 58 | + |
| 59 | + $data['number'] = $number; |
| 60 | + $data['message'] = $text; |
| 61 | + $report = $this->generateReport($smsResult, $data); |
| 62 | + return $report->getContent(); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @throws ParameterException |
| 67 | + */ |
| 68 | + public function errorException() |
| 69 | + { |
| 70 | + if (!array_key_exists('apiKey', $this->senderObject->getConfig())) { |
| 71 | + throw new ParameterException('apiKey key is absent in configuration'); |
| 72 | + } |
| 73 | + |
| 74 | + if (!array_key_exists('sender_id', $this->senderObject->getConfig())) { |
| 75 | + throw new ParameterException('sender_id key is absent in configuration'); |
| 76 | + } |
| 77 | + |
| 78 | + } |
| 79 | +} |
0 commit comments