mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-02 20:02:37 +08:00
🆕 #2755 【小程序】增加小程序云开发短信接口
This commit is contained in:
parent
5a2607787f
commit
b550806956
@ -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 @@ public interface WxMaCloudService {
|
||||
* @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;
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cn.binarywang.wx.miniapp.api.impl;
|
||||
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 class WxMaCloudServiceImpl implements WxMaCloudService {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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<SendStatus> 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;
|
||||
}
|
||||
}
|
@ -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<String> templateParamList;
|
||||
|
||||
@SerializedName("phone_number_list")
|
||||
private List<String> phoneNumberList;
|
||||
|
||||
@SerializedName("use_short_name")
|
||||
private Boolean useShortName;
|
||||
|
||||
@SerializedName("resource_appid")
|
||||
private String resourceAppid;
|
||||
}
|
@ -42,6 +42,7 @@ public class WxMaApiUrlConstants {
|
||||
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 {
|
||||
|
@ -2,6 +2,7 @@ package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
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 class WxMaCloudServiceImplTest {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user