• 短信工具类



    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);
    }

  • 相关阅读:
    三路快排
    双路快排
    随机快排
    快速排序
    双向链表
    单向链表
    堆排序
    二分插入、bisect
    jmockit使用总结-MockUp重点介绍
    java拼接字符串、格式化字符串方式
  • 原文地址:https://www.cnblogs.com/shiyueyangne/p/14240559.html
Copyright © 2020-2023  润新知