Today sms4j ushered in the first major version update, version 2.0.0 is officially released!
This release not only adjusts and changes the project structure, but also brings many new vendors and functions. Let’s take a brief look at it below!
First the maven changes
In the old version, groupId was the author's personal website, which was also the official website of the project. In the new version, it was uniformly changed to Dromara's address
<dependency>
<groupId>org.dromara.sms4j</groupId>
<artifactId>sms4j-spring-boot-starter</artifactId>
<version> version </version>
</dependency>
Followed by the adjustment of the function
In version 1.X, (the former name sms-aggregatio ) only supports the use of a single operator, and cannot use multiple manufacturers at the same time. The switch of manufacturers can only rely on the change of configuration files. It can be said that the function is extremely single. , but in the new version, multi-vendor support and usage have been added, and the configuration method has also changed
sms:
alibaba:
#阿里云的accessKey
accessKeyId: 您的accessKey
#阿里云的accessKeySecret
accessKeySecret: 您的accessKeySecret
#短信签名
signature: 测试签名
#模板ID 用于发送固定模板短信使用
templateId: SMS_215125134
#模板变量 上述模板的变量
templateName: code
#请求地址 默认为dysmsapi.aliyuncs.com 如无特殊改变可以不用设置
requestUrl: dysmsapi.aliyuncs.com
huawei:
#华为短信appKey
appKey: 5N6fvXXXX920HaWhVXXXXXX7fYa
#华为短信appSecret
app-secret: Wujt7EYzZTBXXXXXXEhSP6XXXX
#短信签名
signature: 华为短信测试
#通道号
sender: 8823040504797
#模板ID 如果使用自定义模板发送方法可不设定
template-id: acXXXXXXXXc274b2a8263479b954c1ab5
#华为回调地址,如不需要可不设置或为空
statusCallBack:
#华为分配的app请求地址
url: https://XXXXX.cn-north-4.XXXXXXXX.com:443
@RestController
@RequestMapping("/test/")
public class DemoController {
// 测试发送固定模板短信
@RequestMapping("/")
public void doLogin(String username, String password) {
//阿里云向此手机号发送短信
SmsFactory.createSmsBlend(SupplierType.ALIBABA).sendMessage("18888888888","123456");
//华为短信向此手机号发送短信
SmsFactory.createSmsBlend(SupplierType.HUAWEI).sendMessage("16666666666","000000");
}
}
The above is just an example, and more manufacturers can be supported at the same time in actual practice.
In other aspects, sms4j also adds support for database configuration, developers can replace configuration files by adding configuration in the database, so as to dynamically switch vendors
sms:
# 告诉框架要读取的厂商配置来源,此处为枚举形式
config-type: sql_config
sql:
# JDBC驱动
driver-class-name: com.mysql.cj.jdbc.Driver
# 要链接的数据库名称
database-name: dev
# 连接字符串
url: jdbc:mysql://localhost:3306
# 数据库账号
username: root
# 数据库密码
password: 123456
# 配置所在表名
table-name: config_info
# 厂商名称存储字段
supplier-field-name: user_name
# 配置所在字段
config-name: pay_psw
# 配置启用标识字段
start-name: state
# 配置启用值 此处意思为 当字段state值为1时,则启用这个配置
is-start: 1
More new features and functions are not introduced here one by one, you can check the official documentation or gitee warehouse for details
Official document gitee repository
Your support is the driving force for us to move forward. If our project has helped you or you think it is not bad, please give us a star