ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 ``` /** * <b>方法描述:</b> MD5计算签名 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 18:12:07 <br/> * * @param contants * 入参|待编码数据(byte数组或字符串)|{@link Object} * @param isfile * 入参|是否是对文件编码|{@link boolean} * @param codeset * 入参|字符串编码(UTF-8或GBK)|{@link java.lang.String} * @param md5txt * 出参|MD5签名内容|{@link java.lang.String} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "MD5计算签名", style = "判断型", type = "同步组件", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 06:12:07") @InParams(param = { @Param(name = "contants", comment = "待编码数据(byte数组或文件名)", type = Object.class), @Param(name = "isfile", comment = "是否是文件", type = boolean.class), @Param(name = "codeset", comment = "字符串编码(UTF-8或GBK)", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "md5txt", comment = "MD5签名内容", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_md5Enc(Object contants, boolean isfile, String codeset) { if (contants == null) { return ResultBase.newFailureResult("TPTS0005", "待编码内容不能为空"); } String strErr = ""; try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte by[] = null; if (isfile) { String fileName = contants.toString(); File file = new File(fileName); FileInputStream fis = new FileInputStream(file); byte[] buffer = new byte[(int) file.length()]; fis.read(buffer); fis.close(); by = md5.digest(buffer); } else { if (contants instanceof String) { by = md5.digest(((String) contants).getBytes(codeset)); } else if (contants instanceof byte[]) { by = md5.digest((byte[]) contants); } } if (by != null) { String strRet = ""; for (int i = 0; i < by.length; i++) strRet += Integer.toString(0x200 + by[i], 16).substring(1); return ResultBase.newSuccessResult(strRet); } else { strErr = "不支持对输入对象进行MD5编码"; } } catch (Exception ex) { AppLog.error(ex); strErr = AppLog.errorMsg(ex); } return ResultBase.newExceptionResult("TPTS0006", "MD5计算签名出现异常:" + strErr); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/d4/36/d4363ab5d849e5f7eafaf23cd3c288ff_1868x890.png) # 参数说明及示例 ## 入口参数 待编码数据(byte数组或文件名):输入一个 byte 数组或者文件绝对路径,示例: `"D:\\work\\CQYY\\workspace\\123.txt"` 是否是文件:设置是否是文件,示例: `true` 字符串编码(UTF-8或GBK):设置编码格式,示例: `"utf-8"` ## 出口参数 MD5签名内容:经过编码后的内容,示例: `__INNER__["result"]`