package com.bootdo.datas.tools;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @date 2022/3/17 14:38
 * @author wangp
 * @description
 */
public class SmsMD5 {
    public static String makeMD5(String plainText) {
        String re_md5 = new String();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes("UTF-8"));
            byte b[] = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            re_md5 = buf.toString().toLowerCase();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return re_md5;
    }

    public static void main(String[] args) {
        String cpcode = "AACCAA";
        String msg = "测试企业,测试数据,通过";
        String mobiles = "18751846061";
        String excode = "";
        String templetid = "355529";
        String key = "28e6123811f059f1faf9a14b2ff127ca";
        String md5source = cpcode + msg + mobiles + excode + templetid + key;
        String md5str = "";
        try {
            md5str = makeMD5(new String(md5source.getBytes("UTF-8"), "UTF-8")).toLowerCase();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(md5str);
    }
}
