Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function handle()
- {
- $res=array();
- $data=DB::table('devices')
- ->select('name','uniqueId','lastValidLatitude as latitude','lastValidLongitude as longitude','speed','address','device_time','server_time')
- ->where('vendor',2)
- ->whereNotNull('latestPosition_id')
- ->get();
- $i=0;
- foreach ($data as $e) {
- $res[$i]['DeviceId']=$e->uniqueId;
- $res[$i]['Name']=$e->name;
- $res[$i]['lat']=$e->latitude;
- $res[$i]['lng']=$e->longitude;
- $res[$i]['TimeServer']= date('Y-m-d H:i:s');
- $res[$i]['Speed']= $e->;
- $res[$i]['GpsDateTime']= $e->device_time;
- $res[$i]['GpsDateTimeUtc']= $e->server_time;
- $res[$i]['TransferDateTimeUtc']= date('Y-m-d H:i:s');
- $url = 'https://gps.aitron.id/api/geo_address?lat='.$res[$i]['lat'].'&lon='.$res[$i]['lng'];
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $resp = curl_exec($ch);
- curl_close($ch);
- $res[$i]['alamat_sekarang'] = $resp;
- $i++;
- }
- for ($i=0; $i<count($res); $i++) {
- $ch = curl_init( "http://linfox.southeastasia.cloudapp.azure.com/LinfoxINDO/RESTServices/GPSDataService.svc/Upload" );
- $data_log_truck = array();
- $data_arr = array(
- "VehicleNumber" => $res[$i]['Name'],
- "Latitude" => $res[$i]['lat'],
- "Longitude" => $res[$i]['lng'],
- "TransferDateTime" => $res[$i]['TimeServer'],
- "Location" => $res[$i]['alamat_sekarang'],
- );
- array_push($data_log_truck, $data_arr);
- $arr_post = array("api_key"=> "pJHc9Ikc08Co4ZF9o5PE",
- "data_log_truck" => $data_log_truck);
- $payload = json_encode($arr_post);
- curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
- curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- $result = curl_exec($ch);
- curl_close($ch);
- echo "<pre>";
- print_r($result);
- \Log::info($result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement