Skip to content

Commit 6889e3d

Browse files
committed
添加门店信息查看的接口, for issue #17
1 parent 7478361 commit 6889e3d

File tree

5 files changed

+63
-29
lines changed

5 files changed

+63
-29
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package me.chanjar.weixin.mp.api;
22

3-
import java.util.List;
4-
53
import me.chanjar.weixin.common.exception.WxErrorException;
64
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
75
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
86
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
97

8+
import java.util.List;
9+
1010
/**
1111
* 门店管理的相关接口代码
1212
* @author binarywang(https://github.com/binarywang)
@@ -27,6 +27,21 @@ public interface WxMpStoreService {
2727
*/
2828
void add(WxMpStoreBaseInfo request) throws WxErrorException;
2929

30+
31+
/**
32+
* <pre>
33+
* 查询门店信息
34+
* 创建门店后获取poi_id 后,商户可以利用poi_id,查询具体某条门店的信息。
35+
* 若在查询时,update_status 字段为1,表明在5 个工作日内曾用update 接口修改过门店扩展字段,该扩展字段为最新的修改字段,尚未经过审核采纳,因此不是最终结果。
36+
* 最终结果会在5 个工作日内,最终确认是否采纳,并前端生效(但该扩展字段的采纳过程不影响门店的可用性,即available_state仍为审核通过状态)
37+
* 注:扩展字段为公共编辑信息(大家都可修改),修改将会审核,并决定是否对修改建议进行采纳,但不会影响该门店的生效可用状态。
38+
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a>
39+
* </pre>
40+
* @param poiId 门店poiId
41+
* @throws WxErrorException
42+
*/
43+
WxMpStoreBaseInfo get(String poiId) throws WxErrorException;
44+
3045
/**
3146
* <pre>
3247
* 查询门店列表(指定查询起始位置和个数)

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
package me.chanjar.weixin.mp.api.impl;
22

3-
import java.lang.reflect.Field;
4-
import java.util.List;
5-
import java.util.Map.Entry;
6-
7-
import org.joor.Reflect;
8-
93
import com.google.common.collect.Lists;
104
import com.google.gson.JsonObject;
11-
5+
import com.google.gson.JsonParser;
126
import me.chanjar.weixin.common.annotation.Required;
137
import me.chanjar.weixin.common.bean.result.WxError;
148
import me.chanjar.weixin.common.exception.WxErrorException;
@@ -17,6 +11,11 @@
1711
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
1812
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
1913
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
14+
import org.joor.Reflect;
15+
16+
import java.lang.reflect.Field;
17+
import java.util.List;
18+
import java.util.Map.Entry;
2019

2120
/**
2221
* Created by Binary Wang on 2016/9/26.
@@ -44,6 +43,20 @@ public void add(WxMpStoreBaseInfo request) throws WxErrorException {
4443
}
4544
}
4645

46+
@Override
47+
public WxMpStoreBaseInfo get(String poiId) throws WxErrorException {
48+
String url = API_BASE_URL + "/getpoi";
49+
JsonObject paramObject = new JsonObject();
50+
paramObject.addProperty("poi_id",poiId);
51+
String response = this.wxMpService.post(url, paramObject.toString());
52+
WxError wxError = WxError.fromJson(response);
53+
if (wxError.getErrorCode() != 0) {
54+
throw new WxErrorException(wxError);
55+
}
56+
return WxMpStoreBaseInfo.fromJson(new JsonParser().parse(response).getAsJsonObject()
57+
.get("business").getAsJsonObject().get("base_info").toString());
58+
}
59+
4760
private void checkParameters(WxMpStoreBaseInfo request) {
4861
List<String> nullFields = Lists.newArrayList();
4962
for (Entry<String, Reflect> entry : Reflect.on(request).fields()

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreBaseInfo.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package me.chanjar.weixin.mp.bean.store;
22

3-
import java.math.BigDecimal;
4-
import java.util.List;
5-
6-
import org.apache.commons.lang3.builder.ToStringBuilder;
7-
import org.apache.commons.lang3.builder.ToStringStyle;
8-
93
import com.google.gson.JsonElement;
104
import com.google.gson.JsonObject;
115
import com.google.gson.annotations.SerializedName;
12-
136
import me.chanjar.weixin.common.annotation.Required;
147
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
8+
import org.apache.commons.lang3.builder.ToStringBuilder;
9+
import org.apache.commons.lang3.builder.ToStringStyle;
10+
11+
import java.math.BigDecimal;
12+
import java.util.List;
1513

1614
/**
1715
* 门店基础信息
@@ -24,6 +22,10 @@ public String toString() {
2422
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
2523
}
2624

25+
public static WxMpStoreBaseInfo fromJson(String json) {
26+
return WxMpGsonBuilder.create().fromJson(json, WxMpStoreBaseInfo.class);
27+
}
28+
2729
public String toJson() {
2830
JsonElement base_info = WxMpGsonBuilder.create().toJsonTree(this);
2931
JsonObject jsonObject = new JsonObject();

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/store/WxMpStoreInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.chanjar.weixin.mp.bean.store;
22

3+
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
34
import org.apache.commons.lang3.builder.ToStringBuilder;
45
import org.apache.commons.lang3.builder.ToStringStyle;
56

@@ -22,4 +23,4 @@ public void setBaseInfo(WxMpStoreBaseInfo baseInfo) {
2223
this.baseInfo = baseInfo;
2324
}
2425

25-
}
26+
}

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package me.chanjar.weixin.mp.api.impl;
22

3-
import static org.junit.Assert.assertNotNull;
4-
5-
import java.math.BigDecimal;
6-
import java.util.List;
7-
8-
import org.testng.annotations.Guice;
9-
import org.testng.annotations.Test;
10-
113
import com.google.inject.Inject;
12-
134
import me.chanjar.weixin.common.exception.WxErrorException;
145
import me.chanjar.weixin.mp.api.ApiTestModule;
156
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
167
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
178
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
9+
import org.testng.annotations.Guice;
10+
import org.testng.annotations.Test;
11+
12+
import java.math.BigDecimal;
13+
import java.util.List;
14+
15+
import static org.junit.Assert.assertNotNull;
1816

1917
/**
2018
* @author 王彬 (Binary Wang)
@@ -28,18 +26,23 @@ public class WxMpStoreServiceImplTest {
2826

2927
/**
3028
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}.
31-
* @throws WxErrorException
29+
* @throws WxErrorException
3230
*/
3331
public void testAdd() throws WxErrorException {
3432
this.wxMpService.getStoreService()
3533
.add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc")
36-
.province("aaa").district("aaa").telephone("122").address("abc")
37-
.categories(new String[] { "美食,江浙菜" })
34+
.province("aaa").district("aaa").telephone("122").address("abc").categories(new String[] { "美食,江浙菜" })
3835
.longitude(new BigDecimal("115.32375"))
3936
.latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1)
4037
.build());
4138
}
4239

40+
public void testGet() throws WxErrorException {
41+
WxMpStoreBaseInfo result = this.wxMpService.getStoreService().get("291503654");
42+
assertNotNull(result);
43+
System.err.println(result);
44+
}
45+
4346
public void testList() throws WxErrorException {
4447
WxMpStoreListResult result = this.wxMpService.getStoreService().list(0, 10);
4548
assertNotNull(result);

0 commit comments

Comments
 (0)