Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getSpot($maps, $auth)
- {
- $url = "https://api.gojekapi.com/gofood/consumer/v3/restaurants?collection=NEAR_ME";
- $headers = array();
- $headers[] = "X-AppId: com.gojek.app";
- $headers[] = "X-AppVersion: 4.52.2";
- $headers[] = "X-PhoneModel: OPPO, CPH1609";
- $headers[] = "X-UniqueId: deb1151243984062";
- $headers[] = "X-location: ".$maps;
- $headers[] = "Authorization: Bearer ".$auth;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- $respon = curl_exec($ch);
- curl_close($ch);
- if($respon == FALSE) {
- die("Curl error : ".curl_error($ch));
- }
- $response = [
- 'data' => [
- 'cards' => []
- ]
- ];
- $data = json_decode($respon, true);
- foreach ($data['data']['cards'] as $key) {
- $main = $key['content'];
- $resto = $main['title']['text'];
- // nama alamat cordinat
- $info = $main['other_info'];
- $maps = $info['address'];
- $tikor = $info['location'];
- $buka = $info['availability']['code'];
- // jarak
- $km = $main['additional_info']['normal_text'];
- $json = [
- "title" => $resto,
- "address" => $maps,
- "location" => $tikor,
- "Status" => $buka,
- "Distance" => $km,
- ];
- // {
- // "title":"Cozy Co - Cokelat & Kopi & Boba & Tea & Dimsum, Kramat Jati",
- // "address":"Jl. Tanah Merdeka No.40A, Kramat Jati, Jakarta",
- // "location":"-6.3037226,106.8693294",
- // "Status":"OPEN",
- // "Distance":"\u2022 0.8 km"
- // }
- $response['data']['cards'][] = [
- 'nama' => $resto,
- 'alamat' => $maps,
- 'location' => $tikor,
- 'other_info' => [
- 'status' => $buka,
- 'jarak' => $km
- ]
- ];
- $out = json_encode($json);
- // print_r($out);
- }
- /**
- * jangan lupa set header ini
- * untuk ngilangin "\u2022" dari response
- */
- header("Content-type: application/json; charset=utf-8");
- echo json_encode($response);
- }
Advertisement
Add Comment
Please, Sign In to add comment