
公司某個(gè)線上項(xiàng)目的月短信量
經(jīng)常使用阿里產(chǎn)品的同學(xué)對(duì)于阿里的產(chǎn)品使用起來應(yīng)該是輕車熟路了。我這里就不過多的贅述了。
倉庫坐標(biāo)
<!--阿里云短信產(chǎn)品-->
<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-dysmsapi -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
<version>1.1.0</version>
</dependency>
工具類書寫
package cn.lpck.bxgg.utils;
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.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
/**
* @Author:LiuPu
* @Date:2018/11/29 23:41
* @Description:
* @Version 1.011
*/
public class SendMessageUtil {
//產(chǎn)品名稱:云通信短信API產(chǎn)品,開發(fā)者無需替換
static final String product = "Dysmsapi";
//產(chǎn)品域名,開發(fā)者無需替換
static final String domain = "dysmsapi.aliyuncs.com";
// TODO 此處需要替換成開發(fā)者自己的AK(在阿里云訪問控制臺(tái)尋找)
static final String accessKeyId = "Xxxxxxxxxxxxxxxx";
static final String accessKeySecret = "wBnxxxxxxxxxxxxxxxxxx";
//發(fā)短信
public static SendSmsResponse sendSms(String telephone,String code) throws ClientException {
//可自助調(diào)整超時(shí)時(shí)間
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
//初始化acsClient,暫不支持region化
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
//組裝請(qǐng)求對(duì)象-具體描述見控制臺(tái)-文檔部分內(nèi)容
SendSmsRequest request = new SendSmsRequest();
//必填:待發(fā)送手機(jī)號(hào)
request.setPhoneNumbers(telephone);
//必填:短信簽名-可在短信控制臺(tái)中找到
request.setSignName("短信簽名xxxxx");
//必填:短信模板-可在短信控制臺(tái)中找到
request.setTemplateCode("短信模板xxxxxxx");
//可選:模板中的變量替換JSON串,如模板內(nèi)容為"親愛的${name},您的驗(yàn)證碼為${code}"時(shí),此處的值為
request.setTemplateParam("{\"number\":\""+code+"\"}");
//hint 此處可能會(huì)拋出異常,注意catch
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
return sendSmsResponse;
}
}
控制臺(tái)模板的管理

控制臺(tái)詳細(xì)信息

短信模板詳情
創(chuàng)建模板的時(shí)候我們要在會(huì)變更信息的地方編輯我們的站位屬性,這個(gè)我在工具類的注釋上也寫的很明確了(其實(shí)注釋上的文字都是阿里云官方提供的文檔中的一些文字,我只是原封不動(dòng)的拿了過來而已)