zoukankan      html  css  js  c++  java
  • 浅薄研究阿里云短信接口

    package com.zh.util;
    
    import com.aliyuncs.CommonRequest;
    import com.aliyuncs.CommonResponse;
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.http.MethodType;
    import com.aliyuncs.profile.DefaultProfile;
    import redis.clients.jedis.Jedis;
    
    /**
     * @ClassName SendSms
     * @Description TODO
     * @Author zh
     * @Data 2020/12/30 12:05
     **/
    public class SendSms {
        public static void main(String[] args) {
    sendSms(
    "13462571103"); } public static String verifyCode(){ return String.valueOf((int)(Math.random()*900000 + 100000)); } public static String sendSms(String phone){ /** *@author zh *@Date 2020/12/30 *@MethodNotes "<your-region-id>", // 您的地域ID * "<your-access-key-id>", // 您的AccessKey ID * "<your-access-key-secret>"); // 您的AccessKey Secret **/ DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "", ""); IAcsClient client = new DefaultAcsClient(profile); //生成随机验证码 String verifyCode = verifyCode(); //请求 CommonRequest request = new CommonRequest(); //设置请求方法提交方式 request.setSysMethod(MethodType.POST); //该产品的服务地址(开发者无需替换) 阿里云的api request.setSysDomain("dysmsapi.aliyuncs.com"); //api版本号 request.setSysVersion("2017-05-25"); //请求方法路径 request.setSysAction("SendSms"); request.putQueryParameter("RegionId", "cn-hangzhou"); //连接超时时间 //request.putQueryParameter("connectTimeout", ); //读取超时时间 //request.putQueryParameter("readTimeout", ); //待发送手机号 request.putQueryParameter("PhoneNumbers", phone); //短信签名 request.putQueryParameter("SignName", "hopu学习"); //短信模板 request.putQueryParameter("TemplateCode", "SMS_193517058"); //短信验证码 request.putQueryParameter("TemplateParam", "{"code":""+ verifyCode +""}"); System.out.println("验证码为:" + verifyCode); Jedis jedis = new Jedis("localhost", 6379); jedis.set(phone, verifyCode); try { // CommonResponse response = client.getCommonResponse(request); return response.getData(); } catch (Exception e) { e.printStackTrace(); } return "error"; } }

    一些浅薄的小研究,若有错误,欢迎指正

  • 相关阅读:
    Expression基础体验
    浅谈Pool对象
    TreeBuilder科学的树创建器
    2种负载均衡算法
    亲自打造Deferred对象
    Animation
    micro-template改造
    Node.js的缺陷
    让JSON.js完全适应.NET
    关系型数据库操作一些不好用的地方
  • 原文地址:https://www.cnblogs.com/zhboke/p/14215442.html
Copyright © 2011-2022 走看看