package cn.iocoder.yudao.module.member.util;

import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpUtil;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zt
 * @description <description class purpose>
 * @since 2024/11/13
 */

public class SmsUtil {

    private static final String USER = "yclh";
    private static final String PASS = "yclh6666";
    private static final String USERID = "1694";
    private static final String  URL= "http://120.79.149.129:7799/v2sms.aspx";


    public static void sendMsg(String mobile,String content){
        LocalDateTime now = LocalDateTime.now();

        // 定义时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

        // 将当前时间按照指定格式进行格式化
        String time = now.format(formatter);
        String sign = createSign(time);
        Map<String, Object> param = new HashMap<>();
        param.put("action","send");
        param.put("userid",USERID);
        param.put("timestamp",time);
        param.put("sign",sign);
        param.put("mobile",mobile);
        param.put("content",content);
        param.put("sendTime",null);
        param.put("extno",null);
        String s = HttpUtil.post(URL, param);
        System.out.println(s);
    }


    public static String createSign(String timestamp){
        return MD5.create().digestHex(USER+PASS+timestamp);
    }

    public static void main(String[] args) {
        sendMsg("15723110242,15213164384","这是一条测试短信2");
    }
}
