@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $from = $this->from; |
124 | 124 | $to = $numbers; |
125 | 125 | $input_data = $this->data; |
126 | - $url = $this->url."?username=" . $username . "&password=" . urlencode($password) . "&from=$from&to=" . json_encode($to) . "&input_data=" . urlencode(json_encode($input_data)) . "&pattern_code=$pattern_code"; |
|
126 | + $url = $this->url."?username=".$username."&password=".urlencode($password)."&from=$from&to=".json_encode($to)."&input_data=".urlencode(json_encode($input_data))."&pattern_code=$pattern_code"; |
|
127 | 127 | $handler = curl_init($url); |
128 | 128 | curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST"); |
129 | 129 | curl_setopt($handler, CURLOPT_POSTFIELDS, $input_data); |
@@ -139,12 +139,11 @@ discard block |
||
139 | 139 | public function message($text) |
140 | 140 | { |
141 | 141 | |
142 | - $this->url = config('sms.drivers.'.$this->drive.'.urlNormal'); |
|
142 | + $this->url = config('sms.drivers.'.$this->drive.'.urlNormal'); |
|
143 | 143 | |
144 | 144 | $rcpt_nm = $this->numbers; |
145 | - $param = array |
|
146 | - ( |
|
147 | - 'uname'=> $this->username , |
|
145 | + $param = array( |
|
146 | + 'uname'=> $this->username, |
|
148 | 147 | 'pass'=> $this->password, |
149 | 148 | 'from'=>$this->from, |
150 | 149 | 'message'=>$text, |
@@ -48,10 +48,11 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function send() |
50 | 50 | { |
51 | - if ($this->method == 'pattern') |
|
52 | - $res = $this->sendPattern(); |
|
53 | - else |
|
54 | - $res = $this->message($this->text); |
|
51 | + if ($this->method == 'pattern') { |
|
52 | + $res = $this->sendPattern(); |
|
53 | + } else { |
|
54 | + $res = $this->message($this->text); |
|
55 | + } |
|
55 | 56 | return $res; |
56 | 57 | } |
57 | 58 | |
@@ -73,8 +74,9 @@ discard block |
||
73 | 74 | public function pattern($pattern_code = null) |
74 | 75 | { |
75 | 76 | $this->method = 'pattern'; |
76 | - if ($pattern_code) |
|
77 | - $this->pattern_code = $pattern_code; |
|
77 | + if ($pattern_code) { |
|
78 | + $this->pattern_code = $pattern_code; |
|
79 | + } |
|
78 | 80 | return $this; |
79 | 81 | } |
80 | 82 |
@@ -10,11 +10,11 @@ |
||
10 | 10 | { |
11 | 11 | public function register() |
12 | 12 | { |
13 | - $this->app->singleton('sms',function (){ |
|
13 | + $this->app->singleton('sms', function() { |
|
14 | 14 | return new SmsService(); |
15 | 15 | }); |
16 | 16 | |
17 | - $this->mergeConfigFrom(__DIR__.'/config/sms.php','sms'); |
|
17 | + $this->mergeConfigFrom(__DIR__.'/config/sms.php', 'sms'); |
|
18 | 18 | |
19 | 19 | } |
20 | 20 |
@@ -67,7 +67,7 @@ |
||
67 | 67 | { |
68 | 68 | $class = new $this->class; |
69 | 69 | |
70 | - return call_user_func_array(array($class,$key),$params); |
|
70 | + return call_user_func_array(array($class,$key),$params); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | } |
@@ -5,11 +5,11 @@ discard block |
||
5 | 5 | class SmsService |
6 | 6 | { |
7 | 7 | |
8 | - protected $driver ; |
|
8 | + protected $driver; |
|
9 | 9 | |
10 | - protected $mode ; |
|
10 | + protected $mode; |
|
11 | 11 | |
12 | - protected $class ; |
|
12 | + protected $class; |
|
13 | 13 | |
14 | 14 | |
15 | 15 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function driver($key) |
31 | 31 | { |
32 | - $this->driver = $key ; |
|
32 | + $this->driver = $key; |
|
33 | 33 | |
34 | 34 | $this->class = config('sms.map.'.$this->driver); |
35 | 35 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function text($text) |
44 | 44 | { |
45 | - $drive = $this->drive('text',[$text]); |
|
45 | + $drive = $this->drive('text', [$text]); |
|
46 | 46 | |
47 | 47 | return $drive; |
48 | 48 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function pattern($code = null) |
55 | 55 | { |
56 | - $drive = $this->drive('pattern',[$code]); |
|
56 | + $drive = $this->drive('pattern', [$code]); |
|
57 | 57 | |
58 | 58 | return $drive; |
59 | 59 | } |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | * @param array $params |
64 | 64 | * @return mixed |
65 | 65 | */ |
66 | - public function drive($key,$params = []) |
|
66 | + public function drive($key, $params = []) |
|
67 | 67 | { |
68 | 68 | $class = new $this->class; |
69 | 69 | |
70 | - return call_user_func_array(array($class,$key),$params); |
|
70 | + return call_user_func_array(array($class, $key), $params); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $from = $this->from; |
124 | 124 | $to = $numbers; |
125 | 125 | $input_data = $this->data; |
126 | - $url = $this->url."?username=" . $username . "&password=" . urlencode($password) . "&from=$from&to=" . json_encode($to) . "&input_data=" . urlencode(json_encode($input_data)) . "&pattern_code=$pattern_code"; |
|
126 | + $url = $this->url."?username=".$username."&password=".urlencode($password)."&from=$from&to=".json_encode($to)."&input_data=".urlencode(json_encode($input_data))."&pattern_code=$pattern_code"; |
|
127 | 127 | $handler = curl_init($url); |
128 | 128 | curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST"); |
129 | 129 | curl_setopt($handler, CURLOPT_POSTFIELDS, $input_data); |
@@ -139,12 +139,11 @@ discard block |
||
139 | 139 | public function message($text) |
140 | 140 | { |
141 | 141 | |
142 | - $this->url = config('sms.drivers.'.$this->drive.'.urlNormal'); |
|
142 | + $this->url = config('sms.drivers.'.$this->drive.'.urlNormal'); |
|
143 | 143 | |
144 | 144 | $rcpt_nm = $this->numbers; |
145 | - $param = array |
|
146 | - ( |
|
147 | - 'uname'=> $this->username , |
|
145 | + $param = array( |
|
146 | + 'uname'=> $this->username, |
|
148 | 147 | 'pass'=> $this->password, |
149 | 148 | 'from'=>$this->from, |
150 | 149 | 'message'=>$text, |
@@ -48,10 +48,11 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function send() |
50 | 50 | { |
51 | - if ($this->method == 'pattern') |
|
52 | - $res = $this->sendPattern(); |
|
53 | - else |
|
54 | - $res = $this->message($this->text); |
|
51 | + if ($this->method == 'pattern') { |
|
52 | + $res = $this->sendPattern(); |
|
53 | + } else { |
|
54 | + $res = $this->message($this->text); |
|
55 | + } |
|
55 | 56 | return $res; |
56 | 57 | } |
57 | 58 | |
@@ -73,8 +74,9 @@ discard block |
||
73 | 74 | public function pattern($pattern_code = null) |
74 | 75 | { |
75 | 76 | $this->method = 'pattern'; |
76 | - if ($pattern_code) |
|
77 | - $this->pattern_code = $pattern_code; |
|
77 | + if ($pattern_code) { |
|
78 | + $this->pattern_code = $pattern_code; |
|
79 | + } |
|
78 | 80 | return $this; |
79 | 81 | } |
80 | 82 |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $token = $this->token ?? $this->password; |
127 | 127 | $url = $this->url.'/'.$token.'/verify/lookup.json'; |
128 | 128 | $url .= '?receptor='.$this->numbers[0]; |
129 | - foreach ($this->data as $patternKey => $patternValue ){ |
|
129 | + foreach ($this->data as $patternKey => $patternValue) { |
|
130 | 130 | $url .= '&'.$patternKey.'='.$patternValue; |
131 | 131 | } |
132 | 132 | $url .= '&template='.$this->pattern_code; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | { |
143 | 143 | $token = $this->token ?? $this->password; |
144 | 144 | $url = $this->url.'/'.$token.'/sms/send.json'; |
145 | - $url .= '?receptor='.implode(",",$this->numbers); |
|
145 | + $url .= '?receptor='.implode(",", $this->numbers); |
|
146 | 146 | $url .= '&sender='.$this->from; |
147 | 147 | $url .= '&message='.$text; |
148 | 148 | $response = Http::get($url)->body(); |
@@ -48,10 +48,11 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function send() |
50 | 50 | { |
51 | - if ($this->method == 'pattern') |
|
52 | - $res = $this->sendPattern(); |
|
53 | - else |
|
54 | - $res = $this->message($this->text); |
|
51 | + if ($this->method == 'pattern') { |
|
52 | + $res = $this->sendPattern(); |
|
53 | + } else { |
|
54 | + $res = $this->message($this->text); |
|
55 | + } |
|
55 | 56 | return $res; |
56 | 57 | } |
57 | 58 | |
@@ -73,8 +74,9 @@ discard block |
||
73 | 74 | public function pattern($pattern_code = null) |
74 | 75 | { |
75 | 76 | $this->method = 'pattern'; |
76 | - if ($pattern_code) |
|
77 | - $this->pattern_code = $pattern_code; |
|
77 | + if ($pattern_code) { |
|
78 | + $this->pattern_code = $pattern_code; |
|
79 | + } |
|
78 | 80 | return $this; |
79 | 81 | } |
80 | 82 |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct() |
41 | 41 | { |
42 | - $this->username = config('sms.drivers.' . $this->drive . '.username'); |
|
43 | - $this->password = config('sms.drivers.' . $this->drive . '.password'); |
|
44 | - $this->from = config('sms.drivers.' . $this->drive . '.from'); |
|
45 | - $this->url = config('sms.drivers.' . $this->drive . '.urlPattern'); |
|
42 | + $this->username = config('sms.drivers.'.$this->drive.'.username'); |
|
43 | + $this->password = config('sms.drivers.'.$this->drive.'.password'); |
|
44 | + $this->from = config('sms.drivers.'.$this->drive.'.from'); |
|
45 | + $this->url = config('sms.drivers.'.$this->drive.'.urlPattern'); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -208,8 +208,7 @@ discard block |
||
208 | 208 | { |
209 | 209 | $inputs = $this->setMessageExceptions(); |
210 | 210 | |
211 | - $param = array |
|
212 | - ( |
|
211 | + $param = array( |
|
213 | 212 | 'lineNumber' => $this->from, |
214 | 213 | 'MessageText' => $text, |
215 | 214 | 'Mobiles' => json_encode($inputs['numbers']), |
@@ -230,11 +229,11 @@ discard block |
||
230 | 229 | |
231 | 230 | private function setMessageExceptions() |
232 | 231 | { |
233 | - $apiKey = config('sms.drivers.' . $this->drive . '.apiKey'); |
|
232 | + $apiKey = config('sms.drivers.'.$this->drive.'.apiKey'); |
|
234 | 233 | if ($apiKey == '') |
235 | 234 | throw new \Exception('The apiKey of SMS.ir muse be set in config'); |
236 | 235 | |
237 | - $this->url = config('sms.drivers.' . $this->drive . '.urlNormal'); |
|
236 | + $this->url = config('sms.drivers.'.$this->drive.'.urlNormal'); |
|
238 | 237 | if ($this->url == '') |
239 | 238 | throw new \Exception('The url of SMS.ir muse be set in config'); |
240 | 239 |
@@ -50,10 +50,11 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function send() |
52 | 52 | { |
53 | - if ($this->method == 'pattern') |
|
54 | - $res = $this->sendPattern(); |
|
55 | - else |
|
56 | - $res = $this->message($this->text); |
|
53 | + if ($this->method == 'pattern') { |
|
54 | + $res = $this->sendPattern(); |
|
55 | + } else { |
|
56 | + $res = $this->message($this->text); |
|
57 | + } |
|
57 | 58 | return $res; |
58 | 59 | } |
59 | 60 | |
@@ -75,8 +76,9 @@ discard block |
||
75 | 76 | public function pattern($pattern_code = null) |
76 | 77 | { |
77 | 78 | $this->method = 'pattern'; |
78 | - if ($pattern_code) |
|
79 | - $this->pattern_code = $pattern_code; |
|
79 | + if ($pattern_code) { |
|
80 | + $this->pattern_code = $pattern_code; |
|
81 | + } |
|
80 | 82 | return $this; |
81 | 83 | } |
82 | 84 | |
@@ -156,31 +158,38 @@ discard block |
||
156 | 158 | private function setPatternExceptions() |
157 | 159 | { |
158 | 160 | $parameters = $this->data; |
159 | - if (is_null($parameters)) |
|
160 | - throw new \Exception('The data must be set'); |
|
161 | - elseif (count($parameters) > 1) |
|
162 | - throw new \Exception('The data must have just one OTP code'); |
|
161 | + if (is_null($parameters)) { |
|
162 | + throw new \Exception('The data must be set'); |
|
163 | + } elseif (count($parameters) > 1) { |
|
164 | + throw new \Exception('The data must have just one OTP code'); |
|
165 | + } |
|
163 | 166 | |
164 | 167 | $mobile = $this->numbers; |
165 | - if ($mobile = []) |
|
166 | - throw new \Exception('The mobile number must be set'); |
|
167 | - if (count($mobile) > 1) |
|
168 | - throw new \Exception('The OTP code must send to just one mobile number'); |
|
168 | + if ($mobile = []) { |
|
169 | + throw new \Exception('The mobile number must be set'); |
|
170 | + } |
|
171 | + if (count($mobile) > 1) { |
|
172 | + throw new \Exception('The OTP code must send to just one mobile number'); |
|
173 | + } |
|
169 | 174 | |
170 | 175 | $templateId = $this->templateId; |
171 | - if (is_null($templateId)) |
|
172 | - throw new \Exception('The templateId must be set'); |
|
176 | + if (is_null($templateId)) { |
|
177 | + throw new \Exception('The templateId must be set'); |
|
178 | + } |
|
173 | 179 | |
174 | 180 | |
175 | - if (gettype($parameters[0]) != 'array') |
|
176 | - $checkParameter = $parameters[0]; |
|
177 | - else |
|
178 | - $checkParameter = $parameters; |
|
181 | + if (gettype($parameters[0]) != 'array') { |
|
182 | + $checkParameter = $parameters[0]; |
|
183 | + } else { |
|
184 | + $checkParameter = $parameters; |
|
185 | + } |
|
179 | 186 | |
180 | - if (!isset($checkParameter['name'])) |
|
181 | - throw new \Exception('The `name` parameter not defined in data'); |
|
182 | - if (!isset($checkParameter['value'])) |
|
183 | - throw new \Exception('The `value` parameter not defined in data'); |
|
187 | + if (!isset($checkParameter['name'])) { |
|
188 | + throw new \Exception('The `name` parameter not defined in data'); |
|
189 | + } |
|
190 | + if (!isset($checkParameter['value'])) { |
|
191 | + throw new \Exception('The `value` parameter not defined in data'); |
|
192 | + } |
|
184 | 193 | |
185 | 194 | return compact('parameters', 'mobile', 'templateId'); |
186 | 195 | } |
@@ -195,8 +204,9 @@ discard block |
||
195 | 204 | if (is_null($inputs['parameters'][0]['value'])) { |
196 | 205 | $inputs['parameters'][0]['value'] = rand(100000, 999999); |
197 | 206 | } |
198 | - } else |
|
199 | - $inputs['parameters'][0]['value'] = $pattern_code; |
|
207 | + } else { |
|
208 | + $inputs['parameters'][0]['value'] = $pattern_code; |
|
209 | + } |
|
200 | 210 | |
201 | 211 | } |
202 | 212 | |
@@ -231,19 +241,23 @@ discard block |
||
231 | 241 | private function setMessageExceptions() |
232 | 242 | { |
233 | 243 | $apiKey = config('sms.drivers.' . $this->drive . '.apiKey'); |
234 | - if ($apiKey == '') |
|
235 | - throw new \Exception('The apiKey of SMS.ir muse be set in config'); |
|
244 | + if ($apiKey == '') { |
|
245 | + throw new \Exception('The apiKey of SMS.ir muse be set in config'); |
|
246 | + } |
|
236 | 247 | |
237 | 248 | $this->url = config('sms.drivers.' . $this->drive . '.urlNormal'); |
238 | - if ($this->url == '') |
|
239 | - throw new \Exception('The url of SMS.ir muse be set in config'); |
|
249 | + if ($this->url == '') { |
|
250 | + throw new \Exception('The url of SMS.ir muse be set in config'); |
|
251 | + } |
|
240 | 252 | |
241 | 253 | $numbers = $this->numbers; |
242 | - if (count($numbers) < 1) |
|
243 | - throw new \Exception('The numbers of mobiles must be set'); |
|
254 | + if (count($numbers) < 1) { |
|
255 | + throw new \Exception('The numbers of mobiles must be set'); |
|
256 | + } |
|
244 | 257 | |
245 | - if ($this->from == '') |
|
246 | - throw new \Exception('The lineNumber of SMS.ir muse be set in config (set it in `from` key)'); |
|
258 | + if ($this->from == '') { |
|
259 | + throw new \Exception('The lineNumber of SMS.ir muse be set in config (set it in `from` key)'); |
|
260 | + } |
|
247 | 261 | |
248 | 262 | return compact('apiKey', 'numbers'); |
249 | 263 | } |