Spring Boot实现阿里云SMS短信发送功能( 二 )

其中,AliSmsRequest为开放给客户端调用的参数,其定义如下所示:
@Datapublic class AliSmsRequest implements Serializable{//要接受短信的手机号private String phoneNumbers;//申请的短信签名private String signName;//申请的模板编码private String templateCode;//短信发送参数-json格式的字符串,如{"code":123456}private String templateParam;//短信发送上行编码-按照官方建议的填就行private String smsUpExtendCode;//序列id-按照官方建议的填就行private String outId;public AliSmsRequest(String phoneNumbers, String signName, String templateCode, String templateParam) {this.phoneNumbers = phoneNumbers;this.signName = signName;this.templateCode = templateCode;this.templateParam = templateParam;}public AliSmsRequest() {}}至此,我们已经将发送短信的核心代码撸完了,其中传递给服务端的参数的格式为(以发送短信验证码为例):
{"phoneNumbers":"15812490898","signName":"申请的短信签名","tempCode":"申请的短信模板编码","templateParam":"{"code":"708946"}","smsUpExtendCode":"12345678","outId":"12345678"}如果过程没有报错,不出5秒应该会收到一条短信,如下图所示:

Spring Boot实现阿里云SMS短信发送功能

文章插图
 
OK,打完收工,咱们下期再见!

【Spring Boot实现阿里云SMS短信发送功能】


推荐阅读