Skip to content

Commit 8a5fdb1

Browse files
committed
添加查询门店类目列表的接口, for issue #17
1 parent 460a52b commit 8a5fdb1

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpStoreService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public interface WxMpStoreService {
3535
* 最终结果会在5 个工作日内,最终确认是否采纳,并前端生效(但该扩展字段的采纳过程不影响门店的可用性,即available_state仍为审核通过状态)
3636
* 注:扩展字段为公共编辑信息(大家都可修改),修改将会审核,并决定是否对修改建议进行采纳,但不会影响该门店的生效可用状态。
3737
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
38+
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoi?access_token=TOKEN
3839
* </pre>
3940
* @param poiId 门店Id
4041
* @throws WxErrorException
@@ -46,6 +47,7 @@ public interface WxMpStoreService {
4647
* 删除门店
4748
* 商户可以通过该接口,删除已经成功创建的门店。请商户慎重调用该接口。
4849
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
50+
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/delpoi?access_token=TOKEN
4951
* </pre>
5052
* @param poiId 门店Id
5153
* @throws WxErrorException
@@ -57,6 +59,7 @@ public interface WxMpStoreService {
5759
* 查询门店列表(指定查询起始位置和个数)
5860
* 商户可以通过该接口,批量查询自己名下的门店list,并获取已审核通过的poi_id(所有状态均会返回poi_id,但该poi_id不一定为最终id)、商户自身sid 用于对应、商户名、分店名、地址字段。
5961
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
62+
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN
6063
* </pre>
6164
* @param begin 开始位置,0 即为从第一条开始查询
6265
* @param limit 返回数据条数,最大允许50,默认为20
@@ -69,6 +72,7 @@ public interface WxMpStoreService {
6972
* 查询门店列表(所有)
7073
* 商户可以通过该接口,批量查询自己名下的门店list,并获取已审核通过的poi_id(所有状态均会返回poi_id,但该poi_id不一定为最终id)、商户自身sid 用于对应、商户名、分店名、地址字段。
7174
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
75+
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=TOKEN
7276
* </pre>
7377
* @throws WxErrorException
7478
*/
@@ -79,9 +83,21 @@ public interface WxMpStoreService {
7983
* 修改门店服务信息
8084
* 商户可以通过该接口,修改门店的服务信息,包括:sid、图片列表、营业时间、推荐、特色服务、简介、人均价格、电话8个字段(名称、坐标、地址等不可修改)修改后需要人工审核。
8185
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
86+
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/updatepoi?access_token=TOKEN
8287
* </pre>
8388
* @throws WxErrorException
8489
*/
8590
void update(WxMpStoreBaseInfo info) throws WxErrorException;
8691

92+
/**
93+
* <pre>
94+
* 门店类目表
95+
* 类目名称接口是为商户提供自己门店类型信息的接口。门店类目定位的越规范,能够精准的吸引更多用户,提高曝光率。
96+
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
97+
* 接口格式:http://api.weixin.qq.com/cgi-bin/poi/getwxcategory?access_token=TOKEN
98+
* </pre>
99+
* @throws WxErrorException
100+
*/
101+
List<String> listCategories() throws WxErrorException;
102+
87103
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.collect.Lists;
44
import com.google.gson.JsonObject;
55
import com.google.gson.JsonParser;
6+
import com.google.gson.reflect.TypeToken;
67
import me.chanjar.weixin.common.annotation.Required;
78
import me.chanjar.weixin.common.bean.result.WxError;
89
import me.chanjar.weixin.common.exception.WxErrorException;
@@ -11,6 +12,7 @@
1112
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
1213
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
1314
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
15+
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
1416
import org.joor.Reflect;
1517

1618
import java.lang.reflect.Field;
@@ -139,4 +141,18 @@ public void update(WxMpStoreBaseInfo request) throws WxErrorException {
139141
}
140142
}
141143

144+
@Override
145+
public List<String> listCategories() throws WxErrorException {
146+
String url = API_BASE_URL + "/getwxcategory";
147+
String response = this.wxMpService.get(url, null);
148+
WxError wxError = WxError.fromJson(response);
149+
if (wxError.getErrorCode() != 0) {
150+
throw new WxErrorException(wxError);
151+
}
152+
153+
return WxMpGsonBuilder.create().fromJson(
154+
new JsonParser().parse(response).getAsJsonObject().get("category_list"),
155+
new TypeToken<List<String>>(){}.getType());
156+
}
157+
142158
}

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpStoreServiceImplTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public void testDelete() throws WxErrorException {
5656
this.wxMpService.getStoreService().delete("463558057");
5757
}
5858

59+
public void testListCategories() throws WxErrorException {
60+
List<String> result = this.wxMpService.getStoreService().listCategories();
61+
assertNotNull(result);
62+
System.err.println(result);
63+
}
64+
5965
public void testList() throws WxErrorException {
6066
WxMpStoreListResult result = this.wxMpService.getStoreService().list(0, 10);
6167
assertNotNull(result);

0 commit comments

Comments
 (0)