Home > Java > javaTutorial > Alibaba's tutorial guide for sending text messages

Alibaba's tutorial guide for sending text messages

巴扎黑
Release: 2017-07-22 14:05:58
Original
1824 people have browsed it

Alibaba sends text messages:

Preparation work:

(1) Application management——> Application list——> Create an application to obtain the APP Key and APP Secret

(2) Obtain the SMS signature and SMS template

The SMS template after the preparation is completed

After the preparation work is completed, implement it in the program:

import com.taobao.api.DefaultTaobaoClient;import com.taobao.api.TaobaoClient;import com.taobao.api.request.AlibabaAliqinFcFlowChargeProvinceRequest;import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;public class ceshi {public static void main(String[] args) {// TODO Auto-generated method stub/*//官网的url,http请求,正式环境地址
        String url = "";
        //Top分配给应用的APPKey
        String appkey = "23859907";
        //Top分配给应用的密匙
        String secret = "3249c3b6a29aee38a6c9c63a9093a314";
        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
        //实例化请求
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        //公共会穿参数,在“消息返回”中会透传回改参数
        req.setExtend("123456");
        //(必写)短信类型,传入值填写normal
        req.setSmsType("normal");
        //(必写)短信签名,传入的短信签名必须是在阿里大鱼“管理中心-短信签名管理”中可用的签名
        req.setSmsFreeSignName("羽品测试");
        //短信模板变量,传参规则{"key","value"}
//        req.setSmsParamString("自己的变量");
        //(必写)短信接收号码,支持单个或多个手机号码,多个手机号码间用英文逗号隔开
        req.setRecNum("15387108387");
        //短信模板ID,使用的模板必须在阿里大于“管理中心-短信模板管理”中的可用模板
        req.setSmsTemplateCode("自己的模板ID");
        //实例化响应
        AlibabaAliqinFcSmsNumSendResponse res = new AlibabaAliqinFcSmsNumSendResponse();
        System.out.println(res.getBody());*//** * 短信验证码         *///1.获取手机号、输入的验证码//2.生成随机验证码//3.调用短信接口,发送验证码短信//4.比较页面传过来的验证码与随机生成的验证码是否相等         // 官网的URL   String rusult = null;// 官网的URLString url = "http://gw.api.taobao.com/router/rest";// 成为开发者,创建应用后系统自动生成String appkey = "23859907";
            String secret = "3249c3b6a29aee38a6c9c63a9093a314";
            String number = "520";
            TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
            AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
            req.setExtend("123456");
            req.setSmsType("normal");
            req.setSmsFreeSignName("羽品测试");
            req.setSmsParamString("{\"number\":\"1234\"}");
            req.setRecNum("15387108387");
            req.setSmsTemplateCode("SMS_67785100");try {
                AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
                System.out.println(rsp.getBody());  
                rusult = rsp.getSubMsg();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(rusult);
    }        
        /* * 通知短信         */// 官网的URL   /*String rusult = null;
            // 官网的URL
            String url = "";
            // 成为开发者,创建应用后系统自动生成
            String appkey = "23859907";
            String secret = "3249c3b6a29aee38a6c9c63a9093a314";
            TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
            AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
            req.setExtend("1234");
            req.setSmsType("normal");
            req.setSmsFreeSignName("羽品测试");
            req.setRecNum("15387108387");
            req.setSmsTemplateCode("SMS_69005127");
            try {
                AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
                System.out.println(rsp.getBody());  
                rusult = rsp.getSubMsg();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(rusult);
    }*/}
Copy after login

The jar packages to be imported are:

The above is the detailed content of Alibaba's tutorial guide for sending text messages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template