get('ts'); $sign = $this->getSign($ts, 'get_config'); if ($sign != $request->get('sign')) { $this->returnJson([], 400, "签名不对"); exit; } $data = System::find(1); $arr = [ 'app_address' => $this->decry_data($data->app_address) ?: "", 'app_key' => $this->decry_data($data->app_key) ?: "", 'gui_address' => $this->decry_data($data->gui_address) ?: "", ]; $this->returnJson($arr); exit; } catch (\Exception $e) { $msg = $e->getMessage(); } $this->returnJson([], 400, $msg); exit; } public function updateConfig(Request $request){ try { $ts = $request->get('ts'); $sign = $this->getSign($ts, 'edit_config'); if ($sign != $request->get('sign')) { $this->returnJson([], 400, "签名不对"); exit; } $app_address=$request->post('app_address'); $app_key=$request->post('app_key'); $gui_address=$request->post('gui_address'); System::where(['id'=>1])->update( [ 'app_address' => $this->encry_data($app_address), 'app_key' => $this->encry_data($app_key), 'gui_address' => $this->encry_data($gui_address), ] ); $arr = [ 'app_address' => $app_address, 'app_key' => $app_key, 'gui_address' => $gui_address, ]; $this->returnJson($arr); exit; } catch (\Exception $e) { $msg = $e->getMessage(); } $this->returnJson([], 400, $msg); } private function getSign($ts,$api): string { $sinArr = [ 'secret' => config('secret.sign_key') , 'ts' => $ts, 'api' => $api, ]; $str = implode("|", $sinArr); return md5($str); } private function returnJson($data,$code=200,$msg=""){ $data = [ 'code' => $code, 'msg' => $msg, 'data' => (object)$data, ]; echo json_encode($data, 256); exit; } private function encry_data($data){ $key = config('secret.encry_key'); return openssl_encrypt($data, 'AES-256-ECB', $key); } private function decry_data($endata){ $key = config('secret.encry_key'); return openssl_decrypt($endata, 'AES-256-ECB', $key); } }