Skrypty - PHP, XML, Ruby on Rails
Repozytorium gotowych skryptów obsługujących nasze WebApi.
SMS XML SENDER - klasa obsługująca XML WebApi (PHP)
Zobacz onLine Ściągnij
<?php include_once("sms_xmlsender.php"); //Konstruktor klasy, oraz parametry $sms = new SMS_SENDER; $sms->login="mojlogin@gatesms.eu"; $sms->pass="0a3eeeee8dew45"; $sms->test="false"; //Wysyłanie paczek z wiadomościami z dynamicznym identyfikatorem localId: $sms->localIdRandom=1; $sms->to=48501123456; $err = $sms->AddMsg("TEST A"); $LocalmsgId = $sms->localId; $report = $sms->sendsms(); exit; ?>
<?php class SMS_SENDER { public $to; public $from; public $isFlash; public $login; public $pass; public $pl; public $code; public $wap; public $test; public $speed; public $secure; public $time; public $localId; public $localIdRandom; public $globalId; public $debug; public $raw; public $part; public $modemID; private $smsConnect; private $msg; private $counter; private $stat; public function SMS_SENDER() { $this->msg=array(); $this->stat=array(); $this->counter=0; $this->localId=''; $this->isFlash="false"; $this->from=""; $this->wap=""; $this->pl='false'; $this->code='gsm7'; //gsm7 | ucs2 $this->test='false'; $this->speed='false'; $this->secure=false; $this->time=time(); $this->globalId=0; $this->debug=0; $this->localIdRandom=0; $this->raw="false"; $this->part=''; $this->modemID=""; $this->smsConnect=null; } public function setTime($data='') {//eg. 2010-10-06 23:45:00 if($data) { $d=explode(" ",$data); $h=explode(":",$d[1]); $d=explode("-",$d[0]); $this->time=mktime($h[0],$h[1],$h[2],$d[1],$d[2],$d[0]); }; } public function AddMsg($msg) { if($this->to=='') return 106; if($this->localId=='' && $this->localIdRandom==0) return 301; if($this->localIdRandom==1) $this->localId=substr(md5(microtime(true).mt_rand(100000,100000000)),0,10); if($msg=='') return 103; $msg=str_replace(array("+"," "),array("%2B","%20"),$msg); $this->msg[$this->counter]="<msg time=\"".$this->time."\" speed=\"".$this->speed."\" wap=\"".$this->wap."\" pl=\"".$this->pl."\" isflash=\"".$this->isFlash."\" from=\"".$this->from."\" phone=\"".$this->to."\" localid=\"".$this->localId."\" raw=\"".$this->raw."\" modemid=\"".$this->modemID."\" code=\"".$this->code."\" part=\"".$this->part."\">".$msg."</msg>"; $this->counter++; }
public function AddStat() { if($this->globalId=='' && $this->localId=='') return 301; $id=($this->globalId!='') ? "globalid=\"".$this->globalId."\"" : "localid=\"".$this->localId."\""; $this->stat[$this->counter]="<status timestamp=\"".$this->time."\" ok=\"true\" ".$id."/>"; $this->counter++; } private function Connection() { $url=($this->secure)?"https://gatesms.eu/sms_xmlapi.php": "http://gatesms.eu/sms_xmlapi.php"; if(!$this->smsConnect) { $this->smsConnect = curl_init(); if($this->secure) { curl_setopt($this->smsConnect, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($this->smsConnect, CURLOPT_SSL_VERIFYHOST, false); }; curl_setopt($this->smsConnect, CURLOPT_POST, 1); curl_setopt($this->smsConnect, CURLOPT_USERAGENT, "SMSbot:(www.gatesms.eu)"); curl_setopt($this->smsConnect, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($this->smsConnect, CURLOPT_FRESH_CONNECT, 1); curl_setopt($this->smsConnect, CURLOPT_TIMEOUT, 30); curl_setopt($this->smsConnect, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($this->smsConnect, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->smsConnect, CURLOPT_HEADER, $this->debug); curl_setopt($this->smsConnect, CURLOPT_URL, $url); }; } public function callBack() { return stripslashes($_POST['body']); } public function GetStat() { $out=""; $POST='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><report>'; foreach($this->stat as $stat) $POST.=$stat; $POST.='</report>';
$timestamp=time(); $HASH=md5('POST/sms_xmlapi.php'.md5($POST).'Accept:application/xml'.$timestamp.$this->pass); $header=array(); array_push($header,"X-GT-Auth: ".$this->login.":".$HASH); array_push($header,"X-GT-Timestamp: ".$timestamp); array_push($header,"Content-Type: application/x-www-form-urlencoded"); array_push($header,"Accept: application/xml"); array_push($header,"Expect: 100-continue"); array_push($header,"X-GT-Action: GET STATUS"); $fields="body=".urlencode($POST); if(!$this->smsConnect) $this->Connection(); curl_setopt($this->smsConnect, CURLOPT_HTTPHEADER, $header); curl_setopt($this->smsConnect, CURLOPT_POSTFIELDS, $fields); $out=curl_exec($this->smsConnect); return ($this->debug) ? htmlspecialchars($out) : $out; }
public function AddHlr($numery) { $out=""; $POST=implode("\n",$numery); $timestamp=time(); $HASH=md5('POST/sms_xmlapi_beta.php'.md5($POST).'Accept:text/plain'.$timestamp.$this->pass); $header=array(); array_push($header,"X-GT-Auth: ".$this->login.":".$HASH); array_push($header,"X-GT-Timestamp: ".$timestamp); array_push($header,"Content-Type: application/x-www-form-urlencoded"); array_push($header,"Accept: text/plain"); array_push($header,"Expect: 100-continue"); array_push($header,"X-GT-Action: PUT HLR"); $fields="body=".urlencode($POST); if(!$this->smsConnect) $this->Connection(); curl_setopt($this->smsConnect, CURLOPT_HTTPHEADER, $header); curl_setopt($this->smsConnect, CURLOPT_POSTFIELDS, $fields); $out=curl_exec($this->smsConnect); return ($this->debug) ? htmlspecialchars($out) : $out; } public function sendSms() { $out=""; $POST='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <package test="'.$this->test.'">'; foreach($this->msg as $msg) $POST.=$msg; $POST.='</package>'; $timestamp=time(); $HASH=md5('POST/sms_xmlapi.php'.md5($POST).'Accept:application/xml'.$timestamp.$this->pass); $header=array(); array_push($header,"X-GT-Auth: ".$this->login.":".$HASH); array_push($header,"X-GT-Timestamp: ".$timestamp); array_push($header,"Content-Type: application/x-www-form-urlencoded"); array_push($header,"Accept: application/xml"); array_push($header,"Expect: 100-continue"); //array_push($header,"X-GT-Action: get status"); //array_push($header,"X-GT-Action: hlr"); //array_push($header,"Content-Type: application/xml"); $fields="body=".urlencode($POST); if(!$this->smsConnect) $this->Connection(); curl_setopt($this->smsConnect, CURLOPT_HTTPHEADER, $header); curl_setopt($this->smsConnect, CURLOPT_POSTFIELDS, $fields); $out=curl_exec($this->smsConnect); return ($this->debug) ? htmlspecialchars($out) : $out; }
public function ConnectClose() { if($this->smsConnect) curl_close($this->smsConnect); } private function __desctruct() { $this->ConnectClose(); } }; ?>
SMS SENDER - klasa obsługująca zarówno wysyłkę sms jak i sms Premium, motody przesyłania POST, GET (PHP)
Zobacz onLine Ściągnij
<? class SMS_SENDER { public $to; public $from; public $smsTyp; public $login; public $pass; public $pl; public $wap; public $transaction; public $test; public $contact; public $selfNumber; public $secure; public $time; public $name; public $import; public $hlr; public $massGroup; public $email; public $pakiet; public $msg_info; private $smsConnect; private $msg; private $servers; private $server; public function __construct() { $this->smsTyp="sms"; $this->from=""; $this->wap=""; $this->pl=0; $this->test=0; $this->msg_info=0; $this->transaction=0; $this->import=0; $this->contact=0; $this->name=""; $this->email=""; $this->pakiet=""; $this->selfNumber=-1; $this->secure=0; $this->time=time(); $this->smsConnect=null; $this->server=0; $this->servers=array('www.gatesms.eu'); $this->Connection(); } public function setLogin($login) { $this->login=$login; } public function setPass($pass) { $this->pass=$pass; } public function setFrom($from) { $this->from=$from; } public function setSmsTyp($typ="sms") { $this->smsTyp=$typ; } public function setTo($to) { $this->to=$to; }
public function setPL($pl) { $this->pl=$pl; }
public function setWap($wap) { $this->wap=$wap; }
public function setTest($test=1) { $this->test=$test; }
public function setContact($contact=1) { $this->contact=$contact; }
public function setTransaction($transaction=1) { $this->transaction=$transaction; }
public function setTime($data='') {//eg. 2010-10-06 23:45:00 if($data) { $d=explode(" ",$data); $h=explode(":",$d[1]); $d=explode("-",$d[0]); $this->time=mktime($h[0],$h[1],$h[2],$d[1],$d[2],$d[0]); }; }
public function setSelfNumber($number=-1) { $this->selfNumber=$number; } public function setMsg($msg) { $replacement = array( "&"=>"%26", "#"=>"%23", " "=>"%20" ); $this->msg=($this->smsTyp!='premium') ? strtr($msg,$replacement) : $msg; } public function ChangeServer($id) { $this->server=$id; } private function GetServers() { $url="http://www.gatesms.eu/sms_api.php?server_get_log_ip=1"; $header[0] = "Connection: keep-alive"; $header[1] = "Keep-Alive: 300"; $smsConnect = curl_init(); curl_setopt($smsConnect, CURLOPT_HTTPHEADER, $header); curl_setopt($smsConnect, CURLOPT_POST, 1); curl_setopt($smsConnect, CURLOPT_USERAGENT, "SMSbot:(www.gatesms.eu)"); curl_setopt($smsConnect, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($smsConnect, CURLOPT_FRESH_CONNECT, 1); curl_setopt($smsConnect, CURLOPT_TIMEOUT, 15); curl_setopt($smsConnect, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($smsConnect, CURLOPT_RETURNTRANSFER, 1); curl_setopt($smsConnect, CURLOPT_URL, $url); array_push($this->servers,curl_exec($smsConnect).'/gatesms'); curl_close($smsConnect); } private function Connection() { $url=($this->secure)?"https://".$this->servers[$this->server]."/sms_api.php":"http://".$this->servers[$this->server]."/sms_api.php"; $header[0] = "Connection: keep-alive"; $header[1] = "Keep-Alive: 300";
if(!$this->smsConnect) { //$this->GetServers(); $this->smsConnect = curl_init(); if($this->secure) curl_setopt($this->smsConnect, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($this->smsConnect, CURLOPT_HTTPHEADER, $header); curl_setopt($this->smsConnect, CURLOPT_POST, 1); curl_setopt($this->smsConnect, CURLOPT_USERAGENT, "SMSbot:(www.gatesms.eu)"); curl_setopt($this->smsConnect, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($this->smsConnect, CURLOPT_FRESH_CONNECT, 1); curl_setopt($this->smsConnect, CURLOPT_TIMEOUT, 15); curl_setopt($this->smsConnect, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($this->smsConnect, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->smsConnect, CURLOPT_URL, $url); }; } public function checkNumber($number) { $out=""; $fields="spr_numer=".$number; $fields.="&full=1"; if(!$this->smsConnect) $this->Connection(); curl_setopt($this->smsConnect, CURLOPT_POSTFIELDS, $fields); $out=curl_exec($this->smsConnect); return $out; } public function checkCredit() { $out=""; $fields="login=".$this->login; $fields.="&pass=".$this->pass; $fields.="&check_credit=1"; if(!$this->smsConnect) $this->Connection(); curl_setopt($this->smsConnect, CURLOPT_POSTFIELDS, $fields); $out=curl_exec($this->smsConnect); return $out; } public function sendSms() { $out=""; $fields="login=".$this->login; $fields.="&pass=".$this->pass; if($this->pakiet=='') { $fields.="&msg=".$this->msg; $fields.="&to=".$this->to; } else { $fields.="&pakiet=".$this->pakiet; }; $fields.="&sms_type=".$this->smsTyp; $fields.="&from=".$this->from; $fields.="&pl=".$this->pl; $fields.="&wap=".$this->wap; $fields.="&transaction=".$this->transaction; $fields.="&test=".$this->test; $fields.="&msg_info=".$this->msg_info; $fields.="&contact=".$this->contact; $fields.="&self_number=".$this->selfNumber; $fields.="&time=".$this->time; $fields.="&name=".$this->name; $fields.="&import=".$this->import; $fields.="&email=".$this->email; if(!$this->smsConnect) $this->Connection(); curl_setopt($this->smsConnect, CURLOPT_POSTFIELDS, $fields); $out=curl_exec($this->smsConnect); return $out; }
public function ConnectClose() { if($this->smsConnect) curl_close($this->smsConnect); } private function __desctruct() { $this->ConnectClose(); } }; ?>
Generator kodów - klasa generująca dynamiczne kody dostępowe, może zostać również wykorzystana przy odsyłaniu kodów Premium sms. (PHP)
Zobacz onLine Ściągnij
<?php
class Code { public $expire = 7200; function Code() { try { if(!is_file("gatesms.code")) { $f=fopen("gatesms.code","w"); if(!$f) throw new Exception("PROBLEM Z OTWARCIM PLIKU"); fputs($f,""); fclose($f); } } catch (Exception $e){print $e->getMessage();} } public function getCode() { $AS = array('A','B','C','D','E','F','G','H','I','J','K','L', 'M','N','O','P','Q','R','S','T','U','W','Z','X','Y','V','a', 'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p', 'q','r','s','t','u','w','z','x','y','v','1','2','3','4','5', '6','7','8','9','0'); $CODE = ""; for($z=0;$z<4;$z++) $CODE.= $AS[rand(0,count($AS))]; return $CODE; } public function saveCode($code) { try{ $f=fopen("gatesms.code","a"); if(!$f) throw new Exception('PROBLEM Z OTWARCIEM PLIKU'); fputs($f, $code." ".time()."\n"); fclose($f); } catch (Exception $e){print $e->getMessage();} } public function checkCode($code) { try{ $f=file("gatesms.code"); $out=""; $ok=0; if(!is_array($f)) throw new Exception ("PROBLEM Z OTWARCIEM PLIKU"); foreach($f as $rows) { $row = explode(" ", trim($rows)); if($row[0]!=$code AND $row[1] > time()-$this->expire) { $out.=$row[0]." ".$row[1]."\n"; } else if($row[0]==$code) { $ok=1; }; }; $f=fopen("gatesms.code","w"); if(!$f) throw new Exception("PROBLEM Z OTWARCIEM PLIKU"); fputs($f, $out); fclose($f); } catch(Exception $e) {print $e->getMessage();} return $ok; } }; //------------------------------------------------------------------------------ if($from) {
$Code = new Code; $kod = $Code->getCode(); $Code->saveCode($kod); include_once("sms_sender.php"); $sms = new SMS_SENDER; // konstruktor obiektu SMS $sms->setLogin("demo@gatesms.eu"); // Twój login lub numer telefonu 48XXXXXXXXX $sms->setPass("hasło"); // Twoje hasło $sms->setSmsTyp("premium"); //Przy wysyłaniu smsów z darmowej puli koniecznie MUSI być typ: premium $sms->setTo($from); // Numer pod który zostanie wysłany sms $msg="Twój kod: ".$kod." Wpisz go na stronie internetowej."; //Treść przesyłanej wiadomości sms. $sms->setMsg($msg);// Pole wiadomości tu przesyłamy kod! lub dowolną wiadomość sms $sms->sendSms(); // wysyłamy wiadomość unset($sms); // kasujemy obiekt sms }
if($get_code) { //zmienna która jest ustawiana w momencie kiedy użytkownik wpisze kod na stronie internetowej $Code = new Code; // Konstruktor obiektu Code $Code->expire=3600; // Ilość sekund po których kod wygaśnie if(1==$Code->checkCode($get_code)){ //Funkcja sprawdza kod zwraca 1 jeżeli poprawny i 0 gdy nie //Jeżeli funkcja checkCode zwróci 1 możemy udostępnić internaucie zawartość! }; }
?>
Gotowa obsługa komunikacji USSD (PHP)
Ściągnij
Gotowa obsługa komunikacji SMS z wykorzystaniem frameworku Ruby on Rails (3.2.3)
Opis API w dokumentacji technicznej XML-WEBAPI
Ściągnij
|
|