1 | <?php |
||||
2 | |||||
3 | |||||
4 | namespace Jaby\Sms\Drivers; |
||||
5 | |||||
6 | |||||
7 | use Jaby\Sms\SmsInterface; |
||||
8 | |||||
9 | class farazsms implements SmsInterface |
||||
10 | { |
||||
11 | protected $drive = 'farazsms'; |
||||
12 | |||||
13 | protected $method; |
||||
14 | |||||
15 | protected $username; |
||||
16 | |||||
17 | protected $password; |
||||
18 | |||||
19 | protected $from; |
||||
20 | |||||
21 | protected $pattern_code; |
||||
22 | |||||
23 | protected $to; |
||||
24 | |||||
25 | protected $input_data; |
||||
26 | |||||
27 | protected $url; |
||||
28 | |||||
29 | protected $numbers; |
||||
30 | |||||
31 | protected $data; |
||||
32 | |||||
33 | protected $text; |
||||
34 | |||||
35 | /** |
||||
36 | * farazsms constructor. |
||||
37 | */ |
||||
38 | public function __construct() |
||||
39 | { |
||||
40 | $this->username = config('sms.drivers.'.$this->drive.'.username'); |
||||
41 | $this->password = config('sms.drivers.'.$this->drive.'.password'); |
||||
42 | $this->from = config('sms.drivers.'.$this->drive.'.from'); |
||||
43 | $this->url = config('sms.drivers.'.$this->drive.'.urlPattern'); |
||||
44 | } |
||||
45 | |||||
46 | /** |
||||
47 | * @return bool|mixed|string |
||||
48 | */ |
||||
49 | public function send() |
||||
50 | { |
||||
51 | if ($this->method == 'pattern') |
||||
52 | $res = $this->sendPattern(); |
||||
53 | else |
||||
54 | $res = $this->message($this->text); |
||||
55 | return $res; |
||||
56 | } |
||||
57 | |||||
58 | /** |
||||
59 | * @param $text |
||||
60 | * @return $this|mixed |
||||
61 | */ |
||||
62 | public function text($text) |
||||
63 | { |
||||
64 | $this->text = $text; |
||||
65 | |||||
66 | return $this; |
||||
67 | } |
||||
68 | |||||
69 | /** |
||||
70 | * @param null $pattern_code |
||||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||||
71 | * @return $this|mixed |
||||
72 | */ |
||||
73 | public function pattern($pattern_code = null) |
||||
74 | { |
||||
75 | $this->method = 'pattern'; |
||||
76 | if ($pattern_code) |
||||
0 ignored issues
–
show
|
|||||
77 | $this->pattern_code = $pattern_code; |
||||
78 | return $this; |
||||
79 | } |
||||
80 | |||||
81 | /** |
||||
82 | * @param array $data |
||||
83 | * @return $this|mixed |
||||
84 | */ |
||||
85 | public function data(array $data) |
||||
86 | { |
||||
87 | $this->data = $data; |
||||
88 | |||||
89 | return $this; |
||||
90 | } |
||||
91 | |||||
92 | /** |
||||
93 | * @param $from |
||||
94 | * @return $this|mixed |
||||
95 | */ |
||||
96 | public function from($from) |
||||
97 | { |
||||
98 | $this->from = $from; |
||||
99 | |||||
100 | return $this; |
||||
101 | } |
||||
102 | |||||
103 | /** |
||||
104 | * @param array $numbers |
||||
105 | * @return $this|mixed |
||||
106 | */ |
||||
107 | public function to(array $numbers) |
||||
108 | { |
||||
109 | $this->numbers = $numbers; |
||||
110 | |||||
111 | return $this; |
||||
112 | } |
||||
113 | |||||
114 | /** |
||||
115 | * @return bool|mixed|string |
||||
116 | */ |
||||
117 | public function sendPattern() |
||||
118 | { |
||||
119 | $numbers = $this->numbers; |
||||
120 | $pattern_code = $this->pattern_code; |
||||
121 | $username = $this->username; |
||||
122 | $password = $this->password; |
||||
123 | $from = $this->from; |
||||
124 | $to = $numbers; |
||||
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"; |
||||
127 | $handler = curl_init($url); |
||||
128 | curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST"); |
||||
129 | curl_setopt($handler, CURLOPT_POSTFIELDS, json_encode($input_data)); |
||||
130 | curl_setopt($handler, CURLOPT_RETURNTRANSFER, true); |
||||
131 | $response = curl_exec($handler); |
||||
132 | return $response; |
||||
133 | } |
||||
134 | |||||
135 | /** |
||||
136 | * @param $text |
||||
137 | * @return mixed |
||||
138 | */ |
||||
139 | public function message($text) |
||||
140 | { |
||||
141 | |||||
142 | $this->url = config('sms.drivers.'.$this->drive.'.urlNormal'); |
||||
143 | |||||
144 | $rcpt_nm = $this->numbers; |
||||
145 | $param = array |
||||
146 | ( |
||||
147 | 'uname'=> $this->username , |
||||
148 | 'pass'=> $this->password, |
||||
149 | 'from'=>$this->from, |
||||
150 | 'message'=>$text, |
||||
151 | 'to'=>json_encode($rcpt_nm), |
||||
152 | 'op'=>'send' |
||||
153 | ); |
||||
154 | |||||
155 | $handler = curl_init($this->url); |
||||
156 | curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "POST"); |
||||
157 | curl_setopt($handler, CURLOPT_POSTFIELDS, json_encode($param)); |
||||
158 | curl_setopt($handler, CURLOPT_RETURNTRANSFER, true); |
||||
159 | $response2 = curl_exec($handler); |
||||
160 | |||||
161 | $response2 = json_decode($response2); |
||||
0 ignored issues
–
show
It seems like
$response2 can also be of type true ; however, parameter $json of json_decode() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
162 | $res_code = $response2[0]; |
||||
0 ignored issues
–
show
|
|||||
163 | $res_data = $response2[1]; |
||||
164 | |||||
165 | return $res_data; |
||||
166 | } |
||||
167 | } |
||||
168 |