---恢复内容开始---
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); } }
项目结构:
直接用。
---恢复内容结束---