|
@@ -14,7 +14,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
@Log4j2
|
|
|
-@Component
|
|
|
+//@Component
|
|
|
public class SmsService {
|
|
|
|
|
|
//初始化ascClient需要的几个参数
|
|
@@ -24,6 +24,46 @@ public class SmsService {
|
|
|
private static final String accessKeySecret = "JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4";//你的accessKeySecret,参考本文档步骤2
|
|
|
private static final String signName = "四维看房";
|
|
|
|
|
|
+ public static boolean sendSmsWithSignName(String phoneNum, String templateParam,
|
|
|
+ String templateCode , String tmpSignName) {
|
|
|
+ // 可自助调整超时时间
|
|
|
+ System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
|
|
|
+ System.setProperty("sun.net.client.defaultReadTimeout", "10000");
|
|
|
+ boolean result = false;
|
|
|
+ try {
|
|
|
+ // 初始化acsClient,暂不支持region化
|
|
|
+ IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
|
|
|
+ DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
|
|
|
+ IAcsClient acsClient = new DefaultAcsClient(profile);
|
|
|
+
|
|
|
+ // 组装请求对象-具体描述见控制台-文档部分内容
|
|
|
+ SendSmsRequest request = new SendSmsRequest();
|
|
|
+
|
|
|
+ // 必填:待发送手机号
|
|
|
+ request.setPhoneNumbers(phoneNum);
|
|
|
+ // 必填:短信签名-可在短信控制台中找到
|
|
|
+ request.setSignName(tmpSignName);
|
|
|
+ // 必填:短信模板-可在短信控制台中找到
|
|
|
+ request.setTemplateCode(templateCode);
|
|
|
+
|
|
|
+ // 可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
|
|
|
+ request.setTemplateParam(templateParam);
|
|
|
+
|
|
|
+
|
|
|
+ // hint 此处可能会抛出异常,注意catch
|
|
|
+ SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
|
|
|
+ if (sendSmsResponse != null
|
|
|
+ && !StringUtils.isEmpty(sendSmsResponse.getCode())
|
|
|
+ && "OK".equals(sendSmsResponse.getCode())){
|
|
|
+ log.debug("阿里云短信发送成功");
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ }catch (ClientException e){
|
|
|
+ log.error("阿里云短信发送成功:" + e);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
public static boolean sendSms(String phoneNum, String templateParam, String templateCode) {
|
|
|
// 可自助调整超时时间
|
|
|
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
|
|
@@ -131,10 +171,14 @@ public class SmsService {
|
|
|
String code = String.valueOf((int)((Math.random()*9+1)*100000));
|
|
|
System.out.println(code);
|
|
|
|
|
|
+ String sceneNum = "sk-uyvpOD4vK";
|
|
|
/**
|
|
|
* 四维看看:SMS_126461520
|
|
|
* 四维看房:SMS_184616399
|
|
|
*/
|
|
|
- sendSms("15015980188","{\"code\":\"" + code + "\"}", "SMS_184616399");
|
|
|
+ //sendSms("18718487619","{\"code\":\"" + code + "\"}", "SMS_184616399");
|
|
|
+
|
|
|
+// System.out.println(sendSmsWithSignName("18819272208" , "{\"sceneNum\":\"" + sceneNum + "\"}" ,
|
|
|
+// "SMS_201717882","四维看看Sketch"));
|
|
|
}
|
|
|
}
|