From b550806956520f1b45a2b1c0ee37a6f932475b06 Mon Sep 17 00:00:00 2001 From: liming1019 Date: Tue, 26 Jul 2022 21:40:49 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#2755=20=E3=80=90=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E3=80=91=E5=A2=9E=E5=8A=A0=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E4=BA=91=E5=BC=80=E5=8F=91=E7=9F=AD=E4=BF=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaCloudService.java | 12 +++++ .../api/impl/WxMaCloudServiceImpl.java | 12 +++++ .../bean/cloud/WxCloudSendSmsV2Result.java | 44 +++++++++++++++++++ .../request/WxCloudSendSmsV2Request.java | 41 +++++++++++++++++ .../miniapp/constant/WxMaApiUrlConstants.java | 1 + .../api/impl/WxMaCloudServiceImplTest.java | 14 ++++++ 6 files changed, 124 insertions(+) create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/cloud/WxCloudSendSmsV2Result.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/cloud/request/WxCloudSendSmsV2Request.java diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCloudService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCloudService.java index 02c363a3a0..03fe5a4741 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCloudService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaCloudService.java @@ -1,6 +1,7 @@ package cn.binarywang.wx.miniapp.api; import cn.binarywang.wx.miniapp.bean.cloud.*; +import cn.binarywang.wx.miniapp.bean.cloud.request.WxCloudSendSmsV2Request; import com.google.gson.JsonArray; import me.chanjar.weixin.common.error.WxErrorException; @@ -539,4 +540,15 @@ Long databaseMigrateImport(String env, String collectionName, String filePath, i * @throws WxErrorException . */ WxCloudDatabaseCollectionGetResult databaseCollectionGet(String env, Long limit, Long offset) throws WxErrorException; + + /** + * 发送携带 URL Link 的短信 + * + * 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/cloudbase/cloudbase.sendSmsV2.html + * @param request + * @return WxCloudSendSmsV2Result + * @throws WxErrorException + */ + WxCloudSendSmsV2Result sendSmsV2(WxCloudSendSmsV2Request request) throws WxErrorException; + } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImpl.java index d2ed6e2de2..0ef033d2ba 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImpl.java @@ -3,6 +3,7 @@ import cn.binarywang.wx.miniapp.api.WxMaCloudService; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.cloud.*; +import cn.binarywang.wx.miniapp.bean.cloud.request.WxCloudSendSmsV2Request; import cn.binarywang.wx.miniapp.constant.WxMaConstants; import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; import cn.binarywang.wx.miniapp.util.JoinerUtils; @@ -410,4 +411,15 @@ public WxCloudDatabaseCollectionGetResult databaseCollectionGet(String env, Long String response = this.wxMaService.post(DATABASE_COLLECTION_GET_URL, params); return WxGsonBuilder.create().fromJson(response, WxCloudDatabaseCollectionGetResult.class); } + + @Override + public WxCloudSendSmsV2Result sendSmsV2(WxCloudSendSmsV2Request request) throws WxErrorException { + // 如果没有指定云环境ID,取默认云环境ID + if (request.getEnv() == null){ + String cloudEnv = this.wxMaService.getWxMaConfig().getCloudEnv(); + request.setEnv(cloudEnv); + } + String response = this.wxMaService.post(SEND_SMS_V2_URL, request); + return WxGsonBuilder.create().fromJson(response, WxCloudSendSmsV2Result.class); + } } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/cloud/WxCloudSendSmsV2Result.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/cloud/WxCloudSendSmsV2Result.java new file mode 100644 index 0000000000..eacee01b24 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/cloud/WxCloudSendSmsV2Result.java @@ -0,0 +1,44 @@ +package cn.binarywang.wx.miniapp.bean.cloud; + +import cn.binarywang.wx.miniapp.bean.WxMaBaseResponse; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +/** + * 发送携带 URL Link 的短信结果 + * + * @author liming1019 + * @date 2022-07-26 + */ +@Data +public class WxCloudSendSmsV2Result extends WxMaBaseResponse implements Serializable { + private static final long serialVersionUID = 4273038291300329985L; + + @SerializedName("send_status_list") + private List sendStatusList; + + @NoArgsConstructor + @Data + public static class SendStatus implements Serializable { + private static final long serialVersionUID = 5765836923681051366L; + + @SerializedName("serial_no") + private String serialNo; + + @SerializedName("phone_number") + private String phoneNumber; + + @SerializedName("code") + private String code; + + @SerializedName("message") + private String message; + + @SerializedName("iso_code") + private String isoCode; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/cloud/request/WxCloudSendSmsV2Request.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/cloud/request/WxCloudSendSmsV2Request.java new file mode 100644 index 0000000000..67f926c1f8 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/cloud/request/WxCloudSendSmsV2Request.java @@ -0,0 +1,41 @@ +package cn.binarywang.wx.miniapp.bean.cloud.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 发送携带 URL Link 的短信请求 + * + * @author liming1019 + * @date 2022-07-26 + */ +@Data +@Builder +public class WxCloudSendSmsV2Request implements Serializable { + private static final long serialVersionUID = 8917033507660980594L; + + @SerializedName("env") + private String env; + + @SerializedName("url_link") + private String urlLink; + + @SerializedName("template_id") + private String templateId; + + @SerializedName("template_param_list") + private List templateParamList; + + @SerializedName("phone_number_list") + private List phoneNumberList; + + @SerializedName("use_short_name") + private Boolean useShortName; + + @SerializedName("resource_appid") + private String resourceAppid; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java index fbe7c36cb0..896c59549c 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java @@ -42,6 +42,7 @@ public interface Cloud { String DATABASE_UPDATE_URL = "https://api.weixin.qq.com/tcb/databaseupdate"; String DATABASE_DELETE_URL = "https://api.weixin.qq.com/tcb/databasedelete"; String DATABASE_ADD_URL = "https://api.weixin.qq.com/tcb/databaseadd"; + String SEND_SMS_V2_URL = "https://api.weixin.qq.com/tcb/sendsmsv2"; } public interface Msg { diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImplTest.java index 69d6cc990e..4b7235ba91 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImplTest.java @@ -2,6 +2,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.cloud.*; +import cn.binarywang.wx.miniapp.bean.cloud.request.WxCloudSendSmsV2Request; import cn.binarywang.wx.miniapp.test.ApiTestModule; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Lists; @@ -394,4 +395,17 @@ public void testDatabaseCollectionGet() throws WxErrorException { assertThat(result.getCollections()[0].getIndexCount()).isGreaterThan(0); assertThat(result.getCollections()[0].getIndexSize()).isGreaterThan(0); } + + @Test + public void testSendSmsV2() throws WxErrorException { + WxCloudSendSmsV2Request request = WxCloudSendSmsV2Request.builder() + .urlLink("https://wxaurl.cn/xxxxxx") + .templateId("844110") + .templateParamList(Arrays.asList(new String[]{"能力上新"})) + .phoneNumberList(Arrays.asList("+8612345678910")) + .build(); + + final WxCloudSendSmsV2Result result = this.wxMaService.getCloudService().sendSmsV2(request); + assertThat(result).isNotNull(); + } }