zoukankan      html  css  js  c++  java
  • spring boot 整合 云之讯 demo

    ---恢复内容开始---

    package com.zhourong.controller;
    
    import org.apache.commons.lang3.RandomStringUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.http.ResponseEntity;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.client.RestTemplate;
    
    import com.zhourong.dto.SmsDto;
    import com.zhourong.utils.Result;
    import com.zhourong.vo.SmsVo;
    
    @RestController
    @RequestMapping("/sms/")
    public class SmsController {
        private final String appid = "6d5ea3e7964341058f0cd1b31799eb27";
        private final String sid = "b3cf37114ad3e0f61d66d5317306af70";
        private final String token = "1a1e13a677e25df8ceadb8dd100d2fd3";
        private final String templateid = "413092";
        
        @Autowired
        private RestTemplate restTemplate;
        
        @RequestMapping("/send")
        @ResponseBody
        public Result<SmsVo> send() {
            String url = "https://open.ucpaas.com/ol/sms/sendsms";
            SmsDto sms = new SmsDto();    
            String code = RandomStringUtils.randomNumeric(4);  
            sms.setAppid(appid);
            sms.setMobile("18821962348");
            sms.setSid(sid);
            sms.setTemplateid(templateid);
            sms.setToken(token);
            sms.setParam(code);
            ResponseEntity<SmsVo> smsVo = restTemplate.postForEntity(url,sms, SmsVo.class);
            return new Result(200,"发送成功",smsVo);
            
        }
    }

    项目结构:

     

    直接用。

    git:https://gitee.com/xxoo0_297/SMS.git

    ---恢复内容结束---

  • 相关阅读:
    AtCoder Grand Contest 013 C:Ants on a Circle
    AtCoder Grand Contest 010 C:Cleaning
    055 列表推导式
    054 三元表达式
    05 Python爬虫之信息标记与提取方法
    053 迭代器
    052 装饰器
    051 闭包函数
    04 Python爬虫之Beautiful Soup库
    03 Python爬虫之Requests网络爬取实战
  • 原文地址:https://www.cnblogs.com/1-Admin/p/10159423.html
Copyright © 2011-2022 走看看