Advertisement
adhieresthenes

API Test

Sep 25th, 2017
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.87 KB | None | 0 0
  1. <?php
  2. /*****************************************
  3. *   API Version : 0.1
  4. *   API Service : Operational Back Office Server
  5. ******************************************/
  6.  
  7. //load database config and other data libs
  8. require_once ("../../app/config/config.php");
  9. require_once ("../../app/general/Security.php");
  10. require      ("../../app/securimage/Securimage.php");
  11. //require_once ("../../app/config/FUnction_connect.php");
  12.  
  13.  
  14. //API CALL DATA EXAMPLE & TEST
  15. /************************************
  16. ** Developer can modified these code if it neccessary, otherwise you can ignore it.
  17. ** User data from DB being parsed to json data!
  18. ** password decryptor https://md5hashing.net/hash
  19. /************************************/
  20.  
  21. $act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';
  22.    
  23.     switch ($act) {
  24.         /*case 'registration':
  25.             //registration
  26.             # code...
  27.             $idobu = ($_REQUEST['nomorobu']);
  28.             $vehicenum = strtolower($_REQUEST['nomorobu']);
  29.             $username = strtolower($_REQUEST['nomorkendaraan']);
  30.             $email = strtolower($_REQUEST['email']);
  31.             $password = $_REQUEST['password'];
  32.             $handphone = $_REQUEST['mobnumb'];
  33.             break;*/
  34.  
  35.     /*  case 'login':
  36.             //login validation is to check user accounts validation
  37.             # code...
  38.             $id = empty($_REQUEST['id']);
  39.             $user = $_REQUEST['username'];
  40.             $pass = ($_REQUEST['password']);  
  41.             $password = hash('sha512', $pass);
  42.            
  43.        
  44.             //query = ("SELECT * from m_user");
  45.             $stmt = $mysqli->prepare("SELECT id, username, password, salt
  46.             FROM m_user
  47.             WHERE (email = ? OR username = ?) AND active = 1
  48.             LIMIT 1");
  49.            
  50.             $stmt->bind_param('ss', $email, $user);
  51.            
  52.             $stmt->execute();    // Execute the prepared query.
  53.             $stmt->store_result();
  54.      
  55.             // get variables from result.
  56.             $stmt->bind_result($user_id, $username, $db_password, $salt);
  57.             $stmt->fetch();
  58.  
  59.             // hash the password with the unique salt.
  60.             $password = hash('sha512', $password . $salt);
  61.  
  62.             //query
  63.             $query = ("SELECT * FROM m_user WHERE username='$user' AND password='$password' ");
  64.                
  65.            
  66.             $result = $mysqli->query($query);
  67.             $data = array();
  68.             while ($row = mysqli_fetch_assoc($result)){
  69.                
  70.                 $data[]= array(
  71.                     "id" => $row['id'],
  72.                     "username" => $row['username'],
  73.                     "password" => $row['password'],
  74.                    
  75.                     );
  76.             }
  77.  
  78.              if(!empty($data)){
  79.  
  80.             //respon data
  81.             $json = array(
  82.                 'status' => 'success, 200',
  83.                 'data' => $data
  84.             );
  85.  
  86.             }else{
  87.  
  88.             $json = array(
  89.                         'status' => 'error, 400',
  90.                         'msg' => 'wrong username or password ',
  91.                         );
  92.             }
  93.               echo json_encode($json);
  94.            
  95.             break;*/
  96.            
  97.         case 'validation':
  98.             # this code to check registered obu and validate obu id on server
  99.             $id = $_REQUEST = ['id'];
  100.             $obuid = $_REQUEST = ['obu_id'];
  101.             $noplat = $_REQUEST = ['no_plat'];
  102.             $timestamp = date('Y-m-d H:i:s');
  103.  
  104.             //$query = ("SELECT * FROM obu_registered(id,obu_id,no_plat, date) VALUES ('$id', '$obu_id', '$no_plat', 'NOW()'");
  105.  
  106.             $query = ("SELECT * FROM 'obu_registered' WHERE obu_id ='$obuid' AND no_plat ='$noplat' AND timestamp = '$timestamp'");
  107.  
  108.             $result = $mysqli->query($query);
  109.             //$data = array();
  110.             while ($row = mysqli_fetch_assoc($result)){
  111.                
  112.                 $data[]= array(
  113.                     "id" => $row['id'],
  114.                     "obuid" => $row['obu_id'],
  115.                     "noplat" => $row['no_plat'],
  116.                     "time" => $row['Y-m-d H:i:s'],
  117.                    
  118.                     );
  119.             }
  120.  
  121.              $json = array(
  122.                             'status' => 'OK, 200',
  123.                             'msg' => 'Registered OBU & plat number',
  124.                             );
  125.  
  126.             echo json_encode($json);
  127.  
  128.             /*
  129.             //checking
  130.             if(($obuid === $row['obu_id']) && ($noplat === $row['no_plat']) === true)
  131.             {
  132.                  $json = array(
  133.                             'status' => 'OK, 200',
  134.                             'msg' => 'Registered OBU & plat number',
  135.                             );
  136.             }
  137.             elseif(($obuid === $row['obu_id']) && ($noplat !== $row['noplat']) === false)
  138.             {
  139.                  $json = array(
  140.                             'status' => 'NOK, 400',
  141.                             'msg' => 'unregistered plat number',
  142.                             );  
  143.             }
  144.             elseif(($obuid !== $row['obu_id']) && ($noplat === $row['noplat']) === false)
  145.             {
  146.                 $json = array(
  147.                             'status' => 'NOK, 400',
  148.                             'msg' => 'unregistered OBU',
  149.                             );
  150.             }
  151.             else(($obuid !== $row['obu_id']) && ($noplat !== $row['noplat']) === false);
  152.             {
  153.                 $json = array(
  154.                             'status' => 'NOK, 400',
  155.                             'msg' => 'unregistered OBU & plat number',
  156.                             );
  157.             }
  158.             */
  159.            
  160.  
  161.             break;
  162.  
  163.         default:
  164.             # code...
  165.             echo "akhir";
  166.             break;
  167.     }
  168.  
  169. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement