zjh
2025-03-25 f5e009d6c7cdb7ec64ab68feed4456fec49187b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.ltkj.web.controller.message;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teautil.models.RuntimeOptions;
import com.ltkj.web.controller.message.ALiYunSMSConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
 
@Service
public class SMSConfigServiceImpl{
    private static final Logger log = LogManager.getLogger();
    //阿里云短信服务配置类
    @Autowired
    ALiYunSMSConfig aLiYunSMSConfig;
 
 
    public SendSmsResponse sendShortMessage(SendSmsRequest sendSmsRequest) throws Exception {
        //初始化配置信息
        Client client=aLiYunSMSConfig.createClient();
        RuntimeOptions runtime = new RuntimeOptions();
 
        SendSmsResponse sendSmsResponse;
        try {
            //发送短信
            sendSmsResponse=client.sendSmsWithOptions(sendSmsRequest, runtime);
        }catch (Exception e){
            throw new Exception("调用阿里云发送短信接口失败",e);
        }
        log.info("调用阿里云发送短信接口成功");
        return sendSmsResponse;
    }
}