Last active
November 11, 2018 23:04
-
-
Save guibranco/50af540a505acd922347e0685bdeadd6 to your computer and use it in GitHub Desktop.
Exemplo de post com cURL - freeSmsCraze class (SMS Grátis - zerocool.com.br)
This file contains 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 | |
interface iFreesmscraze{ | |
const USUARIO = ""; | |
const SENHA = ""; | |
const HOST = "http://www.freesmscraze.com/"; | |
const ENDPOINT_LOGIN = "members/login.php"; | |
const ENDPOINT_ENVIAR = "sms/ussmsscript_members.php"; | |
const VIDACOOKIE = 14400; | |
const COOKIE = "cookies//freesmscraze.tmp"; | |
public function login(); | |
public function postEnvio($params); | |
} | |
class freesmscraze implements iFreesmscraze{ | |
var $curl,$tentativas; | |
function __construct(){ | |
$this->curl = curl_init(); | |
$this->tentativas = 0; | |
curl_setopt($this->curl,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]); | |
curl_setopt($this->curl,CURLOPT_HEADER, true); | |
curl_setopt($this->curl,CURLOPT_RETURNTRANSFER, true); | |
if(!file_exists(freesmscraze::COOKIE) || filectime(freesmscraze::COOKIE) < (time() - freesmscraze::VIDACOOKIE)) $this->login(); | |
} | |
function __destruct(){ | |
curl_close($this->curl); | |
} | |
public function login(){ | |
$this->tentativas++; | |
if(file_exists(freesmscraze::COOKIE)) unlink(freesmscraze::COOKIE); | |
$dados = "username=".freesmscraze::USUARIO."&password=".freesmscraze::SENHA; | |
curl_setopt($this->curl,CURLOPT_URL,freesmscraze::HOST.freesmscraze::ENDPOINT_LOGIN); | |
curl_setopt($this->curl,CURLOPT_POST, true); | |
curl_setopt($this->curl,CURLOPT_POSTFIELDS,$dados); | |
curl_setopt($this->curl,CURLOPT_REFERER,freesmscraze::HOST."members/index.php"); | |
curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,true); | |
$exec = curl_exec($this->curl); | |
preg_match_all('/Set-Cookie: ((?:.*?)=(?:.*?);)/', $exec, $cookies); | |
if(array_key_exists(1,$cookies)){ | |
$o = fopen(freesmscraze::COOKIE,"w"); | |
foreach($cookies[1] as $cookie) fwrite($o,$cookie,strlen($cookie)); | |
fclose($o); | |
return true; | |
}else return false; | |
} | |
public function postEnvio($params){ | |
$cookie = file(freesmscraze::COOKIE); | |
$cookie = join("",$cookie)."username=-10800;"; | |
$replaces = array("+"," ","\s"); | |
$params["pais"] = str_replace($replaces,"%2B",$params["pais"]); | |
$dados = "countrycode=".$params["pais"]."&DDD3CB5=".$params["numero"]."&thing=0&83BA7EA=".$params["mensagem"]."&B1=SEND+SMS&modeofform="; | |
curl_setopt($this->curl,CURLOPT_URL,freesmscraze::HOST.freesmscraze::ENDPOINT_ENVIAR); | |
curl_setopt($this->curl,CURLOPT_POST, true); | |
curl_setopt($this->curl,CURLOPT_POSTFIELDS,$dados); | |
curl_setopt($this->curl,CURLOPT_REFERER,freesmscraze::HOST."sms/ussms_intl.php"); | |
curl_setopt($this->curl,CURLOPT_COOKIE,$cookie); | |
curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,false); | |
$exec = curl_exec($this->curl); | |
if(preg_match("#Location: ../members/index.php#",$exec)){ | |
$this->login(); | |
if($this->tentativas < 5) $this->postEnvio($params); | |
else{ | |
mail("[email protected]","Problemas Gama",print_r(curl_getinfo($this->curl),1)); | |
http(500); | |
} | |
} | |
echo $exec; | |
return true; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment