Source:
public <T extends BaseRequestDto> void sign(T dto) { dto.setMerchantNo(this.bankConfig.getMerchant()); dto.setOrderNo(OrderIdGenerator.generate(redisTemplate)); Class<?> dtoClass = dto.getClass(); try { ExtMarkDto extMarkDto = new GsonBuilder().create().fromJson(dto.getExtMark(), ExtMarkDto.class); Method returnUrlMethod = dtoClass.getMethod("setReturnUrl", String.class); Method notifyUrlMethod = dtoClass.getMethod("setNotifyUrl", String.class); String returnUrl = MessageFormat.format("{0}/{1}", this.bankConfig.getCallbackReturnUrl(), extMarkDto.getApiType().name()); String notifyUrl = MessageFormat.format("{0}/{1}", this.bankConfig.getCallbackNotifyUrl(), extMarkDto.getApiType().name()); returnUrlMethod.invoke(dto, returnUrl); notifyUrlMethod.invoke(dto, notifyUrl); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) { } String originalData = gson.toJson(dto); logger.info("origin data: {}", originalData); try { byte[] signedData = originalData.getBytes("utf-8"); Signature signet = Signature.getInstance(SignatureHelper.PFX.getCert().getSigAlgName()); signet.initSign(SignatureHelper.PFX.getPrivateKey()); signet.update(signedData); String sign = this.byteToHex(signet.sign()); String signedJson = gson.toJson(Maps.newHashMap(ImmutableMap.<String, String>builder() .put("merchantNo", this.bankConfig.getMerchant()) .put("data", originalData) .put("sign", sign) .put("certInfo", this.byteToHex(SignatureHelper.PFX.getCert().getEncoded())) .build())); logger.info("origin data: {}, sign: {}", originalData, signedData); dto.setRequestData(signedJson); } catch (Exception e) { dto.setRequestData(null); logger.error(MessageFormat.format("sign error, data {}", originalData), e); } }

Target:
public <T extends BaseRequestDto> void sign(T dto) { dto.setMerchantNo(this.bankConfig.getMerchant()); dto.setOrderNo(OrderIdGenerator.generate(redisTemplate)); Class<?> dtoClass = dto.getClass(); try { ExtMarkDto extMarkDto = new GsonBuilder().create().fromJson(dto.getExtMark(), ExtMarkDto.class); Method returnUrlMethod = dtoClass.getMethod("setReturnUrl", String.class); Method notifyUrlMethod = dtoClass.getMethod("setNotifyUrl", String.class); String returnUrl = MessageFormat.format("{0}/{1}", this.bankConfig.getCallbackReturnUrl(), extMarkDto.getApiType().name().toLowerCase()); String notifyUrl = MessageFormat.format("{0}/{1}", this.bankConfig.getCallbackNotifyUrl(), extMarkDto.getApiType().name().toLowerCase()); returnUrlMethod.invoke(dto, returnUrl); notifyUrlMethod.invoke(dto, notifyUrl); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) { } String originalData = gson.toJson(dto); logger.info("origin data: {}", originalData); try { byte[] signedData = originalData.getBytes("utf-8"); Signature signet = Signature.getInstance(SignatureHelper.PFX.getCert().getSigAlgName()); signet.initSign(SignatureHelper.PFX.getPrivateKey()); signet.update(signedData); String sign = this.byteToHex(signet.sign()); String signedJson = gson.toJson(Maps.newHashMap(ImmutableMap.<String, String>builder() .put("merchantNo", this.bankConfig.getMerchant()) .put("data", originalData) .put("sign", sign) .put("certInfo", this.byteToHex(SignatureHelper.PFX.getCert().getEncoded())) .build())); logger.info("origin data: {}, sign: {}", originalData, signedData); dto.setRequestData(signedJson); } catch (Exception e) { dto.setRequestData(null); logger.error(MessageFormat.format("sign error, data {}", originalData), e); } }