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

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

  • 相关阅读:
    JS权威指南读书笔记(二)
    JS权威指南读书笔记(一)
    NodeList和HTMLCollection区别
    2016年前端技术展望
    Label标签for属性
    JavaScript Array vs new Array区别
    禁止滚动事件方法
    shim和polyfill 区别解释
    Html5知识精粹纪录
    前端url 相关设置获取总结
  • 原文地址:https://www.cnblogs.com/zhboke/p/14215442.html
Copyright © 2011-2022 走看看