zoukankan      html  css  js  c++  java
  • JavaWeb-SpringBoot_一个类实现腾讯云SDK发送短信

      腾讯云应用列表  传送门

      使用Gradle编译项目  传送门

      SDK&API:qcloudsms_java  传送门

    package com.Gary.sms.controller;
    
    import java.io.IOException;
    
    import org.json.JSONException;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import com.github.qcloudsms.SmsSingleSender;
    import com.github.qcloudsms.SmsSingleSenderResult;
    import com.github.qcloudsms.httpclient.HTTPException;
    
    @RestController
    public class UserController {
    
        @RequestMapping("/test")
        public String test() {
            
            //给手机发送短信
            
            //1.腾讯云自己项目的AppID
            int appid = 1111184301;
            //2.腾讯云自己项目的Appkey
            String appkey = "000000000000faba756087b9504bff46";
            //3  短信的模板ID
            int templateID = 275243;
            //4  签名的名字
            String smsSign = "Garyd公众号";
            //5 .给谁发
            String phoneNumber = "00000070428";
            
            //6. 验证码:手动不随机验证码
            String[] params = {"0428"};
            
            //7. 
            SmsSingleSender ssender = new SmsSingleSender(appid,appkey);
            //地区,电话,模板ID,验证码,签名
            try {
                SmsSingleSenderResult result = ssender.sendWithParam("86", phoneNumber, templateID, params, smsSign, "", "");
                //输出一下返回值
                System.out.println(result);
            } catch (HTTPException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //当执行此函数时在http://localhost:8080/test输出success字符串
            return "success";
        }
        
    }
    UserController.java

      项目列表

       

      当控制台输出result第一个参数为 0 后稍等几秒手机便会接收腾讯云发送的短信

    {"result":0,"errmsg":"OK","ext":"","sid":"2019:2258682213273363498","fee":1}

       

      

      给手机发送短信模板六个步骤

            //1.腾讯云自己项目的AppID
            int appid = 1111184301;
            //2.腾讯云自己项目的Appkey
            String appkey = "xxxxxxxxxxxxfaba756087b9504bff46";
            //3  短信的模板ID
            int templateID = 275243;
            //4  签名的名字
            String smsSign = "Garyd公众号";
            //5 .给谁发
            String phoneNumber = "17689470428";
            
            //6. 验证码:手动不随机验证码
            String[] params = {"0428"};            

      1和2填写自己项目的AppIDAppKey[检查无误]

      

      3、填写该项目下短信内容配置中的模板ID

      4、填写该项目下短信内容配置中短信正文模板名称

     

      5和6填写需要发送到人的手机号和验证码

      验证码可设置为随机数

            //5给谁发
            String phoneNumber = "00000070428";
            
            //6验证码:手动不随机验证码
            String[] params = {"0428"};
    (如需转载学习,请标明出处)
  • 相关阅读:
    vue init定制团队模板之meta.js/meta.json写法入门
    使用vux组件库常见报错($t)处理
    vue filter使用方法
    vue init定制团队模板使用方法
    java.lang.String (JDK1.8)
    JDK 1.8 源码阅读和理解
    JAVA 实现tail -f 日志文件监控功能
    JAVA实现上传文件到服务器、删除服务器文件
    JAVA 解析、编辑nginx.conf
    新旧apache HttpClient 获取httpClient方法
  • 原文地址:https://www.cnblogs.com/1138720556Gary/p/10340119.html
Copyright © 2011-2022 走看看