先说一下MD5加密:上代码
/** * md5 加密 * @param key 要加密的字符串 * @return */ public static String md5(String key) { if (StringUtils.isBlank(key)) { return null; } return DigestUtils.md5DigestAsHex(key.getBytes()); }
接下来说一下,
服务端返回的消息要封装成json格式的字符串,看代码:
/** * 将服务端返回的消息封装成 JSON 格式的字符串 * @param code 状态码 * @param msg 提示消息 * @param map 业务数据 * @return 返回 JSON 格式字符串 */ public static String getJSONString(int code, String msg, Map<String, Object> map) { JSONObject json = new JSONObject(); json.put("code", code); json.put("msg", msg); if (map != null) { for (String key : map.keySet()) { json.put(key, map.get(key)); } } return json.toJSONString(); } // 重载 getJSONString 方法,服务端方法可能不返回业务数据 public static String getJSONString(int code, String msg) { return getJSONString(code, msg, null); } // 重载 getJSONString 方法,服务端方法可能不返回业务数据和提示消息 public static String getJSONString(int code) { return getJSONString(code, null, null); }