anggagewor

Untitled

Oct 17th, 2022
1,664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2. function getSpot($maps, $auth)
  3. {
  4.   $url = "https://api.gojekapi.com/gofood/consumer/v3/restaurants?collection=NEAR_ME";
  5.   $headers = array();
  6.   $headers[]  = "X-AppId: com.gojek.app";
  7.   $headers[]  = "X-AppVersion: 4.52.2";
  8.   $headers[]  = "X-PhoneModel: OPPO, CPH1609";
  9.   $headers[]  = "X-UniqueId: deb1151243984062";
  10.   $headers[]  = "X-location: ".$maps;
  11.   $headers[]  = "Authorization: Bearer ".$auth;
  12.  
  13.   $ch = curl_init();
  14.   curl_setopt($ch, CURLOPT_URL, $url);
  15.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  16.   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  17.   $respon = curl_exec($ch);
  18.   curl_close($ch);
  19.  
  20.   if($respon == FALSE) {
  21.     die("Curl error : ".curl_error($ch));
  22.   }
  23.   $response = [
  24.     'data' => [
  25.       'cards' => []
  26.     ]
  27.   ];
  28.   $data = json_decode($respon, true);
  29.   foreach ($data['data']['cards'] as $key) {
  30.     $main = $key['content'];
  31.     $resto  = $main['title']['text'];
  32.     // nama alamat cordinat
  33.     $info   = $main['other_info'];
  34.     $maps   = $info['address'];
  35.     $tikor  = $info['location'];
  36.     $buka   = $info['availability']['code'];
  37.     // jarak
  38.     $km = $main['additional_info']['normal_text'];
  39.    
  40.     $json = [
  41.       "title"     => $resto,
  42.       "address"   => $maps,
  43.       "location"  => $tikor,
  44.       "Status"    => $buka,
  45.       "Distance"  => $km,
  46.     ];
  47.     // {
  48.     //   "title":"Cozy Co - Cokelat & Kopi & Boba & Tea & Dimsum, Kramat Jati",
  49.     //   "address":"Jl. Tanah Merdeka No.40A, Kramat Jati, Jakarta",
  50.     //   "location":"-6.3037226,106.8693294",
  51.     //   "Status":"OPEN",
  52.     //   "Distance":"\u2022 0.8 km"
  53.     // }
  54.     $response['data']['cards'][] = [
  55.       'nama' => $resto,
  56.       'alamat' => $maps,
  57.       'location' => $tikor,
  58.       'other_info' => [
  59.         'status' => $buka,
  60.         'jarak' => $km
  61.       ]
  62.  
  63.     ];
  64.     $out = json_encode($json);
  65.     // print_r($out);
  66.   }
  67.   /**
  68.    * jangan lupa set header ini
  69.    * untuk ngilangin "\u2022" dari response
  70.    */
  71.   header("Content-type: application/json; charset=utf-8");
  72.   echo json_encode($response);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment