These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace zembrowski\SMS; |
||
4 | |||
5 | /** |
||
6 | * Class Orange |
||
7 | * @package zembrowski\phpsms-poland |
||
8 | */ |
||
9 | class Orange |
||
10 | { |
||
11 | public $url = 'https://www.orange.pl'; // orange.pl URL |
||
12 | private $user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4'; |
||
13 | private $login_request_uri = '/zaloguj.phtml'; // login form request uri |
||
14 | private $login_post_query_string = '?_DARGS=/ocp/gear/infoportal/portlets/login/login-box.jsp'; // login form POST query string |
||
15 | private $send_request_uri = '/portal/map/map/message_box?mbox_edit=new&mbox_view=newsms'; // request uri of form for sending new messages |
||
16 | private $send_post_request_uri = '/portal/map/map/message_box?_DARGS=/gear/mapmessagebox/smsform.jsp'; // action target for POST request of the sending new messages form |
||
17 | public $max_length = '640'; // max. length of one SMS message according to the sending new messages form |
||
18 | |||
19 | /** |
||
20 | * Session placeholder during the whole execution |
||
21 | * @var Requests_Session |
||
22 | */ |
||
23 | private $session; |
||
24 | |||
25 | /** |
||
26 | * Initialized DOM for response analyzing |
||
27 | * @var simple_html_dom |
||
28 | */ |
||
29 | private $html; |
||
30 | |||
31 | /** |
||
32 | * Session data variable (not being cross-checked yet) |
||
33 | * @var string |
||
34 | */ |
||
35 | private $dynSess; |
||
36 | |||
37 | /** |
||
38 | * Form submission token placeholder |
||
39 | * @var string |
||
40 | */ |
||
41 | private $token; |
||
42 | |||
43 | /** |
||
44 | * Instantiates the Requests handler with session support. |
||
45 | */ |
||
46 | public function __construct() |
||
47 | { |
||
48 | $session = new \Requests_Session($this->url); |
||
49 | $session->useragent = $this->user_agent; |
||
50 | $this->session = $session; |
||
0 ignored issues
–
show
|
|||
51 | $this->session->get($this->login_request_uri); |
||
52 | |||
53 | $html = new \simple_html_dom(); |
||
54 | $this->html = $html; |
||
0 ignored issues
–
show
It seems like
$html of type object<simple_html_dom> is incompatible with the declared type object<zembrowski\SMS\simple_html_dom> of property $html .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
Loading history...
|
|||
55 | |||
56 | $random = rand(1000000000, 2147483647); |
||
57 | $this->dynSess = $random . $random; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Login at orange.pl |
||
62 | * |
||
63 | * You have to be register at orange.pl |
||
64 | * Head to: https://www.orange.pl/rejestracja.phtml |
||
65 | * |
||
66 | * @param string $login - login or the number assosciated with the service you use |
||
67 | * @param string $password - password (pol. "Hasło") |
||
68 | */ |
||
69 | public function login($login, $password) |
||
70 | { |
||
71 | // Referer header set only to act more like a browser |
||
72 | $this->session->headers['Referer'] = $this->url . $this->login_request_uri; |
||
73 | |||
74 | $this->session->data = array( |
||
75 | '_dyncharset' => 'UTF-8', |
||
76 | '_dynSessConf' => $this->dynSess, |
||
77 | '/tp/core/profile/login/ProfileLoginFormHandler.loginErrorURL' => $this->send_request_uri, |
||
78 | '_D:/tp/core/profile/login/ProfileLoginFormHandler.loginErrorURL' => '', |
||
79 | '/tp/core/profile/login/ProfileLoginFormHandler.loginSuccessURL' => $this->send_request_uri, |
||
80 | '_D:/tp/core/profile/login/ProfileLoginFormHandler.loginSuccessURL' => '', |
||
81 | '/tp/core/profile/login/ProfileLoginFormHandler.firstEnter' => 'true', |
||
82 | '_D:/tp/core/profile/login/ProfileLoginFormHandler.firstEnter' => '', |
||
83 | '/tp/core/profile/login/ProfileLoginFormHandler.value.login' => $login, |
||
84 | '_D:/tp/core/profile/login/ProfileLoginFormHandler.value.login' => '', |
||
85 | '/tp/core/profile/login/ProfileLoginFormHandler.value.password' => $password, |
||
86 | '_D:/tp/core/profile/login/ProfileLoginFormHandler.value.password' => '', |
||
87 | '/tp/core/profile/login/ProfileLoginFormHandler.rememberMe' => 'false', |
||
88 | '_D:/tp/core/profile/login/ProfileLoginFormHandler.rememberMe' => '', |
||
89 | '/tp/core/profile/login/ProfileLoginFormHandler.login' => 'Zaloguj się', |
||
90 | '_D:/tp/core/profile/login/ProfileLoginFormHandler.login' => '', |
||
91 | '_DARGS' => '/ocp/gear/infoportal/portlets/login/login-box.jsp' |
||
92 | ); |
||
93 | |||
94 | $response = $this->session->post($this->login_request_uri . $this->login_post_query_string); |
||
95 | |||
96 | $this->token = $this->token($response->body); |
||
97 | |||
98 | $result = array('check' => $this->check($response->body, 'div.box-error p'), 'free' => $this->free($response->body)); |
||
99 | |||
100 | return $result; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Retrieves the token from the webform |
||
105 | * |
||
106 | * @param string $content - content to be searched through |
||
107 | * @return string - token |
||
108 | */ |
||
109 | private function token($content) |
||
110 | { |
||
111 | $element = $this->find($content, 'div#box-smsform form input[name=/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.token]', 0); |
||
112 | |||
113 | return $element->value; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Send a SMS through the webform at $this->send_post_request_uri |
||
118 | * |
||
119 | * @param string $recipient - number of the recipient (9 digits without leading zero for national numbers e.g. 501234567; two leading zeros followed by prefix for international numbers e.g. 004912345678901; no spaces or special chars) |
||
120 | * @param string $text - content of the SMS |
||
121 | */ |
||
122 | // TODO: check number of recipient for validaty |
||
123 | public function send($recipient, $text) |
||
124 | { |
||
125 | if (strlen($text) <= 0 || strlen($text) > $this->max_length) { |
||
126 | throw new Exception('The message must be longer than 0 characters, but shorter than ' . $this->max_length . ' characters'); |
||
127 | } |
||
128 | |||
129 | $this->session->options['timeout'] = 30; |
||
130 | |||
131 | // Referer header set only to act more like a browser |
||
132 | $this->session->headers['Referer'] = $this->url . $this->send_request_uri; |
||
133 | |||
134 | $this->session->data = array( |
||
135 | '_dyncharset' => 'UTF-8', |
||
136 | '_dynSessConf' => $this->dynSess, |
||
137 | '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.type' => 'sms', |
||
138 | '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.type' => '', |
||
139 | '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.errorURL' => '', |
||
140 | '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.errorURL' => '', |
||
141 | '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.successURL' => '', |
||
142 | '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.successURL' =>'', |
||
143 | '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.to' => $recipient, |
||
144 | '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.to' => '', |
||
145 | '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.body' => $text, |
||
146 | '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.body' => '', |
||
147 | '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.token' => $this->token, |
||
148 | '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.token' => '', |
||
149 | 'enabled' => true, |
||
150 | '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create.x' => rand(0, 50), |
||
151 | '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create.y' => rand(0, 25), |
||
152 | '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create' => 'Wyślij', |
||
153 | '_D:/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.create' => '', |
||
154 | '_DARGS' => '/gear/mapmessagebox/smsform.jsp' |
||
155 | ); |
||
156 | |||
157 | $response = $this->session->post($this->send_post_request_uri); |
||
158 | |||
159 | $result = array('status_code' => $response->status_code, 'check' => $this->check($response->body, 'div.box-error p'), 'free' => $this->free($response->body)); |
||
160 | |||
161 | return $result; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Find element in HTML Dom |
||
166 | * |
||
167 | * @param string $content - content to be searched through |
||
168 | * @return object |
||
169 | */ |
||
170 | private function find($content, $selector, $nth = null) |
||
171 | { |
||
172 | $this->html->load($content); |
||
173 | if (is_int($nth) || $nth === 0) { |
||
174 | $result = $this->html->find($selector, $nth); |
||
175 | } else { |
||
176 | $result = $this->html->find($selector); |
||
177 | } |
||
178 | |||
179 | return $result; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Checks the remaining SMS left this month from the response body |
||
184 | * |
||
185 | * @param string $content - content to be searched through |
||
186 | * @return boolean|int|string - free SMS this month; false if no content; int if int value present; other cases string |
||
187 | */ |
||
188 | private function free($content) |
||
189 | { |
||
190 | if ($content) { |
||
191 | $element = $this->find($content, '#syndication p.item span.value', 0); |
||
192 | $value = $element->plaintext; |
||
193 | if (!empty($element->plaintext)) { |
||
194 | $value = trim($value); |
||
195 | $value_int = intval($value); |
||
196 | if (is_int($value_int)) $result = $value_int; |
||
197 | else $result = $value; |
||
198 | } else { |
||
199 | $result = false; |
||
200 | } |
||
201 | } else { |
||
202 | $result = false; |
||
203 | } |
||
204 | |||
205 | return $result; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Checks the remaining SMS left this month making a GET request |
||
210 | * |
||
211 | * @return int - free SMS this month |
||
212 | */ |
||
213 | public function getFree() |
||
214 | { |
||
215 | $response = $this->session->get($this->send_request_uri); |
||
216 | $element = $this->find($response->body, '#syndication p.item span.value', 0); |
||
217 | $result = intval(trim($element->plaintext)); |
||
218 | |||
219 | return $result; |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * Check whether errors have been returned |
||
224 | * |
||
225 | * @param string $content - response body of a request |
||
226 | * @return boolean - false if an element described by the selector exists |
||
227 | */ |
||
228 | private function check($content, $selector) |
||
229 | { |
||
230 | $elements = $this->find($content, $selector); |
||
231 | if (count($elements) > 0) { |
||
232 | foreach ($elements as $element) { |
||
233 | throw new Exception(trim($element->plaintext)); |
||
234 | } |
||
235 | $result = false; |
||
236 | } else { |
||
237 | $result = true; |
||
238 | } |
||
239 | |||
240 | return $result; |
||
241 | } |
||
242 | } |
||
243 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..