Skip to content

Commit

Permalink
🆕 #2755 【小程序】增加小程序云开发短信接口
Browse files Browse the repository at this point in the history
  • Loading branch information
liming1019 authored Jul 26, 2022
1 parent 5a26077 commit b550806
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit b550806

Please sign in to comment.