Java SDK

安装

pom.xml 中添加 Maven 依赖:

xml
<dependency>
  <groupId>com.fanwan</groupId>
  <artifactId>fanwan-sms</artifactId>
  <version>1.0.0</version>
</dependency>

快速开始

创建客户端实例:

java
FanwanSMS client = new FanwanSMS("YOUR_ACCESS_KEY");

发送短信

使用 send 方法发送短信:

java
SendResult result = client.send(SendRequest.builder()
    .to("13800138000")
    .signature("泛玩短信")
    .templateId("welcome")
    .templateData(Map.of("name", "张三"))
    .build());

System.out.println(result.getMessageId());

发送验证码

使用验证码模板快速发送验证码短信:

java
SendResult result = client.send(SendRequest.builder()
    .to("13800138000")
    .signature("泛玩短信")
    .templateId("verify_code")
    .templateData(Map.of("code", "1234"))
    .build());

System.out.println(result.getMessageId());