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->speed;
- // $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++;
- // }
- $dataToUpload=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;
- $parentData = [
- "GPSProvider"=>"Kabut",
- "Username"=>"Kabut",
- "Password"=>"P@ssw0rd",
- "DataToUpload" => []
- ];
- foreach ($data as $e) {
- $dataToUpload[] = [
- 'DeviceId' => $e->uniqueId,
- 'Name' => $e->name,
- 'lat' => $e->latitude,
- 'lng' => $e->longitude,
- 'TimeServer' => date('Y-m-d H:i:s'),
- 'Speed' => $e->speed,
- 'GpsDateTime' => $e->device_time,
- 'GpsDateTimeUtc' => $e->server_time,
- 'TransferDateTimeUtc' => date('Y-m-d H:i:s')
- ];
- }
- //ini data masih berupa array php
- $parentData["DataToUpload"] = $dataToUpload;
- //jadikan fromat json, data ini yg akan di lemparkan ke api pakai curl
- $data = json_encode($parentData);
- for ($i=0; $i<count($dataToUpload); $i++) {
- $ch = curl_init( "http://linfox.southeastasia.cloudapp.azure.com/LinfoxINDO/RESTServices/GPSDataService.svc/Upload" );
- $parentData = array(
- "VehicleNumber" => $dataToUpload[$i]['Name'],
- "Latitude" => $dataToUpload[$i]['lat'],
- "Longitude" => $dataToUpload[$i]['lng'],
- "TransferDateTime" => $dataToUpload[$i]['TimeServer'],
- "Location" => 'Testing',
- );
- $payload = json_encode($dataToUpload);
- 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