header('platform', ''); if ($platform == "APP_ANDROID" || $platform == "APP_IOS") { // 密钥和加密算法 // $secretKey = 'g6R@9!zB2fL#1cVm'; // 必须是 16/24/32 位 // $cipher = 'AES-128-CBC'; // $iv = substr(md5($secretKey), 0, 16); // IV 长度必须是 16 字节 // 对 $data 进行加密处理 // $dataString = json_encode($data, JSON_UNESCAPED_UNICODE); // $encrypted = openssl_encrypt($dataString, $cipher, $secretKey, 0, $iv); return [ 'ret' => $status, // 'payload' => $data,//$encrypted, 'data' => $data, 'note' => $msg, 'ts' => time(), // 当前时间戳 ]; } $request = request(); return compact('status', 'msg', 'data'); } protected function encryption($data) { $secretKey = 'g6R@9!zB2fL#1cVm'; // 必须是 16/24/32 位 $cipher = 'AES-128-CBC'; $iv = substr(md5($secretKey), 0, 16); // IV 长度必须是 16 字节 // 对 $data 进行加密处理 $dataString = json_encode($data, JSON_UNESCAPED_UNICODE); $encrypted = openssl_encrypt($dataString, $cipher, $secretKey, 0, $iv); return $encrypted; } /** * 返回操作成功json */ protected function renderSuccess($msg = 'success', $data = []) { return json($this->renderJson(1, $msg, $data)); } /** * 返回操作失败json */ protected function renderError($msg = 'error', $data = [], $status = 0) { return json($this->renderJson($status, $msg, $data)); } /** * 返回layui.table格式的数据 */ protected function renderTable($msg = 'success', $count = 0, $data = [], $code = 0) { return json([ 'code' => $code, 'msg' => $msg, 'count' => $count, 'data' => $data ]); } /** * 获取post数据 (数组) */ protected function postData($key = null) { return $this->request->param(is_null($key) ? '' : $key . '/a'); } /** * 获取post数据 (数组) */ protected function getData($key = null) { return $this->request->get(is_null($key) ? '' : $key); } }