Advertisement
aitron

Untitled

Feb 14th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. public function handle()
  2. {
  3. $res=array();
  4. $data=DB::table('devices')
  5. ->select('name','uniqueId','lastValidLatitude as latitude','lastValidLongitude as longitude','speed','address','device_time','server_time')
  6. ->where('vendor',2)
  7. ->whereNotNull('latestPosition_id')
  8. ->get();
  9. $i=0;
  10. foreach ($data as $e) {
  11. $res[$i]['DeviceId']=$e->uniqueId;
  12. $res[$i]['Name']=$e->name;
  13. $res[$i]['lat']=$e->latitude;
  14. $res[$i]['lng']=$e->longitude;
  15. $res[$i]['TimeServer']= date('Y-m-d H:i:s');
  16. $res[$i]['Speed']= $e->;
  17. $res[$i]['GpsDateTime']= $e->device_time;
  18. $res[$i]['GpsDateTimeUtc']= $e->server_time;
  19. $res[$i]['TransferDateTimeUtc']= date('Y-m-d H:i:s');
  20. $url = 'https://gps.aitron.id/api/geo_address?lat='.$res[$i]['lat'].'&lon='.$res[$i]['lng'];
  21. $ch = curl_init();
  22. curl_setopt($ch, CURLOPT_URL, $url);
  23. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  24. $resp = curl_exec($ch);
  25. curl_close($ch);
  26. $res[$i]['alamat_sekarang'] = $resp;
  27. $i++;
  28. }
  29.  
  30. for ($i=0; $i<count($res); $i++) {
  31. $ch = curl_init( "http://linfox.southeastasia.cloudapp.azure.com/LinfoxINDO/RESTServices/GPSDataService.svc/Upload" );
  32. $data_log_truck = array();
  33. $data_arr = array(
  34. "VehicleNumber" => $res[$i]['Name'],
  35. "Latitude" => $res[$i]['lat'],
  36. "Longitude" => $res[$i]['lng'],
  37. "TransferDateTime" => $res[$i]['TimeServer'],
  38. "Location" => $res[$i]['alamat_sekarang'],
  39. );
  40. array_push($data_log_truck, $data_arr);
  41. $arr_post = array("api_key"=> "pJHc9Ikc08Co4ZF9o5PE",
  42. "data_log_truck" => $data_log_truck);
  43. $payload = json_encode($arr_post);
  44. curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
  45. curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
  46. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  47. $result = curl_exec($ch);
  48. curl_close($ch);
  49. echo "<pre>";
  50. print_r($result);
  51. \Log::info($result);
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement