Ajutor api

Discutii despre tot ce nu se incadreaza in celelalte categorii.

Moderators: Moderatori ajutatori, Moderatori

Post Reply
User avatar
sergiu4995
Membru, skill +4
Membru, skill +4
Posts: 1895
Joined: 08 Oct 2011, 20:05
Detinator Steam: Nu
Has thanked: 22 times
Been thanked: 8 times
Contact:

04 May 2019, 15:01

Deci asa am raspunsul pe site si la network din browser am reusit sa-mi afiseze structurat in json

[{"Rate":"0.04","Number":"447369051976","Source":"40773829126","AnswerTime":"2019-04-09 20:06:08","EndTime":"2019-04-09 20:36:09","Duration":1800,"revenue":"1.20000","revenue_client":null},{"Rate":"0.04","Number":"447369051976","Source":"40771656893","AnswerTime":"2019-04-09 21:00:56","EndTime":"2019-04-09 21:30:57","Duration":1800,"revenue":"1.19933","revenue_client":null},{"Rate":"0.04","Number":"447369051976","Source":"40771065446","AnswerTime":"2019-04-09 22:41:14","EndTime":"2019-04-09 23:11:14","Duration":1800,"revenue":"1.20000","revenue_client":null},{"Rate":"0.04","Number":"447369051976","Source":"40773829126","AnswerTime":"2019-04-09 23:41:06","EndTime":"2019-04-09 23:41:12","Duration":5,"revenue":"0.00267","revenue_client":null},{"Rate":"0.04","Number":"447369051976","Source":"40771656889","AnswerTime":"2019-04-09 23:57:36","EndTime":"2019-04-10 00:27:37","Duration":1800,"revenue":"1.20000","revenue_client":null},{"Rate":"0.04","Number":"447369051976","Source":"40771065446","AnswerTime":"2019-04-10 08:25:22","EndTime":"2019-04-10 08:53:15","Duration":1672,"revenue":"1.11467","revenue_client":null},{"Rate":"0.04","Number":"447369051976","Source":"40771656889","AnswerTime":"2019-04-10 09:27:48","EndTime":"2019-04-10 09:57:49","Duration":1800,"revenue":"1.20000","revenue_client":null},{"Rate":"0.002","Number":"443434481995","Source":"40771656889","AnswerTime":"2019-05-01 15:56:19","EndTime":"2019-05-01 15:56:26","Duration":6,"revenue":"0.00000","revenue_client":"0.00000"}]
Cum fac sa-mi afiseze doar de exemplu Number si Source ? asta vreau sa fac, vezi ca aici e altfel interpretat nu api dintr-un link de pe un alt site...aia e mai usor
| Afiseaza codul
<?php
class IvasReseller

{
public $token_access = null;
public $url_base = '
public $url_login = '
public $perms = array();
public function __construct($token, $secret)

{
$token = $this->token_access = $this->callAPI("GET", $this->url_login, ["token" => $token, "secret" => $secret, "host" => "http://sitemeu.com"]);
$this->setPerms();
}
public function callAPI($method, $url, $data)

{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;

case "PUT":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;

default:
if ($data) $url = sprintf("%s?%s", $url, http_build_query($data));
}
// OPTIONS:
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// EXECUTE:
$result = curl_exec($curl);
if (!$result)
{
die("Connection Failure");
}
curl_close($curl);
return $result;
}
public function getToken()
{
return $this->token_access;
}
public function setPerms()
{
return $this->perms = $this->callAPI('GET', $this->url_base.'/api/reseller/params', ['token' => $this->token_access,'host'=>$_SERVER['SERVER_NAME']]);


}
public function GetPerms()
{
$data=array();
foreach (json_decode($this->perms) as $key => $value) {

array_push($data,$value);

}
return $data;

}
public function getCdr()

{



try
{
return $this->callAPI('GET', $this->url_base.'/api/reseller/cdrs', ['token' => $this->token_access]);

}
catch(Throwable $th)
{
return $th->getMessage();
}

}
public function getNumber()
{


try
{
return $this->callAPI('GET', $this->url_base.'/api/reseller/numbers', ['token' => $this->token_access]);

}
catch(Throwable $th)
{
return $th->getMessage();
}

}
}
$token=
$secret='
try {
$data = new IvasReseller($token,$secret);
print_r($data->getCdr()) ;
} catch (\Throwable $th) {
//throw $th;
}
eXtreamSHOP
User avatar
-BlacKodE-
Super moderator
Super moderator
Posts: 1186
Joined: 16 Nov 2013, 11:57
Detinator Steam: Da
SteamID: blackode
Reputatie: Super moderator
Membru Club eXtreamCS (1 luna)
Fost Membru Club eXtreamCS (5 apr - 5 mai - acces in club)
Location: Pascani
Has thanked: 16 times
Been thanked: 10 times

05 May 2019, 10:32

Folosesti json_decode pe codul dat de tine.

Si apoi folosesti rezultatul ca array. Exemplu

$sergiu = json_decode('Cod JSON', true);

si dupa dai foreach.

foreach($sergiu as $decoded)
{
echo $decoded['Number'];
echo $decoded['Source'];
}

Nu am testat dar ar trebui sa mearga.
User avatar
L E V I N
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 2308
Joined: 24 Aug 2011, 11:24
Detinator Steam: Da
CS Status:
Detinator server CS: ☯∴
SteamID: riseofevo
Reputatie: Scripter eXtreamCS
Nume anterior: Adryyy
Location: ҳ̸Ҳ̸ҳ
Has thanked: 33 times
Been thanked: 365 times
Contact:

05 May 2019, 14:05

nu e mai rapid prin xml?
Nu fac nimic contra cost! Faceți cerere bine detaliată aici, pe forum. Nu-mi mai dați add pe Steam doar pentru a mă avea în lista de prieteni.
Am cont și activez doar aici! Aveți grijă la cei ce încearcă să mă copieze..Puteți lua legătura cu mine dacă aveți o problemă/nelămurire în acest caz.
În cazul în care utilizați ceva din addonsurile postate de mine aici, e bine să fiți la curent cu modificările aduse unor plugine, aici.
Post Reply

Return to “Discutii generale”

  • Information