zoukankan      html  css  js  c++  java
  • 阿里大鱼发送短信

    package com.fh.service.SMS;
    
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.UnsupportedEncodingException;
    import java.net.MalformedURLException;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Properties;
    
    import com.taobao.api.ApiException;
    import com.taobao.api.DefaultTaobaoClient;
    import com.taobao.api.TaobaoClient;
    import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
    import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
    
    public class Alidayu {
        
        public static void main(String[] args) {
            try {
                Alidayu.sendSMS("13463267918","注册验证","SMS_22610058","1111");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        
        public static long sendSMS(String Mobile,String freeSignName,String smsTemplateCode,String vercode) throws MalformedURLException, UnsupportedEncodingException {
            Map<String, Object> map = getContextProperty();
            //官网的URL  
            String url=(String) map.get("url");
            //成为开发者,创建应用后系统自动生成  
            String appkey=(String) map.get("appkey");
            String secret=(String) map.get("secret");
            
            //短信模板的内容  
            String json="{"code":""+vercode+"","product":""}";  
    //        String json="{"code":""+vercode+"","product":""+(String) map.get("company")+""}";  
            TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);  
            AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();  
            req.setExtend("123456");  
            req.setSmsType("normal");  
            req.setSmsFreeSignName(freeSignName);  
            req.setSmsParamString(json);  
            req.setRecNum(Mobile);  
            req.setSmsTemplateCode(smsTemplateCode);  
                AlibabaAliqinFcSmsNumSendResponse rsp;
                try {
                    rsp = client.execute(req);
                    System.out.println(rsp.getBody()); 
                    return 1;
                } catch (ApiException e) {
                    e.printStackTrace();
                }
                return 0;  
        }  
         public static Map<String, Object> getContextProperty() {
                
                Map<String, Object> ctxPropertiesMap = new HashMap<String, Object>();
                
                Properties prop = new Properties();
                try {
                    InputStream in = Alidayu.class.getClassLoader().getResourceAsStream("alidayu.properties");
                    prop.load(new InputStreamReader(in, "UTF-8"));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                Iterator<String> it = prop.stringPropertyNames().iterator();
                while(it.hasNext()){
                    String key = it.next();
                    String value = prop.getProperty(key);
                    System.out.println(key+":"+value);
                    ctxPropertiesMap.put(key, value);
                }
                return ctxPropertiesMap;
            }
    }

    alidayu.properties

    #官网的URL 
    url=https://eco.taobao.com/router/rest
    #TOP分配给应用的AppKey 
    appkey=23492181
    secret=f5ad7249451dfa2525f2df85763a7a35
    #公司名称
    #company=【资格宝】
    #company=北京三义资格教育科技有限公司
  • 相关阅读:
    mysql数据库如何设置默认字符集
    vue初探(构建一个axios+java项目)
    mui中几种open页面的区别
    git版本控制的文件(没有图标标明)
    JDBC连接超时,针对连接不稳定,有时候能连上(登录),一会又报连接超时
    提升group by 的效率
    enum类型与tinyint,mysql数据库tinyint数据取出0和1的方法
    word.xml加变量赋值后格式损坏(类似发表评论,脚本符号<>&)
    iOS--全局断点的设置
    23Properties(配置文件)
  • 原文地址:https://www.cnblogs.com/zrui-xyu/p/6007400.html
Copyright © 2011-2022 走看看