package com.dsk.monitor.util;

import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.dromara.sms4j.provider.enumerate.SupplierType;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @ClassName SendMessageUtil
 * @Description 发送短息
 * @Author Dgm
 * @Date 2023/12/9 14:14
 * @Version
 */
@Slf4j
public class SendMessageUtil {

    public static void sendMessage(String phones, String message) {
        String[] array = phones.split(",");
        List<String> stringList = Arrays.asList(array);
        for (String phone : stringList) {
            LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
            map.put("code", message);
            SmsBlend smsBlend = SmsFactory.createSmsBlend(SupplierType.ALIBABA);
            SmsResponse smsResponse = smsBlend.sendMessage(phone, "SMS_181860796", map);
            if (!"OK".equals(smsResponse.getCode())) {
                log.error("验证码短信发送异常 => {}", smsResponse);
            }
        }
    }
}
