Last active
January 3, 2016 21:51
-
-
Save Mooophy/8870a59fb3d36b72425f to your computer and use it in GitHub Desktop.
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 | |
| 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"; | |
| } | |
| ?> |
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 | |
| 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; | |
| ?> |
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 | |
| $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; | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The running result for token fetching: