public function CaiyunGetNow(Request $request) { header('Access-Control-Allow-Origin:*'); header("content-type:application/json"); $lon = $request->input('lon'); //经纬度数据需保留4位小数,例如:104.2569,30.6463 $lat = $request->input('lat'); if (!is_numeric($lon) || !is_numeric($lat)) { $this->throwError(501, '参数违法'); } // $url_now = 'https://api.caiyunapp.com/v2/xeeL7DagnXhxhK7u/' . $lon . ',' . $lat . '/realtime.json'; // $data_now = $this->Curlget($url_now, '', 'get'); // $data_now = json_decode($data_now); // $result = $data_now->result; $weatherData = Weather::all(); $weatherData = $weatherData->toArray(); $key = rand(0, count($weatherData) - 1); unset($weatherData[$key]['id']); $caiyunNow = $weatherData[$key]; // $caiyunNow = array( // 'temperature'=>$result->temperature, // 'humidity'=>$result->humidity, // 'precipitation'=>$result->precipitation->local->intensity, // 'wind'=>array( // 'direction'=>$result->wind->direction, // 'speed'=>$result->wind->speed // ) // ); $this->show($caiyunNow); }