liujie
2025-06-16 5af3d2fa829a7a454c8ddbb6ffb2a7685ceb9c77
springcloud_k8s_panzhihuazhihuishequ/service_westcommittee/src/main/java/com/panzhihua/westcommittee/utils/AliSmsUtil.java
@@ -11,19 +11,28 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
@Slf4j
public class AliSmsUtil {
    private static final String ACCESS_KEY_ID = "LTAI5t8EwfjWRWs7tJGimAQG";
    private static final String ACCESS_KEY_SECRET = "UjuTDcXO14dSQ7STg8Pf3idjLqwx1M";
    private static final String SIGN_NAME = "花城e十";
    private static final String TIME_OUT_TEMPLATE_CODE = "SMS_479120493";
    private static final String SIGN_NAME = "攀枝花市西区玉泉街道";
    // 管理员模板
    private static final String TIME_OUT_TEMPLATE_CODE_ADMIN = "SMS_488715181";
    // 纪委模板
    private static final String TIME_OUT_TEMPLATE_CODE = "SMS_488700190";
    // 分派模板
    private static final String ASSIGN_TEMPLATE_CODE = "SMS_488670038";
    // 办结模板
    private static final String SUCCESS_TEMPLATE_CODE = "SMS_488650016";
    private static final String EXPIRE_TEMPLATE_CODE = "SMS_479510160";
    /**
     * 发送诉求超时提醒短信
@@ -33,8 +42,19 @@
    public static void  sendTimeoutMessage(List<String> phoneList, String title) {
        Map<String, String> param = new HashMap<>(3);
        param.put("title", title);
        param.put("nomber", title);
        sendBatchSms(phoneList, SIGN_NAME, TIME_OUT_TEMPLATE_CODE, param);
    }
    public static void  sendTimeoutMessageAdmin(List<String> phoneList, String title) {
        Map<String, String> param = new HashMap<>(3);
        param.put("nomber", title);
        sendBatchSms(phoneList, SIGN_NAME, TIME_OUT_TEMPLATE_CODE_ADMIN, param);
    }
    public static void  sendAssignMessageAdmin(List<String> phoneList, String title) {
        Map<String, String> param = new HashMap<>(3);
        sendBatchSms(phoneList, SIGN_NAME, ASSIGN_TEMPLATE_CODE, param);
    }
    /**
@@ -52,6 +72,15 @@
        sendBatchSms(phoneList, SIGN_NAME, EXPIRE_TEMPLATE_CODE, param);
    }
    
    public static void sendSuccessMessage(String phone) {
        Map<String, String> param = new HashMap<>(3);
        sendSms(phone,SIGN_NAME,SUCCESS_TEMPLATE_CODE,param);
    }
    public static void main(String[] args) {
        sendSuccessMessage("19915944902");
    }
    /**
     * 阿里发送短信
     *
@@ -61,7 +90,7 @@
     * @param param
     * @return
     */
    private boolean sendSms(String phone, String signName, String templateCode, Map<String, String> param) {
    private static boolean sendSms(String phone, String signName, String templateCode, Map<String, String> param) {
        // 可自助调整超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", "30000");
        System.setProperty("sun.net.client.defaultReadTimeout", "30000");
@@ -84,6 +113,7 @@
            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
            // hint 此处可能会抛出异常,注意catch
            if (StringUtils.equalsIgnoreCase("ok", sendSmsResponse.getBody().getCode())) {
                log.info("{}短信发送成功:{}", phone, sendSmsResponse.getBody().getMessage());
                return true;
            } else {
                log.error("{}短信发送失败:{}", phone, sendSmsResponse.getBody().getMessage());
@@ -140,4 +170,5 @@
        return new Client(config);
    }
}