Skip to content

Commit 738bcf7

Browse files
authored
🆕 #3739 【开放平台】补充完善第三方平台小程序快速配置域名的相关接口
1 parent de4848b commit 738bcf7

File tree

4 files changed

+200
-0
lines changed

4 files changed

+200
-0
lines changed

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ public interface WxOpenComponentService {
203203

204204
String COMPONENT_CLEAR_QUOTA_URL = "https://api.weixin.qq.com/cgi-bin/component/clear_quota/v2";
205205

206+
/**
207+
* 设置第三方平台服务器域名
208+
*/
209+
String API_MODIFY_WXA_SERVER_DOMAIN = "https://api.weixin.qq.com/cgi-bin/component/modify_wxa_server_domain";
210+
211+
/**
212+
* 获取第三方平台业务域名校验文件
213+
*/
214+
String API_GET_DOMAIN_CONFIRM_FILE = "https://api.weixin.qq.com/cgi-bin/component/get_domain_confirmfile";
215+
216+
/**
217+
* 设置第三方平台业务域名
218+
*/
219+
String API_MODIFY_WXA_JUMP_DOMAIN = "https://api.weixin.qq.com/cgi-bin/component/modify_wxa_jump_domain";
220+
206221
/**
207222
* Gets wx mp service by appid.
208223
*
@@ -1117,4 +1132,53 @@ public interface WxOpenComponentService {
11171132
*/
11181133
WxOpenResult applySetOrderPathInfo(WxOpenMaApplyOrderPathInfo info) throws WxErrorException;
11191134

1135+
/**
1136+
* 设置第三方平台服务器域名
1137+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/domain/modify_server_domain.html">文档地址</a>
1138+
*
1139+
* @param action add添加, delete删除, set覆盖, get获取
1140+
* @param requestDomains request 合法域名;当 action 是 get 时不需要此字段
1141+
* @param wsRequestDomains socket 合法域名;当 action 是 get 时不需要此字段
1142+
* @param uploadDomains uploadFile 合法域名;当 action 是 get 时不需要此字段
1143+
* @param downloadDomains downloadFile 合法域名;当 action 是 get 时不需要此字段
1144+
* @param tcpDomains tcp 合法域名;当 action 是 get 时不需要此字段
1145+
* @param udpDomains udp 合法域名;当 action 是 get 时不需要此字段
1146+
* @return the wx open ma domain result
1147+
* @throws WxErrorException the wx error exception
1148+
*/
1149+
WxOpenMaDomainResult modifyWxaServerDomain(String action, List<String> requestDomains, List<String> wsRequestDomains,
1150+
List<String> uploadDomains, List<String> downloadDomains,
1151+
List<String> udpDomains, List<String> tcpDomains) throws WxErrorException;
1152+
1153+
/**
1154+
* 获取第三方平台业务域名校验文件
1155+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/domain/get_domain_confirmfile.html">文档地址</a>
1156+
*
1157+
* @return 业务域名校验文件信息
1158+
* @throws WxErrorException 操作失败时抛出,具体错误码请看文档
1159+
*/
1160+
WxOpenMaDomainConfirmFileResult getDomainConfirmFile() throws WxErrorException;
1161+
1162+
/**
1163+
* 设置第三方平台业务域名
1164+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/domain/modify_jump_domain.html">文档地址</a>
1165+
*
1166+
* @param action add添加, delete删除, set覆盖, get获取
1167+
* @param domainList the domain list
1168+
* @return 直接返回字符串
1169+
* @throws WxErrorException the wx error exception
1170+
*/
1171+
String modifyWxaJumpDomain(String action, List<String> domainList) throws WxErrorException;
1172+
1173+
/**
1174+
* 设置第三方平台业务域名
1175+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/domain/modify_jump_domain.html">文档地址</a>
1176+
*
1177+
* @param action add添加, delete删除, set覆盖, get获取
1178+
* @param domainList the domain list
1179+
* @return web view domain info
1180+
* @throws WxErrorException the wx error exception
1181+
*/
1182+
WxOpenMaWebDomainResult modifyWxaJumpDomainInfo(String action, List<String> domainList) throws WxErrorException;
1183+
11201184
}

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaService.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public interface WxOpenMaService extends WxMaService {
3232
*/
3333
String API_MODIFY_DOMAIN = "https://api.weixin.qq.com/wxa/modify_domain";
3434

35+
/**
36+
* 快速配置小程序服务器域名
37+
*/
38+
String API_MODIFY_DOMAIN_DIRECTLY = "https://api.weixin.qq.com/wxa/modify_domain_directly";
39+
3540
/**
3641
* 设置小程序业务域名(仅供第三方代小程序调用)
3742
* <pre>
@@ -44,6 +49,11 @@ public interface WxOpenMaService extends WxMaService {
4449
*/
4550
String API_SET_WEBVIEW_DOMAIN = "https://api.weixin.qq.com/wxa/setwebviewdomain";
4651

52+
/**
53+
* 快速配置小程序业务域名
54+
*/
55+
String API_SET_WEBVIEW_DOMAIN_DIRECTLY = "https://api.weixin.qq.com/wxa/setwebviewdomain_directly";
56+
4757
/**
4858
* 获取业务域名校验文件(仅供第三方代小程序调用)
4959
*/
@@ -310,6 +320,24 @@ WxOpenMaDomainResult modifyDomain(String action, List<String> requestDomains, Li
310320
List<String> uploadDomains, List<String> downloadDomains,
311321
List<String> udpDomains, List<String> tcpDomains) throws WxErrorException;
312322

323+
/**
324+
* 快速配置小程序服务器域名
325+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_Basic_Info/modify_domain_directly.html">文档地址</a>
326+
*
327+
* @param action add添加, delete删除, set覆盖, get获取
328+
* @param requestDomains request 合法域名;当 action 是 get 时不需要此字段
329+
* @param wsRequestDomains socket 合法域名;当 action 是 get 时不需要此字段
330+
* @param uploadDomains uploadFile 合法域名;当 action 是 get 时不需要此字段
331+
* @param downloadDomains downloadFile 合法域名;当 action 是 get 时不需要此字段
332+
* @param tcpDomains tcp 合法域名;当 action 是 get 时不需要此字段
333+
* @param udpDomains udp 合法域名;当 action 是 get 时不需要此字段
334+
* @return the wx open ma domain result
335+
* @throws WxErrorException the wx error exception
336+
*/
337+
WxOpenMaDomainResult modifyDomainDirectly(String action, List<String> requestDomains, List<String> wsRequestDomains,
338+
List<String> uploadDomains, List<String> downloadDomains,
339+
List<String> udpDomains, List<String> tcpDomains) throws WxErrorException;
340+
313341
/**
314342
* 获取小程序的业务域名
315343
*
@@ -346,6 +374,28 @@ WxOpenMaDomainResult modifyDomain(String action, List<String> requestDomains, Li
346374
*/
347375
WxOpenMaWebDomainResult setWebViewDomainInfo(String action, List<String> domainList) throws WxErrorException;
348376

377+
/**
378+
* 快速配置小程序业务域名
379+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_Basic_Info/setwebviewdomain_directly.html">文档地址</a>
380+
*
381+
* @param action add添加, delete删除, set覆盖, get获取
382+
* @param domainList the domain list
383+
* @return 直接返回字符串
384+
* @throws WxErrorException the wx error exception
385+
*/
386+
String setWebViewDomainDirectly(String action, List<String> domainList) throws WxErrorException;
387+
388+
/**
389+
* 快速配置小程序业务域名
390+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Mini_Program_Basic_Info/setwebviewdomain_directly.html">文档地址</a>
391+
*
392+
* @param action add添加, delete删除, set覆盖, get获取
393+
* @param domainList the domain list
394+
* @return web view domain info
395+
* @throws WxErrorException the wx error exception
396+
*/
397+
WxOpenMaWebDomainResult setWebViewDomainDirectlyInfo(String action, List<String> domainList) throws WxErrorException;
398+
349399
/**
350400
* 获取业务域名校验文件
351401
*

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,4 +1307,55 @@ public WxOpenResult applySetOrderPathInfo(WxOpenMaApplyOrderPathInfo info) throw
13071307
String response = post(OPEN_APPLY_SET_ORDER_PATH_INFO, gson.toJson(info));
13081308
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
13091309
}
1310+
1311+
@Override
1312+
public WxOpenMaDomainResult modifyWxaServerDomain(String action, List<String> requestDomains, List<String> wsRequestDomains,
1313+
List<String> uploadDomains, List<String> downloadDomains,
1314+
List<String> udpDomains, List<String> tcpDomains) throws WxErrorException {
1315+
JsonObject requestJson = new JsonObject();
1316+
requestJson.addProperty("action", action);
1317+
if (!"get".equals(action)) {
1318+
requestJson.add("requestdomain", toJsonArray(requestDomains));
1319+
requestJson.add("wsrequestdomain", toJsonArray(wsRequestDomains));
1320+
requestJson.add("uploaddomain", toJsonArray(uploadDomains));
1321+
requestJson.add("downloaddomain", toJsonArray(downloadDomains));
1322+
requestJson.add("udpdomain", toJsonArray(udpDomains));
1323+
requestJson.add("tcpdomain", toJsonArray(tcpDomains));
1324+
}
1325+
1326+
String response = post(API_MODIFY_WXA_SERVER_DOMAIN, requestJson.toString());
1327+
return WxOpenGsonBuilder.create().fromJson(response, WxOpenMaDomainResult.class);
1328+
}
1329+
1330+
@Override
1331+
public WxOpenMaDomainConfirmFileResult getDomainConfirmFile() throws WxErrorException {
1332+
String responseContent = post(API_GET_DOMAIN_CONFIRM_FILE, "{}");
1333+
return WxOpenMaDomainConfirmFileResult.fromJson(responseContent);
1334+
}
1335+
1336+
@Override
1337+
public String modifyWxaJumpDomain(String action, List<String> domainList) throws WxErrorException {
1338+
JsonObject requestJson = new JsonObject();
1339+
requestJson.addProperty("action", action);
1340+
if (!"get".equals(action)) {
1341+
requestJson.add("webviewdomain", toJsonArray(domainList));
1342+
}
1343+
return post(API_MODIFY_WXA_JUMP_DOMAIN, requestJson.toString());
1344+
}
1345+
1346+
@Override
1347+
public WxOpenMaWebDomainResult modifyWxaJumpDomainInfo(String action, List<String> domainList) throws WxErrorException {
1348+
String response = this.modifyWxaJumpDomain(action, domainList);
1349+
return WxOpenGsonBuilder.create().fromJson(response, WxOpenMaWebDomainResult.class);
1350+
}
1351+
1352+
private JsonArray toJsonArray(List<String> list) {
1353+
JsonArray jsonArray = new JsonArray();
1354+
if (list != null) {
1355+
for (String item : list) {
1356+
jsonArray.add(item);
1357+
}
1358+
}
1359+
return jsonArray;
1360+
}
13101361
}

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaServiceImpl.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,25 @@ public WxOpenMaDomainResult modifyDomain(String action, List<String> requestDoma
113113
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaDomainResult.class);
114114
}
115115

116+
@Override
117+
public WxOpenMaDomainResult modifyDomainDirectly(String action, List<String> requestDomains, List<String> wsRequestDomains,
118+
List<String> uploadDomains, List<String> downloadDomains,
119+
List<String> udpDomains, List<String> tcpDomains) throws WxErrorException {
120+
JsonObject requestJson = new JsonObject();
121+
requestJson.addProperty(ACTION, action);
122+
if (!ACTION_GET.equals(action)) {
123+
requestJson.add("requestdomain", toJsonArray(requestDomains));
124+
requestJson.add("wsrequestdomain", toJsonArray(wsRequestDomains));
125+
requestJson.add("uploaddomain", toJsonArray(uploadDomains));
126+
requestJson.add("downloaddomain", toJsonArray(downloadDomains));
127+
requestJson.add("udpdomain", toJsonArray(udpDomains));
128+
requestJson.add("tcpdomain", toJsonArray(tcpDomains));
129+
}
130+
131+
String response = post(API_MODIFY_DOMAIN_DIRECTLY, GSON.toJson(requestJson));
132+
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaDomainResult.class);
133+
}
134+
116135
@Override
117136
public String getWebViewDomain() throws WxErrorException {
118137
return setWebViewDomain(ACTION_GET, null);
@@ -140,6 +159,22 @@ public WxOpenMaWebDomainResult setWebViewDomainInfo(String action, List<String>
140159
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaWebDomainResult.class);
141160
}
142161

162+
@Override
163+
public String setWebViewDomainDirectly(String action, List<String> domainList) throws WxErrorException {
164+
JsonObject requestJson = new JsonObject();
165+
requestJson.addProperty(ACTION, action);
166+
if (!ACTION_GET.equals(action)) {
167+
requestJson.add("webviewdomain", toJsonArray(domainList));
168+
}
169+
return post(API_SET_WEBVIEW_DOMAIN_DIRECTLY, GSON.toJson(requestJson));
170+
}
171+
172+
@Override
173+
public WxOpenMaWebDomainResult setWebViewDomainDirectlyInfo(String action, List<String> domainList) throws WxErrorException {
174+
String response = this.setWebViewDomainDirectly(action, domainList);
175+
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaWebDomainResult.class);
176+
}
177+
143178
@Override
144179
public WxOpenMaDomainConfirmFileResult getWebviewDomainConfirmFile() throws WxErrorException {
145180
String responseContent = post(API_GET_WEBVIEW_DOMAIN_CONFIRM_FILE, "{}");

0 commit comments

Comments
 (0)