spring boot发送短信服务
来源:互联网 发布:智多星软件多少钱一年 编辑:程序博客网 时间:2024/06/10 21:21
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.http.HttpEntity;import org.springframework.http.HttpHeaders;import org.springframework.http.MediaType;import org.springframework.stereotype.Service;import org.springframework.util.LinkedMultiValueMap;import org.springframework.util.MultiValueMap;import org.springframework.web.client.RestTemplate;import java.text.SimpleDateFormat;import java.util.Date;/*** Created by jalen on 17-6-1.*/@Servicepublic class SmsService { @Autowired RestTemplate restTemplate; @Value("${sms.username}") String username; @Value("${sms.password}") String password; @Value("${sms.url}") String url; public String sendMsg(String phoneNum,String text){ if (text.getBytes().length<=500){ String postUrl = url + "xxxx"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String,String> p = new LinkedMultiValueMap<>(); p.add("userId",username); p.add("password",password); p.add("pszMobis",phoneNum); p.add("pszMsg",text); HttpEntity< MultiValueMap<String,String>> entity = new HttpEntity< MultiValueMap<String,String>>(p,headers); String result = restTemplate.postForObject(postUrl,entity,String.class); return result; }else { String result = "短信内容过长,请重新编辑"; return result; } }}
2.看注入的属性RestTemplate对象实在哪里实例化的,这里实在spring boot入口Application处设置的bean
import com.xxx.repository.support.CustomRepository;import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cache.annotation.EnableCaching;import org.springframework.context.annotation.Bean;import org.springframework.data.jpa.repository.config.EnableJpaAuditing;import org.springframework.data.jpa.repository.config.EnableJpaRepositories;import org.springframework.web.client.RestTemplate;@SpringBootApplication//@EnableEncryptableProperties //启用配置文件加密Encrypt@EnableJpaAuditing//@EnableCaching //启用Ehcache缓存@EnableJpaRepositories(repositoryBaseClass = CustomRepository.class)public class Application { @Bean RestTemplate restTemplate(){ return new RestTemplate(); } public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
sms: username: xxxx password: xxxx url: http://xx.xx.xx.xx:8086/xx/xx.asmx/
阅读全文
0 0
- spring boot发送短信服务
- spring-boot | 集成短信验证码服务
- Spring boot 集成JavaMail服务发送邮件
- spring boot 发送邮件
- spring boot 发送邮件
- spring boot 发送邮件
- spring boot 发送邮件
- spring boot发送邮件
- spring boot 发送邮件
- Spring Boot 发送邮件
- 阿里大于短信发送服务
- spring boot 服务管理
- 47. Spring Boot发送邮件
- spring-boot mail 邮件发送
- 47. Spring Boot发送邮件
- 三个最好的免费短信发送服务
- 搭建亿万级别短信服务发送平台
- c# 利用sian的短信服务实现短信发送
- cookie的使用及单点登录
- zookeeper集群搭建
- python-抓取数据、下载图片(正则)、构造headers、urlencode、get_post
- SQL注入的原理以及危害
- js隐藏手机中间4位号秒
- spring boot发送短信服务
- caffe编译之fatal error: hdf5.h: No such file or directory
- 取出Set中的byte数组的值以及判断byte数组是否为空
- mysql允许root远程连接
- 中国剩余定理(孙子定理)
- MySQL 分组
- Background中data类型的Url格式url(data:image/gif;base64,AAAA)把小数据直接嵌入到Url中
- 同余详解入门
- navicat连接oracle报错ORA-28547:connection to server failed,probable Oracle Net admin error