diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 1d601d7..0b67a11 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -24,6 +24,8 @@ Please follow this steps and you are live with in a mere seconds. Depending on driver option you choose, add these API credentials after existing general configuration variables. +### Global SMS API Providers + | Driver | Credentials | Region | Configured | Tested | |-------------------|-------------------------------------------------------------------------|:------:|:------------------:|:------:| | `africastalking` | `SMS_AFRICA_TALKING_API_KEY=null`
`SMS_AFRICA_TALKING_USERNAME=null` | GLOBAL | :white_check_mark: | :x: | @@ -34,7 +36,14 @@ after existing general configuration variables. | `smsbroadcast` | `SMS_SMSBROADCAST_USERNAME=null`
`SMS_SMSBROADCAST_PASSWORD=null` | GLOBAL | :white_check_mark: | :x: | | `telnyx` | `SMS_TELNYX_API_TOKEN=null` | GLOBAL | :white_check_mark: | :x: | | `twilio` | `SMS_TWILIO_USERNAME=null`
`SMS_TWILIO_PASSWORD=null` | GLOBAL | :white_check_mark: | :x: | -| `adn` | `SMS_TWILIO_USERNAME=null`
`SMS_TWILIO_PASSWORD=null` | BAN | :x: | :x: | +| `smsapi` | `SMS_SMSAPI_API_TOKEN=null` | GLOBAL | :white_check_mark: | :x: | + + +### Bangladesh only SMS API Providers + +| Driver | Credentials | Region | Configured | Tested | +|-------------------|-------------------------------------------------------------------------|:------:|:------------------:|:------:| +| `adn` | `SMS_ADN_API_KEY=null`
`SMS_ADN_API_SECRET=null` | BAN | :white_check_mark: | :x: | | `ajuratech` | `SMS_TWILIO_USERNAME=null`
`SMS_TWILIO_PASSWORD=null` | BAN | :x: | :x: | | `alpha` | `SMS_TWILIO_USERNAME=null`
`SMS_TWILIO_PASSWORD=null` | BAN | :x: | :x: | | `banglalink` | `SMS_TWILIO_USERNAME=null`
`SMS_TWILIO_PASSWORD=null` | BAN | :x: | :x: | diff --git a/config/sms.php b/config/sms.php index b9c97b5..8560c95 100644 --- a/config/sms.php +++ b/config/sms.php @@ -138,22 +138,25 @@ 'password' => env('SMS_TWILIO_PASSWORD'), ], ], + Providers::SMS_API => [ + 'driver' => \Laraflow\Sms\Drivers\SmsApi::class, + 'live' => [ + 'api_token' => env('SMS_SMSAPI_API_TOKEN', ''), + ], + 'sandbox' => [ + 'api_token' => env('SMS_SMSAPI_API_TOKEN', ''), + ], + ], //Bangladesh Providers::ADN => [ 'driver' => \Laraflow\Sms\Drivers\Adn::class, 'live' => [ - 'senderid' => env('SMS_ADN_SENDER_ID', ''), 'api_key' => env('SMS_ADN_API_KEY', ''), - 'api_secret' => env('SMS_ADN_API_SECRET', ''), - 'request_type' => env('SMS_ADN_API_REQUEST_TYPE', ''), - 'message_type' => env('SMS_ADN_API_MESSAGE_TYPE', ''), + 'api_secret' => env('SMS_ADN_API_SECRET', '') ], 'sandbox' => [ - 'senderid' => env('SMS_ADN_SENDER_ID', ''), 'api_key' => env('SMS_ADN_API_KEY', ''), - 'api_secret' => env('SMS_ADN_API_SECRET', ''), - 'request_type' => env('SMS_ADN_API_REQUEST_TYPE', ''), - 'message_type' => env('SMS_ADN_API_MESSAGE_TYPE', ''), + 'api_secret' => env('SMS_ADN_API_SECRET', '') ] ], Providers::AJURA_TECH => [ diff --git a/src/Drivers/Adn.php b/src/Drivers/Adn.php index c8ce4e8..15abb16 100644 --- a/src/Drivers/Adn.php +++ b/src/Drivers/Adn.php @@ -8,7 +8,7 @@ use Laraflow\Sms\SmsMessage; /** - * @reference + * @reference https://portal.adnsms.com/client/api/documentation */ class Adn extends SmsDriver { @@ -22,6 +22,8 @@ protected function mergeConfig(): array { return [ 'url' => 'https://portal.adnsms.com/api/v1/secure/send-sms', + 'request_type' => 'SINGLE_SMS', + 'message_type' => 'UNICODE' ]; } @@ -34,8 +36,8 @@ public function rules(): array { return [ 'url' => 'required|url:http,https', - 'apiKey' => 'required|string', - 'username' => 'required|string', + 'api_key' => 'required|string', + 'api_secret' => 'required|string' ]; } @@ -48,20 +50,20 @@ public function rules(): array public function send(SmsMessage $message): Response { $this->payload = [ - 'username' => $this->config['username'], - 'to' => $message->getReceiver(), - 'from' => $message->getSender(), - 'message' => $message->getContent(), + 'api_key' => $this->config['api_key'], + 'api_secret' => $this->config['api_secret'], + 'request_type' => $this->config['request_type'], + 'message_type' => $this->config['message_type'], + 'mobile' => $message->getReceiver(), + 'message_body' => $message->getContent(), ]; $this->removeEmptyParams(); return Http::withoutVerifying() ->timeout(30) - ->withHeader('Content-Type', 'application/json') - ->withHeader('Accept', 'application/json') - ->withHeader('apiKey', $this->config['apiKey']) - ->get($this->config['url'], $this->payload); + ->withHeaders(['Content-Type'=>'application/json','Accept'=>'application/json']) + ->post($this->config['url'], $this->payload); } } diff --git a/src/Drivers/SmsApi.php b/src/Drivers/SmsApi.php new file mode 100644 index 0000000..e1ef25c --- /dev/null +++ b/src/Drivers/SmsApi.php @@ -0,0 +1,66 @@ + 'https://api.smsapi.com/sms.do', + 'format' =>'json' + ]; + } + + /** + * Return validation rules for + * that sms driver to operate. + */ + public function rules(): array + { + return [ + 'url' => 'required|url:http,https', + 'api_token' => 'required|string' + ]; + } + + /** + * Execute the sms sending request to api provider + * + * @param SmsMessage $message + * @return Response + */ + public function send(SmsMessage $message): Response + { + $this->payload = [ + 'to' => $message->getReceiver(), + 'from' => $message->getSender(), + 'message' => $message->getContent(), + 'format' => $this->config['format'] + ]; + + $this->removeEmptyParams(); + + return Http::withoutVerifying() + ->timeout(30) + ->withToken($this->config['api_token']) + ->withHeader('Content-Type', 'application/json') + ->withHeader('Accept', 'application/json') + ->post($this->config['url'], $this->payload); + + } +} diff --git a/src/Providers.php b/src/Providers.php index 4f3f4d6..b5a61da 100644 --- a/src/Providers.php +++ b/src/Providers.php @@ -48,6 +48,7 @@ class Providers public const SMSINBD = 'smsinbd'; public const SMSNETBD = 'smsnetbd'; public const SMSQ = 'smsq'; + public const SMS_API = 'smsapi'; public const SSL = 'ssl'; public const TENSE = 'tense'; public const TRUBO_SMS = 'trubosms';