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

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

  • 相关阅读:
    关于《浪潮之巅》
    C++知识点
    #ifndef/#define/#endif以及#if defined/#else/#endif使用详解
    typedef void(*Fun)(void);
    C#-StructLayoutAttribute(结构体布局)
    Web Services
    C# DataGridView
    VS2017编译boost库
    位与字节
    c++ map
  • 原文地址:https://www.cnblogs.com/zhboke/p/14215442.html
Copyright © 2011-2022 走看看