init:代码提交
parent
e16d379f70
commit
734c12e0da
|
|
@ -2,10 +2,19 @@ nacos:
|
||||||
url: 192.168.20.100:30290
|
url: 192.168.20.100:30290
|
||||||
namespace: jjb-dragon
|
namespace: jjb-dragon
|
||||||
application:
|
application:
|
||||||
name: jjb-saas-zcloud-risk
|
name: jjb-saas-zcloud-docking
|
||||||
version:
|
version:
|
||||||
gateway: risk
|
gateway: docking
|
||||||
cn-name: 风险中心
|
cn-name: 对接系统
|
||||||
|
|
||||||
|
humanresources:
|
||||||
|
appKey: A5EF205479D2DFB5E621E159AA8FF34B
|
||||||
|
appSecret: 53130AAAAC791D5B7AFD6D89C51853510190C903405242C49B83DECBBA0ADA5E
|
||||||
|
|
||||||
|
server:
|
||||||
|
port: 8090
|
||||||
|
debug: true
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: ${application.name}${application.version}
|
name: ${application.name}${application.version}
|
||||||
|
|
@ -20,7 +29,7 @@ spring:
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- config-common.yml
|
- config-common.yml
|
||||||
- config-port.yml
|
# - config-port.yml
|
||||||
- config-mq.yml
|
- config-mq.yml
|
||||||
- config-log.yml
|
- config-log.yml
|
||||||
- config-sdk-server.yml
|
- config-sdk-server.yml
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,124 @@
|
||||||
|
package com.zcloud.docking.web;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONConfig;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.zcloud.docking.config.RZConfig;
|
||||||
|
import com.zcloud.docking.utils.humanresources.SignUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lin
|
||||||
|
*/
|
||||||
|
@Api(tags = "对接人资系统")
|
||||||
|
@RequestMapping("/docking/rz")
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DockingRZController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 人资系统有可能出现空值,Hutool的JSON库在序列化对象时,遇到了无法处理的类型(例如JSONNull),导致序列化失败。
|
||||||
|
*/
|
||||||
|
private JSONConfig config;
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
// 此时所有依赖注入已完成
|
||||||
|
config = JSONConfig.create().setIgnoreNullValue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RZConfig rzConfig;
|
||||||
|
|
||||||
|
@ApiOperation("获取用户信息总条数")
|
||||||
|
@PostMapping("/getUserInfoCount")
|
||||||
|
public String getUserInfoCount() {
|
||||||
|
|
||||||
|
LinkedHashMap<String, Object> map = getRequestMap(1, 1);
|
||||||
|
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(map, false);
|
||||||
|
String a = jsonObject.toString();
|
||||||
|
|
||||||
|
System.out.println("开始调用人资系统==============================================");
|
||||||
|
String body = HttpRequest.post("https://192.168.195.249:28001/idatashare/api/remoteCall/v1/1057412621613957120")
|
||||||
|
.body(a).execute().body();
|
||||||
|
JSONObject returnJson = JSONUtil.parseObj(body, config);
|
||||||
|
System.out.println("请求返回:" + returnJson);
|
||||||
|
|
||||||
|
JSONObject boJson = new JSONObject(returnJson.get("bo"));
|
||||||
|
|
||||||
|
return boJson.get("total").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("获取用户信息")
|
||||||
|
@PostMapping("/getUserInfo")
|
||||||
|
public JSONArray getUserInfo(Integer pageNum, Integer pageSize) {
|
||||||
|
|
||||||
|
LinkedHashMap<String, Object> map = getRequestMap(pageNum, pageSize);
|
||||||
|
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(map, false);
|
||||||
|
String a = jsonObject.toString();
|
||||||
|
|
||||||
|
System.out.println("开始调用人资系统==============================================");
|
||||||
|
String body = HttpRequest.post("https://192.168.195.249:28001/idatashare/api/remoteCall/v1/1057412621613957120")
|
||||||
|
.body(a).execute().body();
|
||||||
|
JSONObject returnJson = JSONUtil.parseObj(body, config);
|
||||||
|
System.out.println("请求返回:" + returnJson);
|
||||||
|
|
||||||
|
JSONObject boJson = new JSONObject(returnJson.get("bo"));
|
||||||
|
JSONArray jsonArray = new JSONArray(boJson.get("rows"));
|
||||||
|
|
||||||
|
System.out.println(jsonArray);
|
||||||
|
return jsonArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedHashMap<String, Object> getRequestMap(Integer pageNum, Integer pageSize){
|
||||||
|
SignUtil signUtil = new SignUtil();
|
||||||
|
signUtil.setAppKey(rzConfig.getAppKey());
|
||||||
|
signUtil.setAppSecret(rzConfig.getAppSecret());
|
||||||
|
signUtil.setEnvType("online");
|
||||||
|
signUtil.setPageNum(pageNum == null ? 1 : pageNum);
|
||||||
|
signUtil.setPageSize(pageSize == null ? 200 : pageSize);
|
||||||
|
signUtil.setNonce(RandomStringUtils.randomAlphanumeric(5));
|
||||||
|
signUtil.setTimeStamp(System.currentTimeMillis());
|
||||||
|
Map<String, String> paramMap = new HashMap<>();
|
||||||
|
signUtil.setParamMap(paramMap);
|
||||||
|
List<String> orderByList = new ArrayList<>();
|
||||||
|
orderByList.add("id_card_number,DESC");
|
||||||
|
signUtil.setOrderByList(orderByList);
|
||||||
|
signUtil.buildSignatureParam();
|
||||||
|
String signature = SignUtil.getSignature(signUtil.getSignatureParam());
|
||||||
|
|
||||||
|
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("appKey", rzConfig.getAppKey());
|
||||||
|
map.put("timeStamp", signUtil.getTimeStamp());
|
||||||
|
map.put("nonce", signUtil.getNonce());
|
||||||
|
map.put("signature", signature);
|
||||||
|
map.put("signatureParam", null);
|
||||||
|
map.put("apiid", "1057412621613957120");
|
||||||
|
map.put("pageNum", signUtil.getPageNum());
|
||||||
|
map.put("pageSize", signUtil.getPageSize());
|
||||||
|
map.put("paramMap", paramMap);
|
||||||
|
map.put("orderByList", orderByList);
|
||||||
|
map.put("hasTotal", "Y");
|
||||||
|
map.put("envType", signUtil.getEnvType());
|
||||||
|
map.put("empNo", "10262589");
|
||||||
|
map.put("versionType", "published");
|
||||||
|
map.put("invokeLogId", null);
|
||||||
|
map.put("sdkType", "JAVA");
|
||||||
|
map.put("sdkVersion", "1.0.13");
|
||||||
|
map.put("accessIp", null);
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
package com.zcloud.docking.web;
|
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.cola.dto.MultiResponse;
|
|
||||||
import com.alibaba.cola.dto.PageResponse;
|
|
||||||
import com.alibaba.cola.dto.Response;
|
|
||||||
import com.alibaba.cola.dto.SingleResponse;
|
|
||||||
import com.zcloud.docking.api.RiskPointServiceI;
|
|
||||||
import com.zcloud.docking.dto.RiskPointAddCmd;
|
|
||||||
import com.zcloud.docking.dto.RiskPointPageQry;
|
|
||||||
import com.zcloud.docking.dto.RiskPointUpdateCmd;
|
|
||||||
import com.zcloud.docking.dto.clientobject.RiskPointCo;
|
|
||||||
import com.jjb.saas.framework.auth.model.SSOUser;
|
|
||||||
import com.jjb.saas.framework.auth.utils.AuthContext;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author lin
|
|
||||||
*/
|
|
||||||
@Api(tags = "风险点管理")
|
|
||||||
@RequestMapping("/risk/riskPoint")
|
|
||||||
@RestController
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class RiskPointController {
|
|
||||||
private final RiskPointServiceI riskPointService;
|
|
||||||
|
|
||||||
@ApiOperation("新增")
|
|
||||||
@PostMapping("/save")
|
|
||||||
public SingleResponse<RiskPointCo> add(@Validated @RequestBody RiskPointAddCmd cmd) {
|
|
||||||
SSOUser ssoUser = AuthContext.getCurrentUser();
|
|
||||||
return riskPointService.add(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("分页")
|
|
||||||
@PostMapping("/list")
|
|
||||||
public PageResponse<RiskPointCo> page(@RequestBody RiskPointPageQry qry) {
|
|
||||||
return riskPointService.listPage(qry);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("所有数据")
|
|
||||||
@GetMapping("/listAll")
|
|
||||||
public MultiResponse<RiskPointCo> listAll() {
|
|
||||||
return MultiResponse.of(new ArrayList<RiskPointCo>());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("详情")
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public SingleResponse<RiskPointCo> getInfoById(@PathVariable("id") Long id) {
|
|
||||||
return SingleResponse.of(new RiskPointCo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("删除")
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public Response remove(@PathVariable("id") Long id) {
|
|
||||||
riskPointService.remove(id);
|
|
||||||
return SingleResponse.buildSuccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("删除多个")
|
|
||||||
@DeleteMapping("/ids")
|
|
||||||
public Response removeBatch(@RequestParam Long[] ids) {
|
|
||||||
riskPointService.removeBatch(ids);
|
|
||||||
return SingleResponse.buildSuccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("修改")
|
|
||||||
@PutMapping("/edit")
|
|
||||||
public SingleResponse edit(@Validated @RequestBody RiskPointUpdateCmd riskPointUpdateCmd) {
|
|
||||||
riskPointService.edit(riskPointUpdateCmd);
|
|
||||||
return SingleResponse.buildSuccess();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.zcloud.docking.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author SondonYong
|
||||||
|
* @description
|
||||||
|
* @date 2025/12/2/周二 15:22
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RZConfig {
|
||||||
|
|
||||||
|
private String appKey;
|
||||||
|
private String appSecret;
|
||||||
|
|
||||||
|
public String getAppKey() {
|
||||||
|
return appKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Value("${humanresources.appKey}")
|
||||||
|
public void setAppKey(String appKey) {
|
||||||
|
this.appKey = appKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppSecret() {
|
||||||
|
return appSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Value("${humanresources.appSecret}")
|
||||||
|
public void setAppSecret(String appSecret) {
|
||||||
|
this.appSecret = appSecret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,263 @@
|
||||||
|
package com.zcloud.docking.utils.humanresources;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对接人资系统签名工具类
|
||||||
|
*/
|
||||||
|
public class SignUtil {
|
||||||
|
private String appKey;
|
||||||
|
private String appSecret;
|
||||||
|
private Integer pageNum;
|
||||||
|
private Integer pageSize;
|
||||||
|
private Map<String, String> paramMap;
|
||||||
|
private List<String> orderByList;
|
||||||
|
private Long timeStamp;
|
||||||
|
private String nonce;
|
||||||
|
private String envType;
|
||||||
|
private Map<String, Object> signatureParam;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SignUtil signUtil = new SignUtil();
|
||||||
|
signUtil.setAppKey("7401C9849D1BF3CAF796E146C7AE05AE");
|
||||||
|
|
||||||
|
signUtil.setAppSecret("29E60A33FC846468AFCCFD2576FA28120317AB8259E3D1EF9BD236422618613C");
|
||||||
|
signUtil.setPageNum(1);
|
||||||
|
signUtil.setPageSize(1000);
|
||||||
|
Map<String, String> paramMap = new HashMap<>();
|
||||||
|
//paramMap.put("status", "1");
|
||||||
|
signUtil.setParamMap(paramMap);
|
||||||
|
List<String> orderByList = new ArrayList<>();
|
||||||
|
//orderByList.add("version,DESC");
|
||||||
|
signUtil.setOrderByList(orderByList);
|
||||||
|
signUtil.setEnvType("online");
|
||||||
|
signUtil.setTimeStamp(System.currentTimeMillis());
|
||||||
|
signUtil.setNonce(RandomStringUtils.randomAlphanumeric(5));
|
||||||
|
signUtil.buildSignatureParam();
|
||||||
|
String signature = getSignature(signUtil.getSignatureParam());
|
||||||
|
System.out.println(signUtil.getTimeStamp());
|
||||||
|
System.out.println(signUtil.getNonce());
|
||||||
|
System.out.println(signature);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成签名算法,生成规则:参数+时间戳+唯一编码+AppKey+AppSecret 升序拼
|
||||||
|
* 接后通过 SHA-256 加密的得到
|
||||||
|
**/
|
||||||
|
public static String getSignature(Map<String, Object> map) {
|
||||||
|
if (CollectionUtils.isEmpty(map)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
Set<Map.Entry<String, Object>> set = map.entrySet();
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
for (Iterator<Map.Entry<String, Object>> it = set.iterator();
|
||||||
|
it.hasNext(); ) {
|
||||||
|
Map.Entry<String, Object> me = it.next();
|
||||||
|
sb.append(me.getKey()).append(me.getValue());
|
||||||
|
}
|
||||||
|
String signString = sb.toString();
|
||||||
|
if (StrUtil.isNotBlank(signString)) {
|
||||||
|
return ShaUtils.encryptBySha256(signString).toUpperCase();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buildSignatureParam() {
|
||||||
|
Map<String, Object> argsMap = new TreeMap<>();
|
||||||
|
argsMap.put(SignatureParamName.APP_KEY.getParamName(),
|
||||||
|
this.getAppKey());
|
||||||
|
argsMap.put(SignatureParamName.APP_SECRET.getParamName(),
|
||||||
|
this.getAppSecret());
|
||||||
|
argsMap.put(SignatureParamName.PAGE_NUM.getParamName(),
|
||||||
|
this.getPageNum());
|
||||||
|
argsMap.put(SignatureParamName.PAGE_SIZE.getParamName(),
|
||||||
|
this.getPageSize());
|
||||||
|
argsMap.put(SignatureParamName.PARAM_MAP.getParamName(),
|
||||||
|
this.getParamMap());
|
||||||
|
argsMap.put(SignatureParamName.ORDER_BY_LIST.getParamName(),
|
||||||
|
this.getOrderByList());
|
||||||
|
argsMap.put(SignatureParamName.TIME_STAMP.getParamName(),
|
||||||
|
this.getTimeStamp());
|
||||||
|
argsMap.put(SignatureParamName.NONCE.getParamName(),
|
||||||
|
this.getNonce());
|
||||||
|
argsMap.put(SignatureParamName.ENV_TYPE.getParamName(),
|
||||||
|
this.getEnvType());
|
||||||
|
this.signatureParam = argsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppKey() {
|
||||||
|
return appKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppKey(String appKey) {
|
||||||
|
this.appKey = appKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppSecret() {
|
||||||
|
return appSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppSecret(String appSecret) {
|
||||||
|
this.appSecret = appSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTimeStamp() {
|
||||||
|
return timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeStamp(Long timeStamp) {
|
||||||
|
this.timeStamp = timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNonce() {
|
||||||
|
return nonce;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNonce(String nonce) {
|
||||||
|
this.nonce = nonce;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPageNum() {
|
||||||
|
return pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageNum(Integer pageNum) {
|
||||||
|
this.pageNum = pageNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageSize(Integer pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getParamMap() {
|
||||||
|
return paramMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParamMap(Map<String, String> paramMap) {
|
||||||
|
this.paramMap = paramMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getOrderByList() {
|
||||||
|
return orderByList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrderByList(List<String> orderByList) {
|
||||||
|
this.orderByList = orderByList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEnvType() {
|
||||||
|
return envType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnvType(String envType) {
|
||||||
|
this.envType = envType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getSignatureParam() {
|
||||||
|
return signatureParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSignatureParam(Map<String, Object> signatureParam) {
|
||||||
|
this.signatureParam = signatureParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SignatureParamName {
|
||||||
|
/**
|
||||||
|
* appKey
|
||||||
|
*/
|
||||||
|
APP_KEY("appKey"),
|
||||||
|
/**
|
||||||
|
* pageNum
|
||||||
|
*/
|
||||||
|
PAGE_NUM("pageNum"),
|
||||||
|
/**
|
||||||
|
* pageSize
|
||||||
|
*/
|
||||||
|
PAGE_SIZE("pageSize"),
|
||||||
|
/**
|
||||||
|
* appSecret
|
||||||
|
*/
|
||||||
|
APP_SECRET("appSecret"),
|
||||||
|
/**
|
||||||
|
* paramMap
|
||||||
|
*/
|
||||||
|
PARAM_MAP("paramMap"),
|
||||||
|
/**
|
||||||
|
* orderByList
|
||||||
|
*/
|
||||||
|
ORDER_BY_LIST("orderByList"),
|
||||||
|
/**
|
||||||
|
* timeStamp
|
||||||
|
*/
|
||||||
|
TIME_STAMP("timeStamp"),
|
||||||
|
/**
|
||||||
|
* nonce
|
||||||
|
*/
|
||||||
|
NONCE("nonce"),
|
||||||
|
/**
|
||||||
|
* envType
|
||||||
|
*/
|
||||||
|
ENV_TYPE("envType");
|
||||||
|
private String paramName;
|
||||||
|
|
||||||
|
SignatureParamName(String paramName) {
|
||||||
|
this.paramName = paramName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParamName() {
|
||||||
|
return paramName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ShaUtils {
|
||||||
|
private final static String CHAR_SET_UTF8 = "UTF-8";
|
||||||
|
private final static String ALGORITHM_SHA256 = "SHA-256";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密 大小写敏感
|
||||||
|
**/
|
||||||
|
public static String encryptBySha256(String str) {
|
||||||
|
return encrypt(str, CHAR_SET_UTF8, ALGORITHM_SHA256);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String encrypt(String str, String charset, String
|
||||||
|
algorithm) {
|
||||||
|
if (StrUtil.isBlank(str)) {// throw new
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
MessageDigest messageDigest =
|
||||||
|
MessageDigest.getInstance(algorithm);
|
||||||
|
messageDigest.update(str.getBytes(charset));
|
||||||
|
return byte2Hex(messageDigest.digest());
|
||||||
|
} catch (Exception e) {// throw new
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SHA-256 将 byte 转为 16 进制
|
||||||
|
**/
|
||||||
|
private static String byte2Hex(byte[] bytes) {
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
String temp;
|
||||||
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
|
temp = Integer.toHexString(bytes[i] & 0xFF);
|
||||||
|
if (temp.length() == 1) {
|
||||||
|
stringBuffer.append("0");
|
||||||
|
}
|
||||||
|
stringBuffer.append(temp);
|
||||||
|
}
|
||||||
|
return stringBuffer.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue