Signature Generation

Signature Generation Process:

  1. Sort the data fields in the request body by their field names in ascending order, then concatenate them sequentially into a single string.

  2. Use the HmacSHA256 algorithm to sign the concatenated string with the secret key (APPSECRET), generating the sign parameter.



        MchCreateOrderDto mchOrderDto = new MchCreateOrderDto();
	JSONObject mchOrderJson =  SONObject.from(mchOrderDto);

        Map<String, Object> sortedMap = new TreeMap<>(mchOrderJson);

        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, Object> entry : sortedMap.entrySet()) {
            sb.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
        }
        String signStr = sb.substring(0, sb.length() - 1);

        HMac hmac = SecureUtil.hmac(HmacAlgorithm.HmacSHA256, token.getBytes());
		String sign = hmac.digestHex(signStr);

Last updated