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;
|
}
|
}
|