|
8 | 8 | class ParsaSms extends AdapterAbstract implements AdapterInterface |
9 | 9 | { |
10 | 10 | private $credential = [ |
11 | | - 'gateway' => '', |
12 | | - 'api_key' => '', |
13 | | - 'sender' => '' |
| 11 | + 'gateway' => '', |
| 12 | + 'api_key' => '', |
| 13 | + 'sender' => '', |
14 | 14 | ]; |
15 | 15 |
|
16 | | - public function __construct() |
| 16 | + public function __construct($account = null) |
17 | 17 | { |
18 | | - $this->credential['gateway'] = config('iranian_sms.parsasms.gateway'); |
19 | | - $this->credential['api_key'] = config('iranian_sms.parsasms.api_key'); |
20 | | - $this->credential['sender'] = config('iranian_sms.parsasms.sender'); |
| 18 | + if (is_null($account)) { |
| 19 | + $this->credential['gateway'] = config('iranian_sms.parsasms.gateway'); |
| 20 | + $this->credential['api_key'] = config('iranian_sms.parsasms.api_key'); |
| 21 | + $this->credential['sender'] = config('iranian_sms.parsasms.sender'); |
| 22 | + } else { |
| 23 | + $this->credential['gateway'] = config("iranian_sms.parsasms.{$account}.gateway"); |
| 24 | + $this->credential['api_key'] = config("iranian_sms.parsasms.{$account}.api_key"); |
| 25 | + $this->credential['sender'] = config("iranian_sms.parsasms.{$account}.sender"); |
| 26 | + } |
21 | 27 | } |
22 | 28 |
|
23 | 29 | public function send(String $number, String $message) |
24 | 30 | { |
25 | | - $number = $this->filterNumber($number); |
26 | | - $sender = $this->credential['sender']; |
| 31 | + $number = $this->filterNumber($number); |
| 32 | + $sender = $this->credential['sender']; |
27 | 33 | $api_key = $this->credential['api_key']; |
28 | 34 |
|
29 | 35 | $curl = curl_init(); |
30 | 36 | curl_setopt_array($curl, array( |
31 | | - CURLOPT_URL => $this->credential['gateway'], |
32 | | - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
33 | | - CURLOPT_CUSTOMREQUEST => "POST", |
34 | | - CURLOPT_POSTFIELDS => "message=$message &sender=$sender &Receptor=$number", |
| 37 | + CURLOPT_URL => $this->credential['gateway'], |
| 38 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 39 | + CURLOPT_CUSTOMREQUEST => "POST", |
| 40 | + CURLOPT_POSTFIELDS => "message=$message &sender=$sender &Receptor=$number", |
35 | 41 | CURLOPT_CONNECTTIMEOUT => 5, |
36 | | - CURLOPT_TIMEOUT => 5, |
37 | | - CURLOPT_HTTPHEADER => array( |
38 | | - "apikey: $api_key"), |
| 42 | + CURLOPT_TIMEOUT => 5, |
| 43 | + CURLOPT_HTTPHEADER => array( |
| 44 | + "apikey: $api_key", |
| 45 | + ), |
39 | 46 | CURLOPT_RETURNTRANSFER => true, |
40 | 47 | )); |
41 | 48 |
|
42 | 49 | $response = curl_exec($curl); |
43 | 50 | curl_close($curl); |
44 | 51 |
|
45 | | - $response_array = json_decode($response,TRUE); |
| 52 | + $response_array = json_decode($response, true); |
46 | 53 |
|
47 | | - if (!(isset($response_array['result']) && $response_array['result'] == 'success')){ |
48 | | - throw new Exception("Error: ".$response); |
| 54 | + if (!(isset($response_array['result']) && $response_array['result'] == 'success')) { |
| 55 | + throw new Exception("Error: " . $response); |
49 | 56 | } |
50 | 57 |
|
51 | 58 | return $response; |
|
0 commit comments