如果这个项目让你有所收获,记得 Star 关注哦,这对我是非常不错的鼓励与支持。
源码地址(后端):https://gitee.com/csps/mingyue
源码地址(前端):https://gitee.com/csps/mingyue-ui
文档地址:https://gitee.com/csps/mingyue/wikis
短信服务(Short Message Service,简称SMS)是一种基于移动电话网络的通信方式,用于在移动设备之间传递短文本消息。这些消息通常被限制在一定的字符数内,通常为160个字符,尽管一些系统支持连接多条短信以形成较长的消息。短信服务是一种简便、广泛应用的通信手段,可用于个人、商业和技术领域。
以下是关于短信服务的一些关键特点:
有许多短信服务商为个人、企业和开发者提供短信发送和接收的服务。以下是一些在国内常用的短信服务商:
MingYue 短信服务将接入 阿里云(Aliyun)、腾讯云(Tencent Cloud)作为短信服务商!!!
mingyue ->
new module
-> mingyue-sms
mingyue
└── mingyue-sms
├── mingyue-sms-api
└── mingyue-sms-biz
└── MingYueSmsApplication (短信服务启动类)
<dependencies>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
dependency>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-configartifactId>
dependency>
<dependency>
<groupId>com.csp.mingyuegroupId>
<artifactId>mingyue-common-webartifactId>
dependency>
<dependency>
<groupId>com.csp.mingyuegroupId>
<artifactId>mingyue-common-docartifactId>
dependency>
<dependency>
<groupId>com.csp.mingyuegroupId>
<artifactId>mingyue-common-securityartifactId>
dependency>
dependencies>
添加一个测试接口
com.csp.mingyue.sms.controller.SmsController
/**
* 短信服务模块
* @author Strive
* @date 2023/8/24 14:59
*/
@Slf4j
@Tag(name = "短信服务模块")
@Validated
@RestController
@RequestMapping("/sms")
@RequiredArgsConstructor
public class SmsController {
/**
* 短信验证码
*
* @param phone 用户手机号
*/
@GetMapping("/code")
@Operation(summary = "短信验证码",
parameters = { @Parameter(name = "phone", description = "手机号", required = true) })
public R<Void> smsCaptcha(@NotBlank(message = "手机号不能为空") String phone) {
String code = "4321";
log.info("手机[{}] 验证码短信发送 => {}", phone, code);
return R.ok();
}
}
# 短信服务配置
# swagger配置
swagger:
services:
## 配置开启的接口服务
mingyue-sms-biz: sms
# 短信服务
- id: mingyue-sms-biz
uri: lb://mingyue-sms-biz
predicates:
- Path=/sms/**
filters:
- StripPrefix=1
http://mingyue-gateway:9100/v3/api-docs/sms 接口文档数据展示如下即可:
{
"openapi": "3.0.1",
"info": {
"title": "MingYue 基础服务中心_接口文档",
"description": "基础服务中心",
"contact": {
"name": "Strive",
"url": "https://gitee.com/csps/mingyue",
"email": "[email protected]"
},
"version": "1.0.0"
},
"servers": [
{
"url": "http://mingyue-gateway:9100/sms"
}
],
"paths": {
"/sms/code": {
"get": {
"tags": [
"短信服务模块"
],
"summary": "短信验证码",
"operationId": "smsCaptcha",
"parameters": [
{
"name": "phone",
"in": "query",
"description": "手机号",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/RVoid"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"RVoid": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"msg": {
"type": "string"
},
"data": {
"type": "object"
}
},
"description": "响应信息主体"
}
},
"securitySchemes": {
"apiKey": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}
}
短信服务模块已经添加完成,后续将依次接入阿里云与腾讯云的短信服务,等接入短信服务后实现发送短信验证码登录!具体流程如下图: