对接阿里云短信
1.配置sdk:
<!--阿里云短信SDK-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
</dependency>
2.编写阿里云发送短信工具类
package com.base.cn.platform.os.common.utils.sms;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
/**
* 阿里短信发送工具
*/
public class ALSmsSendUtils {
private static Logger logger = LoggerFactory.getLogger(ALSmsSendUtils .class);
private static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
/**
* 阿里云短信接口
*
* @param mobile 接收人手机号码,多个号码使用','隔开
* @param content 消息内容: 验证码,提示信息等
* @param tempId 模板Id
* @param appKey
* @param appSecret
* @return
*/
static boolean aliSendMessage(String mobile, Map<String,String> content, String tempId, String appKey, String appSecret,String sig) {
try {
if (StringUtils.isEmpty(mobile) || StringUtils.isEmpty(content) || StringUtils.isEmpty(tempId)
|| StringUtils.isEmpty(appKey) || StringUtils.isEmpty(appSecret)){
logger.error("----------发送短信失败: 参数错误");
return false;
}
//初始化ascClient,暂时不支持多region(请勿修改)
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", appKey, appSecret);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");
IAcsClient acsClient = new DefaultAcsClient(profile);
//组装请求对象
SendSmsRequest request = new SendSmsRequest();
//使用post提交
request.setMethod(MethodType.POST);
/* 必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,
批量调用