来 源:jianshu.com/u/36510c75d37c
广而告之:由于此订阅号换了个皮肤,系统自动取消了读者的公众年夜众号置顶。导致用户接管文章不及时。可以打开订阅号,选择置顶(标星)"大众年夜众号,重磅干货,第一韶光投递!
短信服务在用户注册、登录、找回密码等干系操作中,可以让用户利用更加便捷,越来越多的公司都采取短信验证的办法让用户进行操作,从而提高用户的实用性。

由于 Spring boot 的约定大于配置的理念,使得在利用Spring变得更加方便。Spring Boot 项目组供应了很多Starter ,让我们在利用 Spring 的时候变得非常随意马虎。对付官方供应的Starter 采取 spring-boot-starter-xxx开头,对付非官方供应的Spring Boot Starter ,官方建议采取 xxxx-spring-boot-starter命名。
1. 开拓工具及编译
IntelliJ IDEA 2018.2.5
Maven 3.5
JDK 1.8
2. 如何利用sms-spring-boot-starter(1) 在pom文件中引入
<dependency>
<groupId>com.github.jackieonway.sms</groupId>
<artifactId>sms-spring-boot-starter</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
在pom.xml中配置maven中心仓库Snapshots地址
<repositories>
<repository>
<id>mavenRepoCenter</id>
<name>Maven Development Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
spring:
pengzu:
sms:
sms-type: tentcent
security-key: your security-key
appid: your appid
sign: your sign
@EnabledPengzuSmsAutoConfiguration
@ComponentScan(basePackages = {\"大众com.example.demo.sms\"大众, \"大众com.pengzu.sms\"大众})
@RestController
public class HelloController {
@Autowired
private PengzuSmsService pengzuSmsService;
@GetMapping(\"大众/sayHello\"大众)
public Object sayHello throws ClientException, HTTPException, IOException {
String paramst = {\"大众5678\公众,\"大众5\公众};
TencentSmsRequest tencentSmsRequest = new TencentSmsRequest;
tencentSmsRequest.setPhoneNumber(new String[]{\"大众your cellphone\"大众});
tencentSmsRequest.setParams(paramst);
return pengzuSmsService.sendTemplateSms(\"大众your template id\"大众, tencentSmsRequest);
}
}
访问 localhost:8080/sayHello
3 PengzuSmsService接口
/
单个发送短信
@param params 根据对应的短信服务商所需信息填写
/
public Object sendSms(Integer type,Object params) throws HTTPException, IOException, ClientException;
/
单个发送模板短信
@param tempalteId 短信模板id
@param params 根据对应的短信服务商所需信息填写
/
public Object sendTemplateSms(String tempalteId, Object params) throws HTTPException, IOException, ClientException;
/
批量发送短信
@param params 根据对应的短信服务商所需信息填写
/
public Object sendBatchSms(int type,Object params) throws HTTPException, IOException, ClientException;
/
批量发送模板短信
@param tempalteId 短信模板id
@param params 根据对应的短信服务商所需信息填写
/
public Object sendBatchTemplateSms(String tempalteId, Object params) throws HTTPException, IOException, ClientException;
该接供词给了单个和群发短信与模板短信,把稳目前只供应了同步发送方法,异步发送方法,请结合线程池进行。
只是针对腾讯短信服务进行了试验,阿里的短信服务并未真正验证,希望各位小伙伴能互助完成验证,共同完善该starter,以为有用请starter该项目。如果只想利用而腾讯云短信业务的话,按照Demo利用即可。
github地址:sms-spring-boot-project
标星订阅号示意图
推举阅读
1.这简历一看便是包装过的
2. 你必须收藏的 GitHub 技巧
3.Spring Boot 为什么这么火火火火火火?
4.一文读懂 Spring Data Jpa!