【fix sonar】DySmsHelper文件
This commit is contained in:
+16
-17
@@ -1,9 +1,5 @@
|
|||||||
package com.jero.common.util;
|
package com.jero.common.util;
|
||||||
|
|
||||||
import com.jero.config.StaticConfig;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.aliyuncs.DefaultAcsClient;
|
import com.aliyuncs.DefaultAcsClient;
|
||||||
import com.aliyuncs.IAcsClient;
|
import com.aliyuncs.IAcsClient;
|
||||||
@@ -12,6 +8,10 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
|||||||
import com.aliyuncs.exceptions.ClientException;
|
import com.aliyuncs.exceptions.ClientException;
|
||||||
import com.aliyuncs.profile.DefaultProfile;
|
import com.aliyuncs.profile.DefaultProfile;
|
||||||
import com.aliyuncs.profile.IClientProfile;
|
import com.aliyuncs.profile.IClientProfile;
|
||||||
|
import com.jero.common.exception.JeroBootException;
|
||||||
|
import com.jero.config.StaticConfig;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created on 17/6/7.
|
* Created on 17/6/7.
|
||||||
@@ -26,12 +26,16 @@ import com.aliyuncs.profile.IClientProfile;
|
|||||||
*/
|
*/
|
||||||
public class DySmsHelper {
|
public class DySmsHelper {
|
||||||
|
|
||||||
|
private DySmsHelper(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private final static Logger logger=LoggerFactory.getLogger(DySmsHelper.class);
|
private final static Logger logger=LoggerFactory.getLogger(DySmsHelper.class);
|
||||||
|
|
||||||
//产品名称:云通信短信API产品,开发者无需替换
|
//产品名称:云通信短信API产品,开发者无需替换
|
||||||
static final String product = "Dysmsapi";
|
static final String PRODUCT = "Dysmsapi";
|
||||||
//产品域名,开发者无需替换
|
//产品域名,开发者无需替换
|
||||||
static final String domain = "dysmsapi.aliyuncs.com";
|
static final String DOMAIN = "dysmsapi.aliyuncs.com";
|
||||||
|
|
||||||
// TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
|
// TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
|
||||||
static String accessKeyId;
|
static String accessKeyId;
|
||||||
@@ -65,9 +69,10 @@ public class DySmsHelper {
|
|||||||
setAccessKeySecret(staticConfig.getAccessKeySecret());
|
setAccessKeySecret(staticConfig.getAccessKeySecret());
|
||||||
//update-end-author:taoyan date:20200811 for:配置类数据获取
|
//update-end-author:taoyan date:20200811 for:配置类数据获取
|
||||||
|
|
||||||
|
String hangzhou = "cn-hangzhou";
|
||||||
//初始化acsClient,暂不支持region化
|
//初始化acsClient,暂不支持region化
|
||||||
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
|
IClientProfile profile = DefaultProfile.getProfile(hangzhou, accessKeyId, accessKeySecret);
|
||||||
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
|
DefaultProfile.addEndpoint(hangzhou, hangzhou, PRODUCT, DOMAIN);
|
||||||
IAcsClient acsClient = new DefaultAcsClient(profile);
|
IAcsClient acsClient = new DefaultAcsClient(profile);
|
||||||
|
|
||||||
//验证json参数
|
//验证json参数
|
||||||
@@ -95,7 +100,8 @@ public class DySmsHelper {
|
|||||||
//hint 此处可能会抛出异常,注意catch
|
//hint 此处可能会抛出异常,注意catch
|
||||||
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
|
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
|
||||||
logger.info("短信接口返回的数据----------------");
|
logger.info("短信接口返回的数据----------------");
|
||||||
logger.info("{Code:" + sendSmsResponse.getCode()+",Message:" + sendSmsResponse.getMessage()+",RequestId:"+ sendSmsResponse.getRequestId()+",BizId:"+sendSmsResponse.getBizId()+"}");
|
String str = "{Code:" + sendSmsResponse.getCode()+",Message:" + sendSmsResponse.getMessage()+",RequestId:"+ sendSmsResponse.getRequestId()+",BizId:"+sendSmsResponse.getBizId()+"}";
|
||||||
|
logger.info(str);
|
||||||
if ("OK".equals(sendSmsResponse.getCode())) {
|
if ("OK".equals(sendSmsResponse.getCode())) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
@@ -108,15 +114,8 @@ public class DySmsHelper {
|
|||||||
String [] keyArr = keys.split(",");
|
String [] keyArr = keys.split(",");
|
||||||
for(String item :keyArr) {
|
for(String item :keyArr) {
|
||||||
if(!templateParamJson.containsKey(item)) {
|
if(!templateParamJson.containsKey(item)) {
|
||||||
throw new RuntimeException("模板缺少参数:"+item);
|
throw new JeroBootException("模板缺少参数:"+item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public static void main(String[] args) throws ClientException, InterruptedException {
|
|
||||||
// JSONObject obj = new JSONObject();
|
|
||||||
// obj.put("code", "1234");
|
|
||||||
// sendSms("13800138000", obj, DySmsEnum.FORGET_PASSWORD_TEMPLATE_CODE);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user