forked from moiplabs/moip-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoIPStatus.php
84 lines (65 loc) · 2.55 KB
/
MoIPStatus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require 'phpQuery/phpQuery.php';
/**
* Verificação de status da conta do MoIP. Atualmente somente com suporte à verificação de saldo e ultimas transações.
* @author Herberth Amaral
* @version 0.0.2
* @package MoIP
*/
class MoIPStatus
{
private $url_login = "https://www.moip.com.br/j_acegi_security_check";
function setCredenciais($username,$password)
{
$this->username = $username;
$this->password = $password;
return $this;
}
function getStatus()
{
if (!isset($this->username) or !isset($this->password))
throw new Exception("Usuário ou senha não especificados.");
$ch = curl_init($this->url_login);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,"j_username=$this->username&j_password=$this->password");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$page = curl_exec($ch);
$error = curl_error($ch);
if (!empty($error))
{
$errno = curl_errno($ch);
throw new Exception("Ooops, ocorreu um erro ao tentar recuperar os status #$errno: $error");
}
if (stristr($page,"Login e senha incorretos"))
throw new Exception('Login incorreto');
$doc = phpQuery::newDocumentHTML($page);
$this->saldo = pq('div.textoCinza11 b.textoAzul15')->text();
$this->saldo_a_receber = pq('div.textoCinza11 b.textoAzul11')->text();
$this->ultimas_transacoes = $this->getLastTransactions($page);
return $this;
}
private function getLastTransactions($page)
{
$doc = phpQuery::newDocumentHTML($page);
$selector = 'div.conteudo>div:eq(1)>div:eq(1)>div:eq(1)>div:eq(0) div.box table[cellpadding=5]>tbody tr';
if (substr(utf8_encode(pq($selector)->find('td:eq(0)')->html()),0,7)=="Nenhuma")
return null;
$ultimas_transacoes = array();
foreach(pq($selector) as $tr)
{
$tds = pq($tr);
$transacao = array('data'=>$tds->find('td:eq(0)')->html(),
'nome'=>$tds->find('td:eq(1)')->html(),
'pagamento'=>$tds->find('td:eq(2)')->html(),
'adicional'=>$tds->find('td:eq(3)')->html(),
'valor'=>$tds->find('td:eq(4)')->html()
);
$ultimas_transacoes[] = $transacao;
}
return $ultimas_transacoes;
}
}
?>