From 21d5f2fdd2a8648dd9632dbe20b149added4dd6d Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 27 Nov 2025 23:06:19 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#3764=20=E3=80=90=E5=BC=80=E6=94=BE?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E3=80=91=E6=B7=BB=E5=8A=A0=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E7=B1=BB=E7=9B=AE=E7=AE=A1=E7=90=86=20-=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=B1=BB=E7=9B=AE=E5=90=8D=E7=A7=B0=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/open/api/WxOpenMaBasicService.java | 16 ++++ .../api/impl/WxOpenFastMaServiceImpl.java | 6 ++ .../api/impl/WxOpenMaBasicServiceImpl.java | 6 ++ .../WxOpenMaCategoryNameListResult.java | 75 +++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenMaCategoryNameListResult.java diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaBasicService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaBasicService.java index 3952f7dbf..5929f8390 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaBasicService.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaBasicService.java @@ -73,6 +73,10 @@ public interface WxOpenMaBasicService { * 8.6 修改类目 */ String OPEN_MODIFY_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/modifycategory"; + /** + * 8.7 获取类目名称信息 + */ + String OPEN_GET_ALL_CATEGORY_NAME = "https://api.weixin.qq.com/cgi-bin/wxopen/getallcategorynamelist"; /** * 获取订单页path信息 @@ -222,6 +226,18 @@ public interface WxOpenMaBasicService { */ WxOpenResult modifyCategory(WxFastMaCategory category) throws WxErrorException; + /** + * 8.7 获取类目名称信息 + *
+ * 获取所有类目名称信息,用于给用户展示选择 + * https://developers.weixin.qq.com/doc/oplatform/openApi/miniprogram-management/category-management/api_getallcategoryname.html + *+ * + * @return 类目名称列表 + * @throws WxErrorException . + */ + WxOpenMaCategoryNameListResult getAllCategoryName() throws WxErrorException; + /** * 获取订单页Path信息 * diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenFastMaServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenFastMaServiceImpl.java index 84ff7b495..c80ce03c3 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenFastMaServiceImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenFastMaServiceImpl.java @@ -152,6 +152,12 @@ public class WxOpenFastMaServiceImpl extends WxMaServiceImpl implements WxOpenFa return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); } + @Override + public WxOpenMaCategoryNameListResult getAllCategoryName() throws WxErrorException { + String response = get(OPEN_GET_ALL_CATEGORY_NAME, ""); + return WxOpenGsonBuilder.create().fromJson(response, WxOpenMaCategoryNameListResult.class); + } + /** * 获取订单页Path信息 * diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaBasicServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaBasicServiceImpl.java index 56d209a32..6204b1e26 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaBasicServiceImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaBasicServiceImpl.java @@ -146,6 +146,12 @@ public class WxOpenMaBasicServiceImpl implements WxOpenMaBasicService { return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); } + @Override + public WxOpenMaCategoryNameListResult getAllCategoryName() throws WxErrorException { + String response = wxMaService.get(OPEN_GET_ALL_CATEGORY_NAME, ""); + return WxOpenGsonBuilder.create().fromJson(response, WxOpenMaCategoryNameListResult.class); + } + /** * 获取订单页Path信息 * diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenMaCategoryNameListResult.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenMaCategoryNameListResult.java new file mode 100644 index 000000000..014a4ae84 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenMaCategoryNameListResult.java @@ -0,0 +1,75 @@ +package me.chanjar.weixin.open.bean.result; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 获取类目名称信息的返回结果. + *
+ * 用于获取所有小程序类目的 ID 和名称信息,包括一级类目和二级类目。 + *
+ * + * @author Binary Wang + * @see 官方文档 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxOpenMaCategoryNameListResult extends WxOpenResult { + private static final long serialVersionUID = 8989721350285449879L; + + /** + * 类目名称列表. + */ + @SerializedName("category_name_list") + private List+ * 包含一级类目和二级类目的 ID 和名称。 + *
+ */ + @Data + public static class CategoryName implements Serializable { + private static final long serialVersionUID = 8989721350285449880L; + + /** + * 一级类目ID. + */ + @SerializedName("first_id") + private Integer firstId; + + /** + * 一级类目名称. + */ + @SerializedName("first_name") + private String firstName; + + /** + * 二级类目ID. + */ + @SerializedName("second_id") + private Integer secondId; + + /** + * 二级类目名称. + */ + @SerializedName("second_name") + private String secondName; + + @Override + public String toString() { + return WxOpenGsonBuilder.create().toJson(this); + } + } +}