首页 >> 大全

Java后台做 短信验证码、短信通知,阿里云短信服务

2023-06-20 大全 41 作者:考证青年

Java+阿里短信实现系统登录发送验证码功能

阿里云短信服务器地址:

1、申请签名,等待审核通过

2、按需选择你要的短信类型,创建一个短信模板。

3、等待审核通过,其中“模版CODE”是我们需要的字段

4、与获取方法

以上材料准备好之后,就进入后台开发

Java后台代码

阿里云官方API:

1、pom.xml

<dependency><groupId>com.aliyungroupId><artifactId>aliyun-java-sdk-coreartifactId><version>4.0.3version>
dependency>

2、.java

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
/*** 正常报文{"Message":"OK","RequestId":"DEE155B3-80C4-46B8-B251-2D6CBCF845B1","BizId":"134918351688579152^0","Code":"OK"}*/
public class CommonRpc {public static void main(String[] args) {DefaultProfile profile = DefaultProfile.getProfile("default", "", "");IAcsClient client = new DefaultAcsClient(profile);CommonRequest request = new CommonRequest();//request.setProtocol(ProtocolType.HTTPS);request.setMethod(MethodType.POST);request.setDomain("dysmsapi.aliyuncs.com");request.setVersion("2017-05-25");request.setAction("SendSms");request.putQueryParameter("PhoneNumbers", "手机号码");request.putQueryParameter("SignName", "签名名称");request.putQueryParameter("TemplateCode", "短信模板ID");request.putQueryParameter("TemplateParam", "短信模板中对应的变量值对(json类型的参数值)");try {CommonResponse response = client.getCommonResponse(request);System.out.println(response.getData());} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}}
}

3、短信正常发送后的结果集:{“”:“OK”,“”:“-5072-4941-A7ED-”,“BizId”:“^0”,“Code”:“OK”}

4、手机收到验证码提醒

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了