|
1
|
|
|
<?php namespace SOSTheBlack\Moip; |
|
2
|
|
|
|
|
3
|
|
|
use Exception; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Verificação de status da conta do MoIP. Atualmente somente com suporte à verificação de saldo e ultimas transações. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Herberth Amaral |
|
9
|
|
|
* @version 0.0.2 |
|
10
|
|
|
* @package MoIP |
|
11
|
|
|
*/ |
|
12
|
|
|
class Status |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* url for login |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
private $url_login = "https://www.moip.com.br/j_acegi_security_check"; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* setCredennciais |
|
23
|
|
|
* |
|
24
|
|
|
* @param type $username |
|
25
|
|
|
* @param type $password |
|
26
|
|
|
* @return \SOSTheBlack\Moip\Status |
|
27
|
|
|
*/ |
|
28
|
|
|
function setCredenciais($username,$password) |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
$this->username = $username; |
|
|
|
|
|
|
31
|
|
|
$this->password = $password; |
|
|
|
|
|
|
32
|
|
|
return $this; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* getStatus |
|
37
|
|
|
* |
|
38
|
|
|
* @return \SOSTheBlack\Moip\Status |
|
39
|
|
|
*/ |
|
40
|
|
|
function getStatus() |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
if (!isset($this->username) or !isset($this->password)) |
|
43
|
|
|
throw new Exception("Usuário ou senha não especificados."); |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$ch = curl_init($this->url_login); |
|
47
|
|
|
curl_setopt($ch, CURLOPT_POST ,1); |
|
48
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS ,"j_username=$this->username&j_password=$this->password"); |
|
49
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1); |
|
50
|
|
|
curl_setopt($ch, CURLOPT_HEADER ,0); |
|
51
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); |
|
52
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
|
53
|
|
|
$page = curl_exec($ch); |
|
54
|
|
|
$error = curl_error($ch); |
|
55
|
|
|
|
|
56
|
|
|
if (!empty($error)) |
|
57
|
|
|
{ |
|
58
|
|
|
$errno = curl_errno($ch); |
|
59
|
|
|
throw new Exception("Ooops, ocorreu um erro ao tentar recuperar os status #$errno: $error"); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (stristr($page,"Login e senha incorretos")) |
|
63
|
|
|
throw new Exception('Login incorreto'); |
|
64
|
|
|
|
|
65
|
|
|
$this->saldo = pq('div.textoCinza11 b.textoAzul15')->text(); |
|
|
|
|
|
|
66
|
|
|
$this->saldo_a_receber = pq('div.textoCinza11 b.textoAzul11')->text(); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$this->ultimas_transacoes = $this->getLastTransactions($page); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* getLastTransactions |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $page |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
private function getLastTransactions($page) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
$selector = 'div.conteudo>div:eq(1)>div:eq(1)>div:eq(1)>div:eq(0) div.box table[cellpadding=5]>tbody tr'; |
|
82
|
|
|
|
|
83
|
|
|
if (substr(utf8_encode(pq($selector)->find('td:eq(0)')->html()),0,7)=="Nenhuma") |
|
84
|
|
|
return null; |
|
85
|
|
|
|
|
86
|
|
|
$ultimas_transacoes = array(); |
|
87
|
|
|
foreach(pq($selector) as $tr) |
|
88
|
|
|
{ |
|
89
|
|
|
$tds = pq($tr); |
|
90
|
|
|
|
|
91
|
|
|
$transacao = array('data'=>$tds->find('td:eq(0)')->html(), |
|
92
|
|
|
'nome'=>$tds->find('td:eq(1)')->html(), |
|
93
|
|
|
'pagamento'=>$tds->find('td:eq(2)')->html(), |
|
94
|
|
|
'adicional'=>$tds->find('td:eq(3)')->html(), |
|
95
|
|
|
'valor'=>$tds->find('td:eq(4)')->html() |
|
96
|
|
|
); |
|
97
|
|
|
$ultimas_transacoes[] = $transacao; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return $ultimas_transacoes; |
|
101
|
|
|
} |
|
102
|
|
|
} |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.