Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $server = $_GET["server"];
- $login = $_GET["login"];
- $id = $_GET["id"];
- // Dane logowania
- $loginParams = array (
- "primera" => array("username" => "Veigar","password" => "veivei"),
- "suna" => array("username" => "Veigar","password" => "veivei"),
- "secura" => array("username" => "Veigar","password" => "veivei")
- );
- if(empty($server))
- {
- print_r(json_encode(array("error" => "type server name")));
- }
- elseif(!array_key_exists($server, $loginParams))
- {
- print_r(json_encode(array("error" => $server . " server is not supported")));
- }
- elseif(!empty($server))
- {
- $accessToken = getAccessToken($loginParams, $server);
- print_r(getUserInfo($id, $login, $server, $accessToken));
- }
- // Pobieranie access tokena
- function getAccessToken($loginParams, $server)
- {
- $jsonString = json_encode($loginParams[$server]);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "http://".$server.".e-sim.org/mobile/login");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($jsonString)
- ));
- $output = curl_exec($ch);
- curl_close($ch);
- //Pozycja pierwszego nawiasu - {
- $pos = strpos($output, "{");
- //JSON substring
- $substr = substr($output, $pos);
- $jsonObj = json_decode($substr);
- $access_token = $jsonObj->token;
- return $access_token;
- }
- // Pobieranie informacji o graczu
- function getUserInfo($id, $login, $server, $accessToken)
- {
- if (empty($id) && !empty($login))
- {
- $api = "profileByLogin";
- $search = $login;
- }
- elseif (!empty($id) && empty($login))
- {
- $api = "profile";
- $search = $id;
- }
- else
- {
- return json_encode(array("error" => "Nie ma takiego heheszkowania!"));
- }
- $header = array(
- sprintf('token: %s', $accessToken)
- );
- $curl = curl_init("http://". $server .".e-sim.org/mobile/".$api."/" . $search);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_POST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($curl);
- curl_close($curl);
- if(empty($result))
- return json_encode(array("error" => "No such citizen"));
- return $result;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment