Skip to content

Commit 21d5f2f

Browse files
authored
🆕 #3764 【开放平台】添加小程序类目管理 - 获取类目名称信息的接口
1 parent e57b7e1 commit 21d5f2f

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public interface WxOpenMaBasicService {
7373
* 8.6 修改类目
7474
*/
7575
String OPEN_MODIFY_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/modifycategory";
76+
/**
77+
* 8.7 获取类目名称信息
78+
*/
79+
String OPEN_GET_ALL_CATEGORY_NAME = "https://api.weixin.qq.com/cgi-bin/wxopen/getallcategorynamelist";
7680

7781
/**
7882
* 获取订单页path信息
@@ -222,6 +226,18 @@ WxFastMaSetNickameResult setNickname(String nickname, String idCard, String lice
222226
*/
223227
WxOpenResult modifyCategory(WxFastMaCategory category) throws WxErrorException;
224228

229+
/**
230+
* 8.7 获取类目名称信息
231+
* <pre>
232+
* 获取所有类目名称信息,用于给用户展示选择
233+
* https://developers.weixin.qq.com/doc/oplatform/openApi/miniprogram-management/category-management/api_getallcategoryname.html
234+
* </pre>
235+
*
236+
* @return 类目名称列表
237+
* @throws WxErrorException .
238+
*/
239+
WxOpenMaCategoryNameListResult getAllCategoryName() throws WxErrorException;
240+
225241
/**
226242
* 获取订单页Path信息
227243
*

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ public WxOpenResult modifyCategory(WxFastMaCategory category) throws WxErrorExce
152152
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
153153
}
154154

155+
@Override
156+
public WxOpenMaCategoryNameListResult getAllCategoryName() throws WxErrorException {
157+
String response = get(OPEN_GET_ALL_CATEGORY_NAME, "");
158+
return WxOpenGsonBuilder.create().fromJson(response, WxOpenMaCategoryNameListResult.class);
159+
}
160+
155161
/**
156162
* 获取订单页Path信息
157163
*

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ public WxOpenResult modifyCategory(WxFastMaCategory category) throws WxErrorExce
146146
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
147147
}
148148

149+
@Override
150+
public WxOpenMaCategoryNameListResult getAllCategoryName() throws WxErrorException {
151+
String response = wxMaService.get(OPEN_GET_ALL_CATEGORY_NAME, "");
152+
return WxOpenGsonBuilder.create().fromJson(response, WxOpenMaCategoryNameListResult.class);
153+
}
154+
149155
/**
150156
* 获取订单页Path信息
151157
*
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package me.chanjar.weixin.open.bean.result;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 获取类目名称信息的返回结果.
13+
* <p>
14+
* 用于获取所有小程序类目的 ID 和名称信息,包括一级类目和二级类目。
15+
* </p>
16+
*
17+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
18+
* @see <a href="https://developers.weixin.qq.com/doc/oplatform/openApi/miniprogram-management/category-management/api_getallcategoryname.html">官方文档</a>
19+
*/
20+
@Data
21+
@EqualsAndHashCode(callSuper = true)
22+
public class WxOpenMaCategoryNameListResult extends WxOpenResult {
23+
private static final long serialVersionUID = 8989721350285449879L;
24+
25+
/**
26+
* 类目名称列表.
27+
*/
28+
@SerializedName("category_name_list")
29+
private List<CategoryName> categoryNameList;
30+
31+
@Override
32+
public String toString() {
33+
return WxOpenGsonBuilder.create().toJson(this);
34+
}
35+
36+
/**
37+
* 类目名称信息.
38+
* <p>
39+
* 包含一级类目和二级类目的 ID 和名称。
40+
* </p>
41+
*/
42+
@Data
43+
public static class CategoryName implements Serializable {
44+
private static final long serialVersionUID = 8989721350285449880L;
45+
46+
/**
47+
* 一级类目ID.
48+
*/
49+
@SerializedName("first_id")
50+
private Integer firstId;
51+
52+
/**
53+
* 一级类目名称.
54+
*/
55+
@SerializedName("first_name")
56+
private String firstName;
57+
58+
/**
59+
* 二级类目ID.
60+
*/
61+
@SerializedName("second_id")
62+
private Integer secondId;
63+
64+
/**
65+
* 二级类目名称.
66+
*/
67+
@SerializedName("second_name")
68+
private String secondName;
69+
70+
@Override
71+
public String toString() {
72+
return WxOpenGsonBuilder.create().toJson(this);
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)