|
|
|
@ -12,6 +12,7 @@ import com.aliyuncs.exceptions.ClientException; |
|
|
|
|
|
|
|
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
@ -19,23 +20,23 @@ import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
@Component |
|
|
|
@AllArgsConstructor |
|
|
|
|
|
|
|
public class SmsService { |
|
|
|
public class SmsService { |
|
|
|
//private static String ACCESS_KEY_ID = "LTAI5tHsaR8S4nFH3nhchQ3Z";
|
|
|
|
|
|
|
|
//private static String ACCESS_KEY_SECRET = "PWFmEByyD5YrjMlAyioZZqLtMGxZLu";
|
|
|
|
|
|
|
|
//private static String SIGN_NAME = "阿里云短信测试";
|
|
|
|
|
|
|
|
//private static String TEMPLATE_CODE = "SMS_476455177";
|
|
|
|
|
|
|
|
// @Value("${sms.sign-name}")
|
|
|
|
|
|
|
|
// private String SIGN_NAME;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Client client; |
|
|
|
private final Client client; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
public SmsService(Client client) { |
|
|
|
|
|
|
|
this.client = client; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${sms.sign-name}") |
|
|
|
|
|
|
|
private String signName; |
|
|
|
|
|
|
|
|
|
|
|
// @Value("${sms.template-id1}")
|
|
|
|
@Value("${sms.template-id1}") |
|
|
|
// private String TEMPLATE_CODE;
|
|
|
|
private String templateCode; |
|
|
|
|
|
|
|
|
|
|
|
public void sendSms(String phoneNumber, String name) throws ClientException { |
|
|
|
public void sendSms(String phoneNumber, String name) throws ClientException { |
|
|
|
String templateCode = "SMS_476455177"; |
|
|
|
|
|
|
|
SendSmsRequest request = new SendSmsRequest(); |
|
|
|
SendSmsRequest request = new SendSmsRequest(); |
|
|
|
|
|
|
|
|
|
|
|
// 设置短信模板的参数
|
|
|
|
// 设置短信模板的参数
|
|
|
|
@ -46,7 +47,7 @@ public class SmsService { |
|
|
|
// request.putQueryParameter("SignName", SIGN_NAME);
|
|
|
|
// request.putQueryParameter("SignName", SIGN_NAME);
|
|
|
|
request.setTemplateCode(templateCode); //模板名称
|
|
|
|
request.setTemplateCode(templateCode); //模板名称
|
|
|
|
request.setTemplateParam(JSONObject.toJSONString(templateParam)); |
|
|
|
request.setTemplateParam(JSONObject.toJSONString(templateParam)); |
|
|
|
request.setSignName("实验室运维系统"); |
|
|
|
request.setSignName(signName); |
|
|
|
|
|
|
|
|
|
|
|
// 发送短信请求
|
|
|
|
// 发送短信请求
|
|
|
|
try { |
|
|
|
try { |
|
|
|
|