code(200); } } if (!function_exists('jsonResponse')) { function jsonResponse($data, $code = '200', $message = 'ok') { return \think\Response::create(['code' => $code, 'message' => $message, 'data' => $data], 'json')->code(200); } } if (!function_exists('createToken')) { function createToken($data): string { $content = [ 'iss' => request()->domain(), 'exp' => time() + 3600 * 12, 'data' => $data ]; $key = env('jwt_token_key'); return \Firebase\JWT\JWT::encode($content, $key, 'HS256'); } } if (!function_exists('getDataByToken')) { function getDataByToken($token) { try { $key = env('jwt_token_key'); $data = \Firebase\JWT\JWT::decode($token, new \Firebase\JWT\Key($key, 'HS256')); return (array)$data; } catch (\Firebase\JWT\ExpiredException $exception) { return 'token has expired'; } catch (\Firebase\JWT\SignatureInvalidException $exception) { return 'token is not invalidate'; } catch (Exception $e) { return $e->getMessage(); } } } if (!function_exists('responseOk')) { function responseOk($data = []): \think\Response { return json_response(['code' => \app\config\BusinessCode::SUCCESS, 'message' => "ok", 'data' => $data]); } } if (!function_exists("niceDump")) { function niceDump($data, $isTruncate = true) { echo "
";
        var_dump($data);
        echo "
"; $isTruncate && die; } } if (!function_exists('createOrderNo')) { function createOrderNo($id) { return date_create()->format('ymdHisu') . substr($id, -2); } } if (!function_exists('devAuth')) { function devAuth() { return env('devAuth', false); } } if (!function_exists('response_json')) { /** * @describe 请求返回 * @param array $data * @param int $code * @param string $msg * @param array $header * @return \think\Response */ function response_json($data = [], int $code = \app\config\ResponseCode::SUCCESS, string $msg = '操作成功', array $header = []): \think\Response { return json(['code' => $code, 'message' => $msg, 'data' => $data], 200, $header); } }