├── .gitignore ├── composer.json ├── config └── sslwsms.php ├── readme.md ├── src ├── AbstractApi.php ├── Facades │ └── Sms.php ├── HttpManager │ ├── RequestHandler.php │ └── Response.php ├── Sms.php └── SslWSmsServiceProvider.php └── tests └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | example 3 | composer.lock 4 | .DS_Store 5 | index.php 6 | .idea/ 7 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nahid/php-sslwireless-sms", 3 | "description": "PHP client for SSL Wireless SMS API", 4 | "keywords": ["SSL Wireless", "php", "api", "sms", "php-ssl-sms"], 5 | "type": "library", 6 | "require": { 7 | "php": ">=5.5.9", 8 | "guzzlehttp/guzzle": "^6.2", 9 | "ext-simplexml": "*" 10 | }, 11 | 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Nahid Bin Azhar", 16 | "email": "nahid.dns@gmail.com" 17 | } 18 | ], 19 | 20 | "autoload": { 21 | "psr-4": { 22 | "Nahid\\SslWSms\\": "src/" 23 | }, 24 | "files": [ 25 | ] 26 | }, 27 | "extra": { 28 | "laravel": { 29 | "providers": [ 30 | "Nahid\\SslWSms\\SslWSmsServiceProvider" 31 | ], 32 | "aliases": { 33 | "Sms": "Nahid\\SslWSms\\Facades\\Sms" 34 | } 35 | } 36 | }, 37 | 38 | "minimum-stability": "dev", 39 | "prefer-stable": false 40 | } 41 | -------------------------------------------------------------------------------- /config/sslwsms.php: -------------------------------------------------------------------------------- 1 | '', 5 | 'user' => '', 6 | 'password'=> '', 7 | 'url' => '', 8 | ]; 9 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # PHP SSL-Wirless SMS client 2 | 3 | php-sslwireless-sms is a PHP client for SSL Wirless SMS API. Its just a magic to sending SMS trough this client. This package is also support Laravel. 4 | 5 | ## Installation 6 | 7 | Goto terminal and run this command 8 | 9 | ```shell 10 | composer require nahid/php-sslwireless-sms 11 | ``` 12 | 13 | Wait for few minutes. Composer will automatically install this package for your project. 14 | 15 | ### For Laravel 16 | 17 | Open `config/app` and add this line in `providers` section 18 | 19 | ```php 20 | Nahid\SslWSms\SslWSmsServiceProvider::class, 21 | ``` 22 | 23 | For Facade support you have add this line in `aliases` section. 24 | 25 | ```php 26 | 'Sms' => Nahid\SslWSms\Facades\Sms::class, 27 | ``` 28 | 29 | Then run this command 30 | 31 | ```shell 32 | php artisan vendor:publish --provider="Nahid\SslWSms\SslWSmsServiceProvider" 33 | ``` 34 | 35 | 36 | ## Configuration 37 | 38 | This package is required three configurations. 39 | 40 | 1. sid = Which is given by SSL-Wirless. 41 | 2. user = your user id which is given by SSL-Wirless 42 | 3. password = your account password 43 | 44 | php-sslwireless-sms is take an array as config file. Lets services 45 | 46 | ```php 47 | use Nahid\SslWSms\Sms; 48 | 49 | $config = [ 50 | 'sid' => '', 51 | 'user' => '', 52 | 'password'=> '' 53 | ]; 54 | 55 | $sms = new Sms($config); 56 | ``` 57 | ### For Laravel 58 | 59 | This package is also support Laravel. For laravel you have to configure it as laravel style. 60 | 61 | Goto `app\sslwsms.php` and configure it with your credentials. 62 | 63 | ```php 64 | return [ 65 | 'sid' => '', 66 | 'user' => '', 67 | 'password'=> '' 68 | ]; 69 | ``` 70 | 71 | ## Usages 72 | 73 | Its very easy to use. This packages has a lot of functionalities and features. 74 | 75 | 76 | ### Send SMS to a single user 77 | 78 | ```php 79 | $sms = new Sms($config); 80 | $msg = $sms->message('0170420420', 'Hello Dear')->send(); 81 | 82 | if ($msg->parameter == 'ok' and $msg->login == 'successfull') { 83 | echo 'Messages Sent'; 84 | } 85 | ``` 86 | 87 | #### Laravel 88 | 89 | ```php 90 | use Nahid\SslWSms\Facades\Sms; 91 | 92 | $msg = Sms::message('0170420420', 'Hello Dear')->send(); 93 | 94 | if ($msg->parameter == 'ok' and $msg->login == 'successfull') { 95 | echo 'Messages Sent'; 96 | } 97 | ``` 98 | 99 | ### Send SMS to more user 100 | 101 | ```php 102 | $msg = $sms->message('0170420420', 'Hello Dear') 103 | ->message('0160420420', 'Hello Dear Uncle') 104 | ->message('0150420420', 'Hello Dear Trump') 105 | ->send(); 106 | 107 | if ($msg->parameter == 'ok' and $msg->login == 'successfull') { 108 | echo 'Messages Sent'; 109 | } 110 | ``` 111 | ### Send SMS to users from Collections 112 | 113 | ```php 114 | $users = [ 115 | ['01670420420', 'Hello Trump'], 116 | ['01970420420', 'Hello Bush'], 117 | ['01770420420', 'Hello Hilari'], 118 | ['01570420420', 'Hello Obama'], 119 | ['01870420420', 'Hello Hero Alom'] 120 | ] 121 | 122 | $msg = $sms->message($users)->send(); 123 | 124 | if ($msg->parameter == 'ok' and $msg->login == 'successfull') { 125 | echo 'Messages Sent'; 126 | } 127 | ``` 128 | 129 | ### Send same message to all users 130 | 131 | ```php 132 | $users = [ 133 | ['01670420420'], 134 | ['01970420420'], 135 | ['01770420420'], 136 | ['01570420420'], 137 | ['01870420420'] 138 | ] 139 | 140 | $msg = $sms->message($users, 'Hello Everyone')->send(); 141 | 142 | if ($msg->parameter == 'ok' and $msg->login == 'successfull') { 143 | echo 'Messages Sent'; 144 | } 145 | ``` 146 | 147 | 148 | ### Send SMS with SMS template 149 | 150 | Suppose you have to send SMS to multiple users but you want to mentions their name dynamically with message. So what can you do? Ha ha this package already handle this situations. Lets see 151 | 152 | ```php 153 | $users = [ 154 | ['01670420420', ['Nahid', '1234']], 155 | ['01970420420', ['Obi', '3213']], 156 | ['01770420420', ['Shipu', '5000']], 157 | ['01570420420', ['Kaiser', '3214']], 158 | ['01870420420', ['Eather', '7642']] 159 | ] 160 | 161 | $msg = $sms->message($users, "Hello %s , Your promo code is: %s")->send(); 162 | 163 | if ($msg->parameter == 'ok' and $msg->login == 'successfull') { 164 | echo 'Messages Sent'; 165 | } 166 | ``` 167 | 168 | Here this messege will sent as every users with his name and promo code like: 169 | 170 | - `01670420420` - Hello Nahid , Your promo code is: 1234 171 | - `01970420420` - Hello Obi , Your promo code is: 3213 172 | - `01770420420` - Hello Shipu , Your promo code is: 5000 173 | - `01570420420` - Hello Kaiser , Your promo code is: 1234 174 | - `01870420420` - Hello Eather , Your promo code is: 7642 175 | 176 | Thats it. 177 | 178 | Thank you :) 179 | -------------------------------------------------------------------------------- /src/AbstractApi.php: -------------------------------------------------------------------------------- 1 | client = new RequestHandler(isset($config['url']) ? $config['url'] : null); 27 | } 28 | 29 | public function __call($func, $params) 30 | { 31 | $method = strtoupper($func); 32 | 33 | if (in_array($method, $this->requestMethods)) { 34 | $parameters[] = $method; 35 | $parameters[] = $params[0]; 36 | 37 | return call_user_func_array([$this, 'makeMethodRequest'], $parameters); 38 | } 39 | } 40 | 41 | public function formParams($params = array()) 42 | { 43 | if (is_array($params)) { 44 | $this->parameters['form_params'] = $params; 45 | 46 | return $this; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | public function headers($params = array()) 53 | { 54 | if (is_array($params)) { 55 | $this->parameters['headers'] = $params; 56 | 57 | return $this; 58 | } 59 | 60 | return false; 61 | } 62 | 63 | public function query($params = array()) 64 | { 65 | if (is_array($params)) { 66 | $this->parameters['query'] = $params; 67 | 68 | return $this; 69 | } 70 | 71 | return false; 72 | } 73 | 74 | public function makeMethodRequest($method, $uri) 75 | { 76 | $this->parameters['timeout'] = 60; 77 | 78 | return new Response($this->client->http->request($method, $uri, $this->parameters)); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Facades/Sms.php: -------------------------------------------------------------------------------- 1 | http = new Client(['base_uri' => $baseUrl, 'timeout' => 2.0]); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/HttpManager/Response.php: -------------------------------------------------------------------------------- 1 | response = $response; 12 | } 13 | 14 | public function __call($method, $args) 15 | { 16 | if (method_exists($this->response, $method)) { 17 | return call_user_func_array([$this->response, $method], $args); 18 | } 19 | 20 | return false; 21 | } 22 | 23 | public function getData() 24 | { 25 | $header = explode(';', $this->response->getHeader('Content-Type')[0]); 26 | $contentType = $header[0]; 27 | 28 | if ($contentType == 'text/html') { 29 | $contents = $this->response->getBody()->getContents(); 30 | $xmlData = simplexml_load_string(strtolower($contents)); 31 | 32 | if ($xmlData == false) { 33 | return $contents; 34 | } 35 | 36 | return $xmlData; 37 | } 38 | 39 | return null; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Sms.php: -------------------------------------------------------------------------------- 1 | config = $config; 14 | parent::__construct($config); 15 | } 16 | 17 | public function message($to, $message = null) 18 | { 19 | if (is_array($to) && is_null($message)) { 20 | $this->sms = $this->makeSerializeSmsFormat($to); 21 | } elseif (is_array($to) && is_string($message)) { 22 | $this->sms = $this->makeSmsMultiUser($to, $message); 23 | } else { 24 | $this->sms[] = [$to, $message, uniqid()]; 25 | } 26 | 27 | return $this; 28 | } 29 | 30 | public function send() 31 | { 32 | $params = [ 33 | 'sid' => $this->config['sid'], 34 | 'user' => $this->config['user'], 35 | 'pass' => $this->config['password'], 36 | 'sms' => $this->sms, 37 | ]; 38 | 39 | return $this->formParams($params) 40 | ->headers(['Accept' => 'text/html']) 41 | ->post('pushapi/dynamic/server.php'); 42 | } 43 | 44 | protected function makeSerializeSmsFormat($messages) 45 | { 46 | $sms = []; 47 | foreach ($messages as $message) { 48 | $sms[] = [$message[0], $message[1], uniqid()]; 49 | } 50 | 51 | return $sms; 52 | } 53 | 54 | protected function makeSmsMultiUser($to, $message) 55 | { 56 | $sms = []; 57 | foreach ($to as $user) { 58 | $template = isset($user[1]) && is_array($user[1]) ? $user[1] : []; 59 | $sms[] = [$user[0], vsprintf($message, $template), uniqid()]; 60 | } 61 | 62 | return $sms; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/SslWSmsServiceProvider.php: -------------------------------------------------------------------------------- 1 | setupConfig(); 18 | } 19 | /** 20 | * Register the application services. 21 | */ 22 | public function register() 23 | { 24 | $this->registerSslWSms(); 25 | } 26 | /** 27 | * Setup the config. 28 | */ 29 | protected function setupConfig() 30 | { 31 | $source = realpath(__DIR__.'/../config/sslwsms.php'); 32 | // Check if the application is a Laravel OR Lumen instance to properly merge the configuration file. 33 | if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { 34 | $this->publishes([$source => config_path('sslwsms.php')]); 35 | } elseif ($this->app instanceof LumenApplication) { 36 | $this->app->configure('sslwsms'); 37 | } 38 | $this->mergeConfigFrom($source, 'sslwsms'); 39 | } 40 | /** 41 | * Register Talk class. 42 | */ 43 | protected function registerSslWSms() 44 | { 45 | $this->app->bind('sms', function (Container $app) { 46 | return new Sms($app['config']->get('sslwsms')); 47 | }); 48 | $this->app->alias('sms', Sms::class); 49 | } 50 | /** 51 | * Get the services provided by the provider. 52 | * 53 | * @return string[] 54 | */ 55 | public function provides() 56 | { 57 | return [ 58 | 'sms' 59 | ]; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nahid/php-sslwireless-sms/3bd91398c03a52f5e8a2c020393a0e121f730437/tests/.gitkeep --------------------------------------------------------------------------------