Created
January 15, 2009 20:00
-
-
Save icebeat/47579 to your computer and use it in GitHub Desktop.
class.movistar.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
include 'class.movistar.php'; | |
// User and Passs | |
$movistar = new ClientMovistar( '757...02D', 'Pass' ); | |
// Number and Type: actual or anterior | |
$info = $movistar->getInfo( '649...338', 'actual' ); | |
*/ | |
class ClientMovistar { | |
var $ch; | |
var $url_login = 'https://sslwb.movistar.es/auth/Login'; | |
var $url_number = 'https://www.canalcliente.movistar.es/fwk/cda/controller/CCLI_CW_privado/0,2217,259_34641405_18171_0_,00.html'; | |
function ClientMovistar( $user, $pass ) { | |
$this->ch = curl_init( $this->url_login ); | |
$data = 'usr_password=KjhG3Tv51&pgeac='.$pass.'&usr_name=h'.$user.'&HiddenURI=https%3A%2F%2Fwww.canalcliente.movistar.es%2Ffwk%2Fcda%2Fcontroller%2FCCLI_CW_privado%2F0%2C2217%2C259_0_2326_0_0%2C00.html&cifAntig='; | |
curl_setopt( $this->ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)' ); | |
curl_setopt( $this->ch, CURLOPT_COOKIEJAR, 'cookies.txt'); | |
curl_setopt( $this->ch, CURLOPT_COOKIEFILE, 'cookies.txt'); | |
curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt( $this->ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt( $this->ch, CURLOPT_POST,1); | |
curl_setopt( $this->ch, CURLOPT_POSTFIELDS, $data ); | |
curl_exec( $this->ch ); | |
} | |
function getInfo( $number, $type = 'actual' ) { | |
curl_setopt( $this->ch, CURLOPT_URL, $this->url_number ); | |
$data = 'opcion=1&telefono='.$number.'&tipoConsulta=telefono¢ro=&tlfcorporativo=&cifnif=&tipoResultado=1&tipoConsumo='.$type.'&telefonos='.$number; | |
curl_setopt( $this->ch, CURLOPT_POSTFIELDS, $data ); | |
$page = curl_exec( $this->ch ); | |
curl_close( $this->ch ); | |
if( preg_match_all( '!<td height="25" align="center" bgcolor="#ffffff">(.*)</td>!Usi', $page, $info ) ) { | |
$total = str_replace( ',', '.', trim($info[1][0]) ); | |
$iva = round( $total + ( $total * 0.16 ), 4 ); | |
$total = str_replace( '.', ',', $total ); | |
$iva = str_replace( '.', ',', $iva ); | |
if( preg_match_all( '!<p>(.*)</p>!Us', $page, $message ) ) { | |
$date = trim( str_replace( array("\t", "\n"), array('', ' '), $message[1][2] ) ); | |
} else { | |
$date = ''; | |
} | |
$data = array( | |
'interval' => $date, | |
'voice' => array( | |
'total' => $total, | |
'iva' => $iva, | |
'calls' => trim($info[1][1]), | |
'duration' => trim($info[1][2]), | |
), | |
'data' => array( | |
'total' => trim($info[1][3]), | |
'calls' => trim($info[1][4]), | |
'traffic' => trim($info[1][5]) | |
) | |
); | |
return $data; | |
} | |
return null; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment