package com.jkcredit.invoice.util;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

/**
 * 客户返回信息封装类
 * @author mumuxigua
 */
public class DataSignUtil {


    /**
     * 获取appSecret
     *
     * @param appKey
     * @return
     */
    public static String getAppSecret(String appKey) {
        String keyStr = "hangzhou.junxin.risk" + appKey;
        try {
            MessageDigest sha = MessageDigest.getInstance("SHA");
            byte[] byteArray = keyStr.getBytes(StandardCharsets.UTF_8);
            byte[] md5Bytes = sha.digest(byteArray);
            StringBuffer hexValue = new StringBuffer();
            for (int i = 0; i < md5Bytes.length; i++) {
                int val = ((int) md5Bytes[i]) & 0xff;
                if (val < 16) {
                    hexValue.append("0");
                }
                hexValue.append(Integer.toHexString(val));
            }
            String singKey = hexValue.toString().toUpperCase();
            return singKey;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    public static void main(String[] args) {
        String dzka = DataSignUtil.getAppSecret("dzka");
        System.out.println(dzka);
    }

}
