代码拉取完成,页面将自动刷新
阿里云短信服务 spring-boot-starter。
JDK 版本: 11
Spring Boot 版本: 2.7.2
配置(application.properties
)
aliyun.sms.accessKeyId=accessKeyId # 访问key(必)
aliyun.sms.accessKeySecret=accessKeySecret # 访问密钥(必)
aliyun.sms.signature=signature # 短信签名(必)
aliyun.sms.templates.templateCode1=templateCode1 # 短信模板编号和对应的短信模板变量(至少要配置一个键值对)
aliyun.sms.templates.templateCode2=templateCode2
代码使用
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import super9du.sia.aliyun.sms.AliyunSmsTemplate;
class Demo {
/**
* 获取阿里云 sms 原生的客户端对象
*/
@Inject
Client client;
@Inject
AliyunSmsTemplate template;
void test() throws Exception {
// 如果只配置了一个「短信模板编号」,那么可以直接使用 sendAuthCode 发送验证码
SendSmsResponse resp1 = template.sendAuthCode("13245678901");
// 使用阿里云原生的客户端能力
client.sendSms(template.createSendSmsRequest("短信模板编号", "13245678901", "{\"code\":\"1234\"}"));
// client.xxx()
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。