回到目录
阿里短信
1. 配置文件
infra.properties 中包含以下配置项,例如:
aliyun.message.product=Dysmsapi
aliyun.message.signName=Art0X
aliyun.message.domain=dysmsapi.aliyuncs.com
aliyun.message.accessKeyId=
aliyun.message.accessKeySecret=
aliyun.message.region=cn-hangzhou
这些配置项在配置文件 infra.xml 中的“aliyunMessageServiceConfiguration”里被引用
阿里短信通过userContext中的messageService提供服务,也在配置文件infra.xml 中:
2.环境变量
出于安全考虑,一些较敏感的配置参数,例如accessKeyId 和 accessKeySecret, 可以不在代码中配置,而是通过环境变量配置,这样可以使用docker构建服务,另外也不易泄露。| 参数 | 环境变量 |
|---|---|
| accessKeyId | ALIYUN_ACCESS_KEY_ID |
| accessKeySecret | ALIYUN_ACCESS_KEY_SECRET |
3.后台使用
阿里云短信服务集成在DaaS的messageService中MessageService可以通过UserContext的sendMessage接口提供服务。参见“Lesson 3:使用和扩展UserContext”的“发送短信”, 只需简单调用接口
public void sendMessage(
String dest,
String fromWho,
String template,
Map<String, String>parameters) throws Exception;
即可
4.前台使用
发送短信,无需前台参与5.参考资料
官方文档: help.aliyun.com/document_de…