| @@ 8-74 (lines=67) @@ | ||
| 5 | use GuzzleHttp\Exception\ClientException; |
|
| 6 | use GuzzleHttp\Psr7\Request; |
|
| 7 | ||
| 8 | class KudiSms extends Sms |
|
| 9 | { |
|
| 10 | private $baseUrl = 'https://account.kudisms.net/'; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * Class Constructor. |
|
| 14 | * @param null $message |
|
| 15 | */ |
|
| 16 | public function __construct($message = null) |
|
| 17 | { |
|
| 18 | $this->username = config('laravel-sms.kudi_sms.username'); |
|
| 19 | $this->password = config('laravel-sms.kudi_sms.password'); |
|
| 20 | if ($message) { |
|
| 21 | $this->text($message); |
|
| 22 | } |
|
| 23 | $headers = [ |
|
| 24 | 'apiKey' => $this->username, |
|
| 25 | 'Content-Type' => 'application/x-www-form-urlencoded', |
|
| 26 | 'Accept' => 'application/json', |
|
| 27 | 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36 OPR/47.0.2631.39', |
|
| 28 | ]; |
|
| 29 | $this->client = self::getInstance(); |
|
| 30 | $this->request = new Request('GET', $this->baseUrl.'api/', $headers); |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * @param null $text |
|
| 35 | * @return bool |
|
| 36 | */ |
|
| 37 | public function send($text = null): bool |
|
| 38 | { |
|
| 39 | if ($text) { |
|
| 40 | $this->setText($text); |
|
| 41 | } |
|
| 42 | try { |
|
| 43 | $request = $this->client->send($this->request, [ |
|
| 44 | 'query' => [ |
|
| 45 | 'username' => $this->username, |
|
| 46 | 'password' => $this->password, |
|
| 47 | 'sender' => $this->sender ?? config('laravel-sms.sender'), |
|
| 48 | 'mobiles' => implode(',', $this->recipients), |
|
| 49 | 'message' => $this->text, |
|
| 50 | ], |
|
| 51 | ]); |
|
| 52 | ||
| 53 | $response = json_decode($request->getBody()->getContents(), true); |
|
| 54 | ||
| 55 | if (isset($response['status']) && $response['status'] == 'OK') { |
|
| 56 | return true; |
|
| 57 | } |
|
| 58 | ||
| 59 | $this->response = $response['error']; |
|
| 60 | ||
| 61 | return false; |
|
| 62 | } catch (ClientException $e) { |
|
| 63 | logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
| 64 | $this->httpError = $e; |
|
| 65 | ||
| 66 | return false; |
|
| 67 | } catch (\Exception $e) { |
|
| 68 | logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
| 69 | $this->httpError = $e; |
|
| 70 | ||
| 71 | return false; |
|
| 72 | } |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||
| @@ 8-75 (lines=68) @@ | ||
| 5 | use GuzzleHttp\Exception\ClientException; |
|
| 6 | use GuzzleHttp\Psr7\Request; |
|
| 7 | ||
| 8 | class NigerianBulkSms extends Sms |
|
| 9 | { |
|
| 10 | private $baseUrl = 'http://portal.nigeriabulksms.com/'; |
|
| 11 | ||
| 12 | /** |
|
| 13 | * Class Constructor. |
|
| 14 | * @param null $message |
|
| 15 | */ |
|
| 16 | public function __construct($message = null) |
|
| 17 | { |
|
| 18 | $this->username = config('laravel-sms.nigerian_bulk_sms.username'); |
|
| 19 | $this->password = config('laravel-sms.nigerian_bulk_sms.password'); |
|
| 20 | if ($message) { |
|
| 21 | $this->text($message); |
|
| 22 | } |
|
| 23 | $headers = [ |
|
| 24 | 'apiKey' => $this->username, |
|
| 25 | 'Content-Type' => 'application/x-www-form-urlencoded', |
|
| 26 | 'Accept' => 'application/json', |
|
| 27 | 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36 OPR/47.0.2631.39', |
|
| 28 | ]; |
|
| 29 | ||
| 30 | $this->client = self::getInstance(); |
|
| 31 | $this->request = new Request('GET', $this->baseUrl.'api', $headers); |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @param null $text |
|
| 36 | * @return bool |
|
| 37 | */ |
|
| 38 | public function send($text = null): bool |
|
| 39 | { |
|
| 40 | if ($text) { |
|
| 41 | $this->setText($text); |
|
| 42 | } |
|
| 43 | try { |
|
| 44 | $request = $this->client->send($this->request, [ |
|
| 45 | 'query' => [ |
|
| 46 | 'username' => $this->username, |
|
| 47 | 'password' => $this->password, |
|
| 48 | 'sender' => $this->sender ?? config('laravel-sms.sender'), |
|
| 49 | 'mobiles' => implode(',', $this->recipients), |
|
| 50 | 'message' => $this->text, |
|
| 51 | ], |
|
| 52 | ]); |
|
| 53 | ||
| 54 | $response = json_decode($request->getBody()->getContents(), true); |
|
| 55 | ||
| 56 | if (isset($response['status']) && $response['status'] == 'OK') { |
|
| 57 | return true; |
|
| 58 | } |
|
| 59 | ||
| 60 | $this->response = $response['error']; |
|
| 61 | ||
| 62 | return false; |
|
| 63 | } catch (ClientException $e) { |
|
| 64 | logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
| 65 | $this->httpError = $e; |
|
| 66 | ||
| 67 | return false; |
|
| 68 | } catch (\Exception $e) { |
|
| 69 | logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
| 70 | $this->httpError = $e; |
|
| 71 | ||
| 72 | return false; |
|
| 73 | } |
|
| 74 | } |
|
| 75 | } |
|
| 76 | ||