Skip to content

Instantly share code, notes, and snippets.

@Mooophy
Last active January 3, 2016 21:51
Show Gist options
  • Select an option

  • Save Mooophy/8870a59fb3d36b72425f to your computer and use it in GitHub Desktop.

Select an option

Save Mooophy/8870a59fb3d36b72425f to your computer and use it in GitHub Desktop.
<?php
date_default_timezone_set ("Pacific/Auckland");
$url = 'https://wholesale.layer2.co.nz/api/login';
$content = array('username' => 'omnitech.b2b', 'password' => 'Omnit3ch1119');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n} ",
'method' => 'POST',
'content' => http_build_query($content),
),
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
var_dump($response);
echo '<hr>';
$json = json_decode($response,true);
var_dump($json);
echo '<hr>';
if ($json['status'] == 1)
{
$token = $json['data']['token'];
echo $token;
} else
{
echo "Invalid Username or Password";
}
echo '<hr><hr><hr>';
$fdate = '2015-10-01';
$tdate = '2015-10-02';
$url = "https://wholesale.layer2.co.nz/api/cdr/record?token=$token&from=$fdate&to=$tdate";
echo $url;
echo '<hr>';
$content = array('token' => $token, 'from' => $fdate, 'to' => $tdate);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n} ",
'method' => 'GET',
'content' => http_build_query($content),
),
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$json_a = json_decode($response, true);
if ($json_a['status'] == 1) {
echo $response;
} else {
echo "Invalid token";
}
?>
<?php
echo '<hr><h3>'.'Response from the server'.'</h3>';
$url = 'https://wholesale.layer2.co.nz/api/login';
$content = array('username' => 'omnitech.b2b', 'password' => 'Omnit3ch1119');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($content),
),
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
var_dump($response);
echo '<hr><h3>'.'Array converted from the response'.'</h3>';
$arr = json_decode($response, true);
var_dump($arr);
echo '<hr><h3>'.'Token from the array'.'</h3>';
$tok = $arr['data']['token'];
var_dump($tok);
echo $tok;
?>
<?php
$url = 'https://wholesale.layer2.co.nz/api/login';
$content = array('username' => 'omnitech.b2b', 'password' => 'Omnit3ch1119');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($content),
),
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
echo $response;
?>
@Mooophy
Copy link
Copy Markdown
Author

Mooophy commented Jan 2, 2016

The running result for token fetching:

result_for_token_parsing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment