首页 » SEO优化 » sendtemplatesmsphp技巧_一个简单纯真上手的短信服务Spring Boot Starter

sendtemplatesmsphp技巧_一个简单纯真上手的短信服务Spring Boot Starter

访客 2024-11-25 0

扫一扫用手机浏览

文章目录 [+]

来 源:jianshu.com/u/36510c75d37c

广而告之:由于此订阅号换了个皮肤,系统自动取消了读者的公众年夜众号置顶。
导致用户接管文章不及时。
可以打开订阅号,选择置顶(标星)"大众年夜众号,重磅干货,第一韶光投递!

sendtemplatesmsphp技巧_一个简单纯真上手的短信服务Spring Boot Starter

短信服务在用户注册、登录、找回密码等干系操作中,可以让用户利用更加便捷,越来越多的公司都采取短信验证的办法让用户进行操作,从而提高用户的实用性。

sendtemplatesmsphp技巧_一个简单纯真上手的短信服务Spring Boot Starter
(图片来自网络侵删)

由于 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>

(2) 在application.yml中加入

spring: pengzu: sms: sms-type: tentcent security-key: your security-key appid: your appid sign: your sign

(3) 在Springboot主程序中 加入

@EnabledPengzuSmsAutoConfiguration@ComponentScan(basePackages = {\"大众com.example.demo.sms\"大众, \"大众com.pengzu.sms\"大众})

(4) 创建发送短信程序

@RestControllerpublic 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); }}

(5) 发送

访问 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!

标签:

相关文章

介绍百度网盘,云端存储时代的创新先锋

随着互联网技术的飞速发展,云计算已经成为现代生活不可或缺的一部分。而在这其中,百度网盘作为国内领先的云存储服务提供商,以其卓越的性...

SEO优化 2025-01-03 阅读0 评论0

介绍监控屏蔽技术,守护个人隐私的利器

随着科技的发展,监控设备已经深入到我们生活的方方面面。在享受便利的隐私安全问题也日益凸显。如何有效屏蔽监控,保护个人隐私,成为人们...

SEO优化 2025-01-03 阅读0 评论0

介绍番号观看方法,轻松驾驭影视世界

随着互联网的普及,网络影视资源日益丰富,番号作为影视作品的标识码,已经成为广大观众了解、搜索和观看影视作品的重要途径。如何正确地使...

SEO优化 2025-01-03 阅读0 评论0

介绍盗微信号黑幕,网络安全的严峻挑战

在数字化时代,微信已成为人们生活中不可或缺的通讯工具。随着微信用户数量的激增,盗微信号的事件也日益增多。本文将深入剖析盗微信号的方...

SEO优化 2025-01-03 阅读0 评论0