zoukankan      html  css  js  c++  java
  • 短信工具类


    public class SmsUtil {

    public static String sendSms(String phoneNumber,String code) {
    //配置文件类 ,读取配置文件
    DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", “”, “”);
    IAcsClient client = new DefaultAcsClient(profile);


    //配置请求参数
    CommonRequest request = new CommonRequest();
    request.setSysMethod(MethodType.POST);
    request.setSysDomain("dysmsapi.aliyuncs.com");
    request.setSysVersion("2017-05-25");
    request.setSysAction("SendSms");
    request.putQueryParameter("RegionId", "cn-hangzhou"); //查询参数 , 服务器所在地

    //设置 手机号
    request.putQueryParameter("PhoneNumbers", phoneNumber);
    //设置标签名称
    request.putQueryParameter("SignName", "爱思华");
    //模板 code
    request.putQueryParameter("TemplateCode", "SMS_199217541");
    //模板是一个json样式
    request.putQueryParameter("TemplateParam", "{"code":""+code+""}");

    try {
    CommonResponse response = client.getCommonResponse(request); //通过客户端拿到 阿里服务器 响应的 短信内容
    return response.getData();
    } catch (ServerException e) {
    e.printStackTrace();
    } catch (ClientException e) {
    e.printStackTrace();
    }
    return null;
    }

    /**
    * 获取4位随机数
    * @return
    */
    public static String getFourRandom(){
    Random random = new Random();
    String fourRandom = random.nextInt(10000) + "";
    System.out.println(fourRandom);
    int randLength = fourRandom.length();
    if(randLength<4){
    for(int i=1; i<=4-randLength; i++)
    fourRandom = "0" + fourRandom ;
    }
    return fourRandom;
    }

    public static void main(String[] args) {
    String fourRandom = getFourRandom();
    System.out.print(fourRandom);
    }

  • 相关阅读:
    LC 综合 中级算法笔记
    LC 212. 单词搜索2
    [NLP] 2.2 文本正规化 (Text Normalization)
    本地秘钥复制到github,实现两者之间的交互
    Python 实例化对象
    C# 左补齐+ 生成一个星期的日期
    hello world
    迭代器模式、观察者模式
    代理模式、桥接模式、装饰器模式、适配器模式
    外观模式、组合模式、享元模式
  • 原文地址:https://www.cnblogs.com/shiyueyangne/p/14240559.html
Copyright © 2011-2022 走看看