@@ -1,12 +1,12 @@ | |||
package me.chanjar.weixin.mp.api; | |||
import java.util.List; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; | |||
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; | |||
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; | |||
import java.util.List; | |||
/** | |||
* 门店管理的相关接口代码 | |||
* @author binarywang(https://github.com/binarywang) | |||
@@ -27,6 +27,21 @@ public interface WxMpStoreService { | |||
*/ | |||
void add(WxMpStoreBaseInfo request) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 查询门店信息 | |||
* 创建门店后获取poi_id 后,商户可以利用poi_id,查询具体某条门店的信息。 | |||
* 若在查询时,update_status 字段为1,表明在5 个工作日内曾用update 接口修改过门店扩展字段,该扩展字段为最新的修改字段,尚未经过审核采纳,因此不是最终结果。 | |||
* 最终结果会在5 个工作日内,最终确认是否采纳,并前端生效(但该扩展字段的采纳过程不影响门店的可用性,即available_state仍为审核通过状态) | |||
* 注:扩展字段为公共编辑信息(大家都可修改),修改将会审核,并决定是否对修改建议进行采纳,但不会影响该门店的生效可用状态。 | |||
* 详情请见: <a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444378120&token=&lang=zh_CN">微信门店接口</a> | |||
* </pre> | |||
* @param poiId 门店poiId | |||
* @throws WxErrorException | |||
*/ | |||
WxMpStoreBaseInfo get(String poiId) throws WxErrorException; | |||
/** | |||
* <pre> | |||
* 查询门店列表(指定查询起始位置和个数) | |||
@@ -1,14 +1,8 @@ | |||
package me.chanjar.weixin.mp.api.impl; | |||
import java.lang.reflect.Field; | |||
import java.util.List; | |||
import java.util.Map.Entry; | |||
import org.joor.Reflect; | |||
import com.google.common.collect.Lists; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonParser; | |||
import me.chanjar.weixin.common.annotation.Required; | |||
import me.chanjar.weixin.common.bean.result.WxError; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
@@ -17,6 +11,11 @@ import me.chanjar.weixin.mp.api.WxMpStoreService; | |||
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; | |||
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; | |||
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; | |||
import org.joor.Reflect; | |||
import java.lang.reflect.Field; | |||
import java.util.List; | |||
import java.util.Map.Entry; | |||
/** | |||
* Created by Binary Wang on 2016/9/26. | |||
@@ -44,6 +43,20 @@ public class WxMpStoreServiceImpl implements WxMpStoreService { | |||
} | |||
} | |||
@Override | |||
public WxMpStoreBaseInfo get(String poiId) throws WxErrorException { | |||
String url = API_BASE_URL + "/getpoi"; | |||
JsonObject paramObject = new JsonObject(); | |||
paramObject.addProperty("poi_id",poiId); | |||
String response = this.wxMpService.post(url, paramObject.toString()); | |||
WxError wxError = WxError.fromJson(response); | |||
if (wxError.getErrorCode() != 0) { | |||
throw new WxErrorException(wxError); | |||
} | |||
return WxMpStoreBaseInfo.fromJson(new JsonParser().parse(response).getAsJsonObject() | |||
.get("business").getAsJsonObject().get("base_info").toString()); | |||
} | |||
private void checkParameters(WxMpStoreBaseInfo request) { | |||
List<String> nullFields = Lists.newArrayList(); | |||
for (Entry<String, Reflect> entry : Reflect.on(request).fields() | |||
@@ -1,17 +1,15 @@ | |||
package me.chanjar.weixin.mp.bean.store; | |||
import java.math.BigDecimal; | |||
import java.util.List; | |||
import org.apache.commons.lang3.builder.ToStringBuilder; | |||
import org.apache.commons.lang3.builder.ToStringStyle; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.annotations.SerializedName; | |||
import me.chanjar.weixin.common.annotation.Required; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
import org.apache.commons.lang3.builder.ToStringBuilder; | |||
import org.apache.commons.lang3.builder.ToStringStyle; | |||
import java.math.BigDecimal; | |||
import java.util.List; | |||
/** | |||
* 门店基础信息 | |||
@@ -24,6 +22,10 @@ public class WxMpStoreBaseInfo { | |||
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | |||
} | |||
public static WxMpStoreBaseInfo fromJson(String json) { | |||
return WxMpGsonBuilder.create().fromJson(json, WxMpStoreBaseInfo.class); | |||
} | |||
public String toJson() { | |||
JsonElement base_info = WxMpGsonBuilder.create().toJsonTree(this); | |||
JsonObject jsonObject = new JsonObject(); | |||
@@ -1,5 +1,6 @@ | |||
package me.chanjar.weixin.mp.bean.store; | |||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
import org.apache.commons.lang3.builder.ToStringBuilder; | |||
import org.apache.commons.lang3.builder.ToStringStyle; | |||
@@ -22,4 +23,4 @@ public class WxMpStoreInfo { | |||
this.baseInfo = baseInfo; | |||
} | |||
} | |||
} |
@@ -1,20 +1,18 @@ | |||
package me.chanjar.weixin.mp.api.impl; | |||
import static org.junit.Assert.assertNotNull; | |||
import java.math.BigDecimal; | |||
import java.util.List; | |||
import org.testng.annotations.Guice; | |||
import org.testng.annotations.Test; | |||
import com.google.inject.Inject; | |||
import me.chanjar.weixin.common.exception.WxErrorException; | |||
import me.chanjar.weixin.mp.api.ApiTestModule; | |||
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; | |||
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; | |||
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; | |||
import org.testng.annotations.Guice; | |||
import org.testng.annotations.Test; | |||
import java.math.BigDecimal; | |||
import java.util.List; | |||
import static org.junit.Assert.assertNotNull; | |||
/** | |||
* @author 王彬 (Binary Wang) | |||
@@ -28,18 +26,23 @@ public class WxMpStoreServiceImplTest { | |||
/** | |||
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}. | |||
* @throws WxErrorException | |||
* @throws WxErrorException | |||
*/ | |||
public void testAdd() throws WxErrorException { | |||
this.wxMpService.getStoreService() | |||
.add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") | |||
.province("aaa").district("aaa").telephone("122").address("abc") | |||
.categories(new String[] { "美食,江浙菜" }) | |||
.province("aaa").district("aaa").telephone("122").address("abc").categories(new String[] { "美食,江浙菜" }) | |||
.longitude(new BigDecimal("115.32375")) | |||
.latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) | |||
.build()); | |||
} | |||
public void testGet() throws WxErrorException { | |||
WxMpStoreBaseInfo result = this.wxMpService.getStoreService().get("291503654"); | |||
assertNotNull(result); | |||
System.err.println(result); | |||
} | |||
public void testList() throws WxErrorException { | |||
WxMpStoreListResult result = this.wxMpService.getStoreService().list(0, 10); | |||
assertNotNull(result); | |||