sys_key; $sys_name = $request->sys_name; if (!isset($sys_key) || !isset($sys_name)) { return $this->error(-1, '参数错误'); } $db_conf = config('database'); $api_url = 'http://'.$db_conf['python_api'][$sys_key]['url'].'/get/?sys_key='.$sys_key.'&sys_name='.$sys_name; $response = $this->request_post($api_url); if (gettype($response) == 'integer') { switch ($response) { case 3: $error_info = 'CURLE_URL_MALFORMAT'; break; case 7: $error_info = 'CURLE_COULDNT_CONNECT'; break; default: $error_info = '未知错误:'.$response; } return $this->error($response, $error_info); } else { $data = json_decode($response); // $data = $this->data_process($data); // dd($data); // return $data; if ($data == null) { return $this->error(500, preg_replace('/<[^>]*>/','',$response)); } else { return $this->success($data); } } } private function request_post($url = '', $param = '') { if (empty($url)) { return false; } $postUrl = $url; $curlPost = $param; $curl = curl_init();//初始化curl curl_setopt($curl, CURLOPT_URL,$postUrl);//抓取指定网页 curl_setopt($curl, CURLOPT_HEADER, 0);//设置header curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上 curl_setopt($curl, CURLOPT_POST, 1);//post提交方式 curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);//提交的参数 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); $data = curl_exec($curl);//运行curl $errno = curl_errno($curl); curl_close($curl); if ($errno > 0) return $errno; return $data; } private function data_process($data) { $data = is_object($data) ? get_object_vars($data) : $data; $data_arr = []; foreach ($data as $key => $val) { $arr = is_object($val) ? get_object_vars($val) : $val; if (is_array($arr)) { $arr = $this->data_process(($arr)); // dd($arr); } // $arr[$key] = round($val, 2); $data_arr[$key] = $arr; if (isset($data_arr['val']) && $data_arr['val'] != '') { $data_arr[$key] = round($data_arr['val'], 2); } } return $data_arr; // dd($arr); // $data = (array)$data; // $process_arr = []; // foreach ($data as $key=>$val ) { // if ($val) // if ($val == 'val') { // $data[$key] = round($val); // return; // } //// foreach ($val as $k=>$v) { //// $this->data_process($v); //// $vv = (array)$v; //// dd($vv['val']); //// } //// $dd = (array)$val; //// $process_arr[$key] = $this->data_process($val); //// print(gettype($this->data_process($val))); // //// if ($child_data['val']) { //// $child_data['val'] = round($child_data, 2); //// } //// dd($data[$key]); //// dd(round($data[$key]['val'], 2)); // } // return $process_arr; } /** * Display a listing of the resource. * @return Renderable */ public function index() { return view('opcdata::index'); } /** * Show the form for creating a new resource. * @return Renderable */ public function create() { return view('opcdata::create'); } /** * Store a newly created resource in storage. * @param Request $request * @return Renderable */ public function store(Request $request) { // } /** * Show the specified resource. * @param int $id * @return Renderable */ public function show($id) { return view('opcdata::show'); } /** * Show the form for editing the specified resource. * @param int $id * @return Renderable */ public function edit($id) { return view('opcdata::edit'); } /** * Update the specified resource in storage. * @param Request $request * @param int $id * @return Renderable */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * @param int $id * @return Renderable */ public function destroy($id) { // } }