官方提供的签名和验签方法,替换上自己的支付系统秘钥 SALT
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.stream.Collectors;
public class DouYinSign {
/**
* 担保支付请求不参与签名参数
* app_id 小程序appID
* thirdparty_id 代小程序进行该笔交易调用的第三方平台服务商id
* sign 签名
* other_settle_params 其他分账方参数
*
* Guaranteed payment requests do not participate in signature parameters
* app_id Applets appID
* thirdparty_id The id of the third-party platform service provider that calls the transaction on behalf of the Applets
* sign sign
* other_settle_params Other settle params
*/
public final static List<String> REQUEST_NOT_NEED_SIGN_PARAMS = Arrays.asList("app_id", "thirdparty_id", "sign", "other_settle_params");
/**
* 支付密钥值,需要替换为自己的密钥(完成进件后,开发者可在字节开放平台-【某小程序】-【功能】-【支付】-【担保交易设置】中查看支付系统秘钥 SALT)
*
* Payment key value, you need to replace it with your own key
*/
private static final String SALT = "支付系统秘钥 SALT";
/**
* RequestSign 担保支付请求签名算法
* @param paramsMap {@code Map<String, Object>} 所有的请求参数
* @return:签名字符串
*
* RequestSign Guaranteed payment request signature algorithm
* @param paramsMap {@code Map<String, Object>} all request parameters
* @return: Signature string
*/
public static String requestSign(Map<String, Object> paramsMap) {
List<String> paramsArr = new ArrayList<>();
for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
String key = entry.getKey();
if (REQUEST_NOT_NEED_SIGN_PARAMS.contains(key)) {
continue;
}
String value = entry.getValue().toString();
value = value.trim();
if (value.sta