public static String toHex(String str){ try { byte[] bytes = str.getBytes("GBK"); StringBuilder sb = new StringBuilder(bytes.length * 2); //转换hex编码 for (byte b : bytes) { sb.append(Integer.toHexString(b + 0x800).substring(1)); } return sb.toString(); } catch (UnsupportedEncodingException e) { log.error(e); } return null; }