调用短信接口发送验证码,并对验证码进行验证

本文介绍了如何封装短信接口来发送验证码,并详细讲解了前后台交互过程。首先,展示了发送短信的工具类,接着说明了前台如何发起请求,后台如何响应以发送验证码。最后,阐述了验证码验证的流程,包括前台请求验证和后台验证响应,从而完成整个发送及验证功能。
摘要由CSDN通过智能技术生成
  • 首先需要对短信接口内容进行封装: 
public class SendMsg2Util {
    private static String url="http://gw.api.taobao.com/router/rest";
    private static String appkey="xxxxxxxx";
    private static String secret="xxxxxxxx";

    public void sendMsg(String name,String phone,String vcode) throws ApiException{
        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        req.setExtend("XXX");
        req.setSmsType("normal");
        req.setSmsFreeSignName("注册验证");
        req.setSmsParamString("{\"name\":\""+name+"\",\"code\":\""+vcode+"\"}");
        req.setRecNum(phone);
        req.setSmsTemplateCode("SMS_11415328");
        AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
        System.out.println(phone+"]验证码:"+vcode+">"+rsp.getMsg());
    }

    public void sendMsg(String name,String phone) throws ApiException{
        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        req.setExtend("XXX");
        req.setSmsType("normal");
        req.setSmsFreeSignName("变更验证");
        req.setSmsParamString("{\"name\":\""+name+"\",\"phone\":\""+phone+"\"}");
        req.setRecNum(phone);
        req.setSmsTemplateCode("SMS_11535513&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值