From 358f74ea211939b5cecb2161fdae5094f4ddfed7 Mon Sep 17 00:00:00 2001 From: liming Date: Fri, 6 Aug 2021 10:27:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=BB=84=E4=BB=B6=E7=94=B3=E8=AF=B7=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaService.java | 6 ++ .../miniapp/api/WxMaShopRegisterService.java | 46 +++++++++++++ .../miniapp/api/impl/BaseWxMaServiceImpl.java | 6 ++ .../api/impl/WxMaShopRegisterServiceImpl.java | 68 +++++++++++++++++++ .../WxMaShopRegisterApplySceneRequest.java | 22 ++++++ ...MaShopRegisterFinishAccessInfoRequest.java | 21 ++++++ .../WxMaShopRegisterCheckResponse.java | 22 ++++++ .../miniapp/constant/WxMaApiUrlConstants.java | 7 ++ .../impl/WxMaLiveGoodsServiceImplTest.java | 9 +-- .../impl/WxMaShopRegisterServiceImplTest.java | 51 ++++++++++++++ 10 files changed, 254 insertions(+), 4 deletions(-) create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopRegisterService.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImpl.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterApplySceneRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterFinishAccessInfoRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopRegisterCheckResponse.java create mode 100644 weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImplTest.java diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java index 962424430f..e8a7d622f2 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java @@ -403,6 +403,12 @@ public interface WxMaService extends WxService { */ WxMaShopSpuService getShopSpuService(); + /** + * 返回小程序交易组件-接入申请接口 + * @return + */ + WxMaShopRegisterService getShopRegisterService(); + /** * 获取小程序 URL Link服务接口 * @return diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopRegisterService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopRegisterService.java new file mode 100644 index 0000000000..67e1f2bcd1 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopRegisterService.java @@ -0,0 +1,46 @@ +package cn.binarywang.wx.miniapp.api; + +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterApplySceneRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterFinishAccessInfoRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopRegisterCheckResponse; +import me.chanjar.weixin.common.error.WxErrorException; + +/** + * 小程序交易组件-申请接入服务 + * + * @author liming1019 + */ +public interface WxMaShopRegisterService { + /** + * 接入申请 + * + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + WxMaShopBaseResponse registerApply() throws WxErrorException; + + /** + * 获取接入状态 + * + * @return WxMaShopRegisterCheckResponse + * @throws WxErrorException + */ + WxMaShopRegisterCheckResponse registerCheck() throws WxErrorException; + + /** + * 完成接入任务 + * + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + WxMaShopBaseResponse registerFinishAccessInfo(WxMaShopRegisterFinishAccessInfoRequest request) throws WxErrorException; + + /** + * 场景接入申请 + * + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + WxMaShopBaseResponse registerApplyScene(WxMaShopRegisterApplySceneRequest request) throws WxErrorException; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java index 417f49801d..95829f151f 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java @@ -65,6 +65,7 @@ public abstract class BaseWxMaServiceImpl implements WxMaService, RequestH private final WxImgProcService imgProcService = new WxMaImgProcServiceImpl(this); private final WxMaShopSpuService shopSpuService = new WxMaShopSpuServiceImpl(this); private final WxMaShopOrderService shopOrderService = new WxMaShopOrderServiceImpl(this); + private final WxMaShopRegisterService shopRegisterService = new WxMaShopRegisterServiceImpl(this); private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this); private final WxMaReimburseInvoiceService reimburseInvoiceService = new WxMaReimburseInvoiceServiceImpl(this); private Map configMap; @@ -516,6 +517,11 @@ public WxMaShopOrderService getShopOrderService() { return this.shopOrderService; } + @Override + public WxMaShopRegisterService getShopRegisterService() { + return this.shopRegisterService; + } + @Override public WxMaLinkService getLinkService() { return this.linkService; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImpl.java new file mode 100644 index 0000000000..ac69dcab47 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImpl.java @@ -0,0 +1,68 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.WxMaShopRegisterService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterApplySceneRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterFinishAccessInfoRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopRegisterCheckResponse; +import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; +import com.google.gson.JsonObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.enums.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.json.GsonParser; + +import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Register.*; + +/** + * @author liming1019 + */ +@RequiredArgsConstructor +@Slf4j +public class WxMaShopRegisterServiceImpl implements WxMaShopRegisterService { + private static final String ERR_CODE = "errcode"; + private final WxMaService wxMaService; + + @Override + public WxMaShopBaseResponse registerApply() throws WxErrorException { + String responseContent = this.wxMaService.post(REGISTER_APPLY, new JsonObject()); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); + } + + @Override + public WxMaShopRegisterCheckResponse registerCheck() throws WxErrorException { + String responseContent = this.wxMaService.post(REGISTER_CHECK, new JsonObject()); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopRegisterCheckResponse.class); + } + + @Override + public WxMaShopBaseResponse registerFinishAccessInfo(WxMaShopRegisterFinishAccessInfoRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(REGISTER_FINISH_ACCESS_INFO, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); + } + + @Override + public WxMaShopBaseResponse registerApplyScene(WxMaShopRegisterApplySceneRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(REGISTER_APPLY_SCENE, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterApplySceneRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterApplySceneRequest.java new file mode 100644 index 0000000000..bec18e27f1 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterApplySceneRequest.java @@ -0,0 +1,22 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/6 + */ +@Data +public class WxMaShopRegisterApplySceneRequest implements Serializable { + + private static final long serialVersionUID = -3008686013597621522L; + /** + * 1:视频号、公众号场景 + */ + @SerializedName("scene_group_id") + private Long sceneGroupId; +} + diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterFinishAccessInfoRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterFinishAccessInfoRequest.java new file mode 100644 index 0000000000..6b2999e2f2 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopRegisterFinishAccessInfoRequest.java @@ -0,0 +1,21 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/6 + */ +@Data +public class WxMaShopRegisterFinishAccessInfoRequest implements Serializable { + private static final long serialVersionUID = 8679586799807671563L; + /** + * 6:完成spu接口,7:完成订单接口,8:完成物流接口,9:完成售后接口,10:测试完成,11:发版完成 + */ + @SerializedName("access_info_item") + private Long accessInfoItem; +} + diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopRegisterCheckResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopRegisterCheckResponse.java new file mode 100644 index 0000000000..494a70ff42 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopRegisterCheckResponse.java @@ -0,0 +1,22 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import com.google.gson.JsonObject; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/5 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopRegisterCheckResponse extends WxMaShopBaseResponse implements Serializable { + + private static final long serialVersionUID = 9061844525630614116L; + + @SerializedName("data") + private JsonObject data; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java index d2d15b8f50..3ec46a5caa 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java @@ -319,6 +319,13 @@ interface Order { String ORDER_PAY = "https://api.weixin.qq.com/shop/order/pay"; String ORDER_GET = "https://api.weixin.qq.com/shop/order/get"; } + + interface Register { + String REGISTER_APPLY = "https://api.weixin.qq.com/shop/register/apply"; + String REGISTER_CHECK = "https://api.weixin.qq.com/shop/register/check"; + String REGISTER_FINISH_ACCESS_INFO = "https://api.weixin.qq.com/shop/register/finish_access_info"; + String REGISTER_APPLY_SCENE = "https://api.weixin.qq.com/shop/register/apply_scene"; + } } /** diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImplTest.java index af068777ee..ccf073a534 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImplTest.java @@ -10,6 +10,7 @@ import org.testng.annotations.Test; import java.io.File; +import java.math.BigDecimal; import java.util.Arrays; import static org.testng.Assert.assertNotNull; @@ -34,8 +35,8 @@ public void addGoods() throws Exception { WxMaLiveGoodInfo goods = new WxMaLiveGoodInfo(); goods.setCoverImgUrl(mediaUpload.getMediaId()); goods.setName("宫廷奢华真丝四件套"); - goods.setPrice("1599"); - goods.setPrice2("0"); + goods.setPrice(new BigDecimal("1599")); + goods.setPrice2(new BigDecimal("0")); goods.setPriceType(1); goods.setUrl("pages/goods/goods?id=b7c4fbf95493bd294054fe4296d0d9ad"); WxMaLiveResult liveResult = this.wxService.getLiveGoodsService().addGoods(goods); @@ -68,8 +69,8 @@ public void updateGoods() throws Exception { goods.setGoodsId(8); goods.setName("宫廷奢华真丝四件套"); goods.setCoverImgUrl("http://mmbiz.qpic.cn/mmbiz_png/omYktZNGamuUQE0WPVfqdnLV61JDhluXOac7PiaoZeticFpcR7wvicC0aXUC2VXkl7r1gN0QSKosv2satn6oCFeiaQ/0"); - goods.setPrice("2299"); - goods.setPrice2("0"); + goods.setPrice(new BigDecimal("2299")); + goods.setPrice2(new BigDecimal("0")); goods.setPriceType(1); goods.setUrl("pages/goods/goods?id=b7c4fbf95493bd294054fe4296d0d9ad"); boolean maLiveInfo = this.wxService.getLiveGoodsService().updateGoods(goods); diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImplTest.java new file mode 100644 index 0000000000..311b183ac5 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopRegisterServiceImplTest.java @@ -0,0 +1,51 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterApplySceneRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterFinishAccessInfoRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopRegisterCheckResponse; +import cn.binarywang.wx.miniapp.test.ApiTestModule; +import com.google.inject.Inject; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author liming1019 + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaShopRegisterServiceImplTest { + @Inject + private WxMaService wxService; + + @Test + public void testRegisterApply() throws Exception { + WxMaShopBaseResponse response = this.wxService.getShopRegisterService().registerApply(); + assertThat(response).isNotNull(); + } + + @Test + public void testRegisterCheck() throws Exception { + WxMaShopRegisterCheckResponse response = this.wxService.getShopRegisterService().registerCheck(); + assertThat(response).isNotNull(); + } + + @Test + public void testRegisterFinishAccessInfo() throws Exception { + WxMaShopRegisterFinishAccessInfoRequest request = new WxMaShopRegisterFinishAccessInfoRequest(); + request.setAccessInfoItem(6L); + WxMaShopBaseResponse response = this.wxService.getShopRegisterService().registerFinishAccessInfo(request); + assertThat(response).isNotNull(); + } + + @Test + public void testRegisterApplyScene() throws Exception { + WxMaShopRegisterApplySceneRequest request = new WxMaShopRegisterApplySceneRequest(); + request.setSceneGroupId(1L); + WxMaShopBaseResponse response = this.wxService.getShopRegisterService().registerApplyScene(request); + assertThat(response).isNotNull(); + } +} From 0d4fdbc1125242ec6a42ca9dfbb2c92f726b02f1 Mon Sep 17 00:00:00 2001 From: liming Date: Mon, 9 Aug 2021 16:09:39 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6=E4=B9=8B?= =?UTF-8?q?=E5=95=86=E5=AE=B6=E5=85=A5=E9=A9=BB=E7=9B=B8=E5=85=B3=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaService.java | 6 ++ .../miniapp/api/WxMaShopAccountService.java | 48 +++++++++++++ .../miniapp/api/impl/BaseWxMaServiceImpl.java | 6 ++ .../api/impl/WxMaShopAccountServiceImpl.java | 69 +++++++++++++++++++ .../shop/WxMaShopAccountGetBrandListItem.java | 28 ++++++++ .../WxMaShopAccountGetCategoryListItem.java | 48 +++++++++++++ .../bean/shop/WxMaShopAccountGetInfo.java | 26 +++++++ .../WxMaShopAccountUpdateInfoRequest.java | 26 +++++++ .../WxMaShopAccountGetBrandListResponse.java | 22 ++++++ ...xMaShopAccountGetCategoryListResponse.java | 22 ++++++ .../WxMaShopAccountGetInfoResponse.java | 21 ++++++ .../miniapp/constant/WxMaApiUrlConstants.java | 7 ++ .../impl/WxMaShopAccountServiceImplTest.java | 51 ++++++++++++++ 13 files changed, 380 insertions(+) create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAccountService.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImpl.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetBrandListItem.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetCategoryListItem.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetInfo.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAccountUpdateInfoRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetBrandListResponse.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetCategoryListResponse.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetInfoResponse.java create mode 100644 weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImplTest.java diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java index e8a7d622f2..aec8dd438c 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java @@ -409,6 +409,12 @@ public interface WxMaService extends WxService { */ WxMaShopRegisterService getShopRegisterService(); + /** + * 返回小程序交易组件-商户入驻接口 + * @return + */ + WxMaShopAccountService getShopAccountService(); + /** * 获取小程序 URL Link服务接口 * @return diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAccountService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAccountService.java new file mode 100644 index 0000000000..25a487c83f --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAccountService.java @@ -0,0 +1,48 @@ +package cn.binarywang.wx.miniapp.api; + +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAccountUpdateInfoRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAccountGetBrandListResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAccountGetCategoryListResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAccountGetInfoResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +import me.chanjar.weixin.common.error.WxErrorException; + +/** + * 小程序交易组件-商家入驻接口 + * + * @author liming1019 + */ +public interface WxMaShopAccountService { + /** + * 获取商家类目列表 + * + * @return WxMaShopAccountGetCategoryListResponse + * @throws WxErrorException + */ + WxMaShopAccountGetCategoryListResponse getCategoryList() throws WxErrorException; + + /** + * 获取商家品牌列表 + * + * @return WxMaShopAccountGetBrandListResponse + * @throws WxErrorException + */ + WxMaShopAccountGetBrandListResponse getBrandList() throws WxErrorException; + + /** + * 更新商家信息 + * + * @param request + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + WxMaShopBaseResponse updateInfo(WxMaShopAccountUpdateInfoRequest request) throws WxErrorException; + + /** + * 获取商家信息 + * + * @return WxMaShopAccountGetInfoResponse + * @throws WxErrorException + */ + WxMaShopAccountGetInfoResponse getInfo() throws WxErrorException; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java index 95829f151f..4ed552a6af 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java @@ -66,6 +66,7 @@ public abstract class BaseWxMaServiceImpl implements WxMaService, RequestH private final WxMaShopSpuService shopSpuService = new WxMaShopSpuServiceImpl(this); private final WxMaShopOrderService shopOrderService = new WxMaShopOrderServiceImpl(this); private final WxMaShopRegisterService shopRegisterService = new WxMaShopRegisterServiceImpl(this); + private final WxMaShopAccountService shopAccountService = new WxMaShopAccountServiceImpl(this); private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this); private final WxMaReimburseInvoiceService reimburseInvoiceService = new WxMaReimburseInvoiceServiceImpl(this); private Map configMap; @@ -522,6 +523,11 @@ public WxMaShopRegisterService getShopRegisterService() { return this.shopRegisterService; } + @Override + public WxMaShopAccountService getShopAccountService() { + return this.shopAccountService; + } + @Override public WxMaLinkService getLinkService() { return this.linkService; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImpl.java new file mode 100644 index 0000000000..00ea99850c --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImpl.java @@ -0,0 +1,69 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.WxMaShopAccountService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAccountUpdateInfoRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAccountGetBrandListResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAccountGetCategoryListResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAccountGetInfoResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; +import com.google.gson.JsonObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.enums.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.json.GsonParser; + +import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Account.*; + +/** + * @author liming1019 + */ +@RequiredArgsConstructor +@Slf4j +public class WxMaShopAccountServiceImpl implements WxMaShopAccountService { + private static final String ERR_CODE = "errcode"; + private final WxMaService wxMaService; + + @Override + public WxMaShopAccountGetCategoryListResponse getCategoryList() throws WxErrorException { + String responseContent = this.wxMaService.post(GET_CATEGORY_LIST, new JsonObject()); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetCategoryListResponse.class); + } + + @Override + public WxMaShopAccountGetBrandListResponse getBrandList() throws WxErrorException { + String responseContent = this.wxMaService.post(GET_BRAND_LIST, new JsonObject()); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetBrandListResponse.class); + } + + @Override + public WxMaShopBaseResponse updateInfo(WxMaShopAccountUpdateInfoRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(UPDATE_INFO, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); + } + + @Override + public WxMaShopAccountGetInfoResponse getInfo() throws WxErrorException { + String responseContent = this.wxMaService.post(GET_INFO, new JsonObject()); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetInfoResponse.class); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetBrandListItem.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetBrandListItem.java new file mode 100644 index 0000000000..48019b2420 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetBrandListItem.java @@ -0,0 +1,28 @@ +package cn.binarywang.wx.miniapp.bean.shop; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/9 + */ +@Data +public class WxMaShopAccountGetBrandListItem implements Serializable { + private static final long serialVersionUID = -8889271375365538573L; + + /** + * 品牌ID + */ + @SerializedName("brand_id") + private Long brandId; + + /** + * 品牌名称 + */ + @SerializedName("brand_wording") + private String brandWording; +} + diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetCategoryListItem.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetCategoryListItem.java new file mode 100644 index 0000000000..987ff074d5 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetCategoryListItem.java @@ -0,0 +1,48 @@ +package cn.binarywang.wx.miniapp.bean.shop; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/9 + */ +@Data +public class WxMaShopAccountGetCategoryListItem implements Serializable { + private static final long serialVersionUID = -6574489801942310752L; + + /** + * 一级类目ID + */ + @SerializedName("first_cat_id") + private Long firstCatId; + /** + * 二级类目ID + */ + @SerializedName("second_cat_id") + private Long secondCatId; + /** + * 类目ID + */ + @SerializedName("third_cat_id") + private Long thirdCatId; + /** + * 一级类目名称 + */ + @SerializedName("first_cat_name") + private String firstCatName; + /** + * 二级类目名称 + */ + @SerializedName("second_cat_name") + private String secondCatName; + + /** + * 类目名称 + */ + @SerializedName("third_cat_name") + private String thirdCatName; +} + diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetInfo.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetInfo.java new file mode 100644 index 0000000000..7c0fd95cbd --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopAccountGetInfo.java @@ -0,0 +1,26 @@ +package cn.binarywang.wx.miniapp.bean.shop; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/9 + */ +@Data +public class WxMaShopAccountGetInfo implements Serializable { + /** + * 品牌ID + */ + @SerializedName("brand_id") + private Long brandId; + + /** + * 品牌名称 + */ + @SerializedName("brand_wording") + private String brandWording; +} + diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAccountUpdateInfoRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAccountUpdateInfoRequest.java new file mode 100644 index 0000000000..8e74f6b4a9 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAccountUpdateInfoRequest.java @@ -0,0 +1,26 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/9 + */ +@Data +public class WxMaShopAccountUpdateInfoRequest implements Serializable { + private static final long serialVersionUID = 5185978220275730559L; + /** + * 小程序path + */ + @SerializedName("service_agent_path") + private String serviceAgentPath; + + /** + * 小程序path + */ + @SerializedName("service_agent_phone") + private String serviceAgentPhone; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetBrandListResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetBrandListResponse.java new file mode 100644 index 0000000000..a734126bc4 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetBrandListResponse.java @@ -0,0 +1,22 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import cn.binarywang.wx.miniapp.bean.shop.WxMaShopAccountGetBrandListItem; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +/** + * @author liming1019 + * @date 2021/8/9 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopAccountGetBrandListResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = -5196210913054514206L; + + @SerializedName("data") + private List items; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetCategoryListResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetCategoryListResponse.java new file mode 100644 index 0000000000..ba9ccee563 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetCategoryListResponse.java @@ -0,0 +1,22 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import cn.binarywang.wx.miniapp.bean.shop.WxMaShopAccountGetCategoryListItem; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +/** + * @author liming1019 + * @date 2021/8/9 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopAccountGetCategoryListResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = -3182300077261435356L; + + @SerializedName("data") + private List items; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetInfoResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetInfoResponse.java new file mode 100644 index 0000000000..f14a59ae5a --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAccountGetInfoResponse.java @@ -0,0 +1,21 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import cn.binarywang.wx.miniapp.bean.shop.WxMaShopAccountGetInfo; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/9 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopAccountGetInfoResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = -3954383181691898592L; + + @SerializedName("data") + private WxMaShopAccountGetInfo data; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java index 3ec46a5caa..d6e70788fb 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java @@ -326,6 +326,13 @@ interface Register { String REGISTER_FINISH_ACCESS_INFO = "https://api.weixin.qq.com/shop/register/finish_access_info"; String REGISTER_APPLY_SCENE = "https://api.weixin.qq.com/shop/register/apply_scene"; } + + interface Account { + String GET_CATEGORY_LIST = "https://api.weixin.qq.com/shop/account/get_category_list"; + String GET_BRAND_LIST = "https://api.weixin.qq.com/shop/account/get_brand_list"; + String UPDATE_INFO = "https://api.weixin.qq.com/shop/account/update_info"; + String GET_INFO = "https://api.weixin.qq.com/shop/account/get_info"; + } } /** diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImplTest.java new file mode 100644 index 0000000000..44c8f97e04 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAccountServiceImplTest.java @@ -0,0 +1,51 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAccountUpdateInfoRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterApplySceneRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopRegisterFinishAccessInfoRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.*; +import cn.binarywang.wx.miniapp.test.ApiTestModule; +import com.google.inject.Inject; +import me.chanjar.weixin.common.error.WxErrorException; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author liming1019 + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaShopAccountServiceImplTest { + @Inject + private WxMaService wxService; + + @Test + public void testGetCategoryList() throws WxErrorException { + WxMaShopAccountGetCategoryListResponse response = this.wxService.getShopAccountService().getCategoryList(); + assertThat(response).isNotNull(); + } + + @Test + public void testGetBrandList() throws WxErrorException { + WxMaShopAccountGetBrandListResponse response = this.wxService.getShopAccountService().getBrandList(); + assertThat(response).isNotNull(); + } + + @Test + public void testUpdateInfo() throws WxErrorException { + WxMaShopAccountUpdateInfoRequest request = new WxMaShopAccountUpdateInfoRequest(); + request.setServiceAgentPhone("020-888888"); + request.setServiceAgentPath("https://www.web.com"); + WxMaShopBaseResponse response = this.wxService.getShopAccountService().updateInfo(request); + assertThat(response).isNotNull(); + } + + @Test + public void testGetInfo() throws WxErrorException { + WxMaShopAccountGetInfoResponse response = this.wxService.getShopAccountService().getInfo(); + assertThat(response).isNotNull(); + } +} From 5610d66bac5c97aba10ab7a726eda1793ac76af0 Mon Sep 17 00:00:00 2001 From: liming Date: Mon, 9 Aug 2021 18:31:17 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6=E4=B9=8B?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=95=86=E5=93=81=E7=B1=BB=E7=9B=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaService.java | 13 ++++ .../wx/miniapp/api/WxMaShopCatService.java | 19 +++++ .../miniapp/api/impl/BaseWxMaServiceImpl.java | 6 ++ .../api/impl/WxMaShopCatServiceImpl.java | 35 +++++++++ .../bean/shop/WxMaShopCatGetDetail.java | 75 +++++++++++++++++++ .../shop/response/WxMaShopCatGetResponse.java | 22 ++++++ .../miniapp/constant/WxMaApiUrlConstants.java | 4 + .../api/impl/WxMaShopCatServiceImplTest.java | 28 +++++++ 8 files changed, 202 insertions(+) create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopCatService.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImpl.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopCatGetDetail.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopCatGetResponse.java create mode 100644 weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImplTest.java diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java index aec8dd438c..7b311952e8 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java @@ -393,36 +393,49 @@ public interface WxMaService extends WxService { /** * 返回小程序交易组件-订单服务接口 + * * @return */ WxMaShopOrderService getShopOrderService(); /** * 返回小程序交易组件-spu商品服务接口 + * * @return */ WxMaShopSpuService getShopSpuService(); /** * 返回小程序交易组件-接入申请接口 + * * @return */ WxMaShopRegisterService getShopRegisterService(); /** * 返回小程序交易组件-商户入驻接口 + * * @return */ WxMaShopAccountService getShopAccountService(); + /** + * 小程序交易组件-接入商品前必需接口-类目相关 + * + * @return + */ + WxMaShopCatService getShopCatService(); + /** * 获取小程序 URL Link服务接口 + * * @return */ WxMaLinkService getLinkService(); /** * 获取电子发票报销方服务接口 + * * @return */ WxMaReimburseInvoiceService getReimburseInvoiceService(); diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopCatService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopCatService.java new file mode 100644 index 0000000000..1f826fc24c --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopCatService.java @@ -0,0 +1,19 @@ +package cn.binarywang.wx.miniapp.api; + +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopCatGetResponse; +import me.chanjar.weixin.common.error.WxErrorException; + +/** + * 小程序交易组件-接入商品前必需接口 + * + * @author liming1019 + */ +public interface WxMaShopCatService { + /** + * 获取商品类目 + * + * @return WxMaShopCatGetResponse + * @throws WxErrorException + */ + WxMaShopCatGetResponse getCat() throws WxErrorException; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java index 4ed552a6af..48cd6f4189 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java @@ -67,6 +67,7 @@ public abstract class BaseWxMaServiceImpl implements WxMaService, RequestH private final WxMaShopOrderService shopOrderService = new WxMaShopOrderServiceImpl(this); private final WxMaShopRegisterService shopRegisterService = new WxMaShopRegisterServiceImpl(this); private final WxMaShopAccountService shopAccountService = new WxMaShopAccountServiceImpl(this); + private final WxMaShopCatService shopCatService = new WxMaShopCatServiceImpl(this); private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this); private final WxMaReimburseInvoiceService reimburseInvoiceService = new WxMaReimburseInvoiceServiceImpl(this); private Map configMap; @@ -528,6 +529,11 @@ public WxMaShopAccountService getShopAccountService() { return this.shopAccountService; } + @Override + public WxMaShopCatService getShopCatService() { + return this.shopCatService; + } + @Override public WxMaLinkService getLinkService() { return this.linkService; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImpl.java new file mode 100644 index 0000000000..8bf9411f4a --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImpl.java @@ -0,0 +1,35 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.WxMaShopCatService; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopCatGetResponse; +import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; +import com.google.gson.JsonObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.enums.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.json.GsonParser; + +import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Cat.GET_CAT; +import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE; + +/** + * @author liming1019 + */ +@RequiredArgsConstructor +@Slf4j +public class WxMaShopCatServiceImpl implements WxMaShopCatService { + private final WxMaService wxMaService; + + @Override + public WxMaShopCatGetResponse getCat() throws WxErrorException { + String responseContent = this.wxMaService.post(GET_CAT, new JsonObject()); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopCatGetResponse.class); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopCatGetDetail.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopCatGetDetail.java new file mode 100644 index 0000000000..3c8f752dd8 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/WxMaShopCatGetDetail.java @@ -0,0 +1,75 @@ +package cn.binarywang.wx.miniapp.bean.shop; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/9 + */ +@Data +public class WxMaShopCatGetDetail implements Serializable { + private static final long serialVersionUID = -3404372682043466685L; + + /** + * 类目ID + */ + @SerializedName("third_cat_id") + private Long thirdCatId; + + /** + * 类目名称 + */ + @SerializedName("third_cat_name") + private String thirdCatName; + + /** + * 类目资质 + */ + @SerializedName("qualification") + private String qualification; + + /** + * 类目资质类型,0:不需要,1:必填,2:选填 + */ + @SerializedName("qualification_type") + private Integer qualificationType; + + /** + * 商品资质 + */ + @SerializedName("product_qualification") + private String productQualification; + + /** + * 商品资质类型,0:不需要,1:必填,2:选填 + */ + @SerializedName("product_qualification_type") + private Integer productQualificationType; + + /** + * 一级类目ID + */ + @SerializedName("first_cat_id") + private Long firstCatId; + + /** + * 一级类目名称 + */ + @SerializedName("first_cat_name") + private String firstCatName; + + /** + * 二级类目ID + */ + @SerializedName("second_cat_id") + private Long secondCatId; + + /** + * 二级类目名称 + */ + @SerializedName("second_cat_name") + private String secondCatName; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopCatGetResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopCatGetResponse.java new file mode 100644 index 0000000000..2077027f29 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopCatGetResponse.java @@ -0,0 +1,22 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import cn.binarywang.wx.miniapp.bean.shop.WxMaShopCatGetDetail; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +/** + * @author liming1019 + * @date 2021/8/9 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopCatGetResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = -2565959470798387313L; + + @SerializedName("third_cat_list") + private List thirdCatList; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java index d6e70788fb..c6b428db85 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java @@ -333,6 +333,10 @@ interface Account { String UPDATE_INFO = "https://api.weixin.qq.com/shop/account/update_info"; String GET_INFO = "https://api.weixin.qq.com/shop/account/get_info"; } + + interface Cat { + String GET_CAT = "https://api.weixin.qq.com/shop/cat/get"; + } } /** diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImplTest.java new file mode 100644 index 0000000000..89b31083a0 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopCatServiceImplTest.java @@ -0,0 +1,28 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopCatGetResponse; +import cn.binarywang.wx.miniapp.test.ApiTestModule; +import com.google.inject.Inject; +import me.chanjar.weixin.common.error.WxErrorException; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author liming1019 + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaShopCatServiceImplTest { + + @Inject + private WxMaService wxService; + + @Test + public void testGetCat() throws WxErrorException { + WxMaShopCatGetResponse response = this.wxService.getShopCatService().getCat(); + assertThat(response).isNotNull(); + } +} From c9717ff03d7c17a5ff9448fa2cdf4feded329a3f Mon Sep 17 00:00:00 2001 From: liming Date: Tue, 10 Aug 2021 17:41:39 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6=E4=B9=8B=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WxMinishopImageUploadCustomizeResult.java | 38 ++++++++++++ .../WxMinishopPicFileCustomizeResult.java | 11 ++++ ...inishopUploadRequestCustomizeExecutor.java | 37 ++++++++++++ ...opMediaUploadRequestCustomizeExecutor.java | 58 +++++++++++++++++++ ...opMediaUploadRequestCustomizeExecutor.java | 49 ++++++++++++++++ ...opMediaUploadRequestCustomizeExecutor.java | 47 +++++++++++++++ .../wx/miniapp/api/WxMaService.java | 7 +++ .../wx/miniapp/api/WxMaShopImgService.java | 21 +++++++ .../miniapp/api/impl/BaseWxMaServiceImpl.java | 6 ++ .../api/impl/WxMaShopImgServiceImpl.java | 29 ++++++++++ .../miniapp/constant/WxMaApiUrlConstants.java | 4 ++ .../api/impl/WxMaShopImgServiceImplTest.java | 31 ++++++++++ 12 files changed, 338 insertions(+) create mode 100644 weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMinishopImageUploadCustomizeResult.java create mode 100644 weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMinishopPicFileCustomizeResult.java create mode 100644 weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MinishopUploadRequestCustomizeExecutor.java create mode 100644 weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMinishopMediaUploadRequestCustomizeExecutor.java create mode 100644 weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMinishopMediaUploadRequestCustomizeExecutor.java create mode 100644 weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMinishopMediaUploadRequestCustomizeExecutor.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopImgService.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImpl.java create mode 100644 weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImplTest.java diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMinishopImageUploadCustomizeResult.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMinishopImageUploadCustomizeResult.java new file mode 100644 index 0000000000..e3077fd00a --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMinishopImageUploadCustomizeResult.java @@ -0,0 +1,38 @@ +package me.chanjar.weixin.common.bean.result; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import lombok.Data; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; + +import java.io.Serializable; + +@Data +public class WxMinishopImageUploadCustomizeResult implements Serializable { + private String errcode; + private String errmsg; + + private WxMinishopPicFileCustomizeResult imgInfo; + + public static WxMinishopImageUploadCustomizeResult fromJson(String json) { + JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject(); + WxMinishopImageUploadCustomizeResult result = new WxMinishopImageUploadCustomizeResult(); + result.setErrcode(jsonObject.get("errcode").getAsNumber().toString()); + if (result.getErrcode().equals("0")) { + WxMinishopPicFileCustomizeResult picFileResult = new WxMinishopPicFileCustomizeResult(); + JsonObject picObject = jsonObject.get("img_info").getAsJsonObject(); + picFileResult.setMediaId(picObject.get("media_id").getAsString()); + if (picObject.has("temp_img_url")) { + picFileResult.setTempImgUrl(picObject.get("temp_img_url").getAsString()); + } + result.setImgInfo(picFileResult); + + } + return result; + } + + @Override + public String toString() { + return WxGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMinishopPicFileCustomizeResult.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMinishopPicFileCustomizeResult.java new file mode 100644 index 0000000000..8f2f36f8dd --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/result/WxMinishopPicFileCustomizeResult.java @@ -0,0 +1,11 @@ +package me.chanjar.weixin.common.bean.result; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class WxMinishopPicFileCustomizeResult implements Serializable { + private String mediaId; + private String tempImgUrl; +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MinishopUploadRequestCustomizeExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MinishopUploadRequestCustomizeExecutor.java new file mode 100644 index 0000000000..d782466c3b --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MinishopUploadRequestCustomizeExecutor.java @@ -0,0 +1,37 @@ +package me.chanjar.weixin.common.util.http; + +import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult; +import me.chanjar.weixin.common.enums.WxType; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.http.apache.ApacheMinishopMediaUploadRequestCustomizeExecutor; +import me.chanjar.weixin.common.util.http.jodd.JoddHttpMinishopMediaUploadRequestCustomizeExecutor; +import me.chanjar.weixin.common.util.http.okhttp.OkHttpMinishopMediaUploadRequestCustomizeExecutor; + +import java.io.File; +import java.io.IOException; + +public abstract class MinishopUploadRequestCustomizeExecutor implements RequestExecutor { + protected RequestHttp requestHttp; + + public MinishopUploadRequestCustomizeExecutor(RequestHttp requestHttp) { + this.requestHttp = requestHttp; + } + + @Override + public void execute(String uri, File data, ResponseHandler handler, WxType wxType) throws WxErrorException, IOException { + handler.handle(this.execute(uri, data, wxType)); + } + + public static RequestExecutor create(RequestHttp requestHttp) { + switch (requestHttp.getRequestType()) { + case APACHE_HTTP: + return new ApacheMinishopMediaUploadRequestCustomizeExecutor(requestHttp); + case JODD_HTTP: + return new JoddHttpMinishopMediaUploadRequestCustomizeExecutor(requestHttp); + case OK_HTTP: + return new OkHttpMinishopMediaUploadRequestCustomizeExecutor(requestHttp); + default: + return null; + } + } +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMinishopMediaUploadRequestCustomizeExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMinishopMediaUploadRequestCustomizeExecutor.java new file mode 100644 index 0000000000..dc38fbae5a --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheMinishopMediaUploadRequestCustomizeExecutor.java @@ -0,0 +1,58 @@ +package me.chanjar.weixin.common.util.http.apache; + +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult; +import me.chanjar.weixin.common.enums.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.http.MinishopUploadRequestCustomizeExecutor; +import me.chanjar.weixin.common.util.http.RequestHttp; +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.CloseableHttpClient; + +import java.io.File; +import java.io.IOException; + +/** + * Created by liming1019 on 2021/8/10. + */ +@Slf4j +public class ApacheMinishopMediaUploadRequestCustomizeExecutor extends MinishopUploadRequestCustomizeExecutor { + public ApacheMinishopMediaUploadRequestCustomizeExecutor(RequestHttp requestHttp) { + super(requestHttp); + } + + @Override + public WxMinishopImageUploadCustomizeResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException { + HttpPost httpPost = new HttpPost(uri); + if (requestHttp.getRequestHttpProxy() != null) { + RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build(); + httpPost.setConfig(config); + } + if (file != null) { + HttpEntity entity = MultipartEntityBuilder + .create() + .addBinaryBody("media", file) + .setMode(HttpMultipartMode.RFC6532) + .build(); + httpPost.setEntity(entity); + } + try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) { + String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); + WxError error = WxError.fromJson(responseContent, wxType); + if (error.getErrorCode() != 0) { + throw new WxErrorException(error); + } + log.info("responseContent: " + responseContent); + return WxMinishopImageUploadCustomizeResult.fromJson(responseContent); + } finally { + httpPost.releaseConnection(); + } + } +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMinishopMediaUploadRequestCustomizeExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMinishopMediaUploadRequestCustomizeExecutor.java new file mode 100644 index 0000000000..8fa1de4279 --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/jodd/JoddHttpMinishopMediaUploadRequestCustomizeExecutor.java @@ -0,0 +1,49 @@ +package me.chanjar.weixin.common.util.http.jodd; + +import jodd.http.HttpConnectionProvider; +import jodd.http.HttpRequest; +import jodd.http.HttpResponse; +import jodd.http.ProxyInfo; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult; +import me.chanjar.weixin.common.enums.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.http.MinishopUploadRequestCustomizeExecutor; +import me.chanjar.weixin.common.util.http.RequestHttp; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +/** + * @author liming1019 + * @date 2021/8/10 + */ +@Slf4j +public class JoddHttpMinishopMediaUploadRequestCustomizeExecutor extends MinishopUploadRequestCustomizeExecutor { + public JoddHttpMinishopMediaUploadRequestCustomizeExecutor(RequestHttp requestHttp) { + super(requestHttp); + } + + @Override + public WxMinishopImageUploadCustomizeResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException { + HttpRequest request = HttpRequest.post(uri); + if (requestHttp.getRequestHttpProxy() != null) { + requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy()); + } + request.withConnectionProvider(requestHttp.getRequestHttpClient()); + request.form("media", file); + HttpResponse response = request.send(); + response.charset(StandardCharsets.UTF_8.name()); + + String responseContent = response.bodyText(); + WxError error = WxError.fromJson(responseContent, wxType); + if (error.getErrorCode() != 0) { + throw new WxErrorException(error); + } + log.info("responseContent: " + responseContent); + + return WxMinishopImageUploadCustomizeResult.fromJson(responseContent); + } +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMinishopMediaUploadRequestCustomizeExecutor.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMinishopMediaUploadRequestCustomizeExecutor.java new file mode 100644 index 0000000000..8b2cdc7b6c --- /dev/null +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/okhttp/OkHttpMinishopMediaUploadRequestCustomizeExecutor.java @@ -0,0 +1,47 @@ +package me.chanjar.weixin.common.util.http.okhttp; + +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult; +import me.chanjar.weixin.common.enums.WxType; +import me.chanjar.weixin.common.error.WxError; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.http.MinishopUploadRequestCustomizeExecutor; +import me.chanjar.weixin.common.util.http.RequestHttp; +import okhttp3.*; + +import java.io.File; +import java.io.IOException; + +/** + * @author liming1019 + * @date 2021/8/10 + */ +@Slf4j +public class OkHttpMinishopMediaUploadRequestCustomizeExecutor extends MinishopUploadRequestCustomizeExecutor { + public OkHttpMinishopMediaUploadRequestCustomizeExecutor(RequestHttp requestHttp) { + super(requestHttp); + } + + @Override + public WxMinishopImageUploadCustomizeResult execute(String uri, File file, WxType wxType) throws WxErrorException, IOException { + + RequestBody body = new MultipartBody.Builder() + .setType(MediaType.parse("multipart/form-data")) + .addFormDataPart("media", + file.getName(), + RequestBody.create(MediaType.parse("application/octet-stream"), file)) + .build(); + Request request = new Request.Builder().url(uri).post(body).build(); + + Response response = requestHttp.getRequestHttpClient().newCall(request).execute(); + String responseContent = response.body().string(); + WxError error = WxError.fromJson(responseContent, wxType); + if (error.getErrorCode() != 0) { + throw new WxErrorException(error); + } + log.info("responseContent: " + responseContent); + + return WxMinishopImageUploadCustomizeResult.fromJson(responseContent); + } + +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java index 7b311952e8..3115a7d5b9 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java @@ -426,6 +426,13 @@ public interface WxMaService extends WxService { */ WxMaShopCatService getShopCatService(); + /** + * 小程序交易组件-接入商品前必需接口-上传图片 + * + * @return + */ + WxMaShopImgService getShopImgService(); + /** * 获取小程序 URL Link服务接口 * diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopImgService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopImgService.java new file mode 100644 index 0000000000..c44bc7df35 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopImgService.java @@ -0,0 +1,21 @@ +package cn.binarywang.wx.miniapp.api; + +import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult; +import me.chanjar.weixin.common.error.WxErrorException; + +import java.io.File; + +/** + * 小程序交易组件-接入商品前必需接口 + * + * @author liming1019 + */ +public interface WxMaShopImgService { + /** + * 上传图片 + * + * @return WxMinishopImageUploadCustomizeResult + * @throws WxErrorException + */ + WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java index 48cd6f4189..1de659e603 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java @@ -68,6 +68,7 @@ public abstract class BaseWxMaServiceImpl implements WxMaService, RequestH private final WxMaShopRegisterService shopRegisterService = new WxMaShopRegisterServiceImpl(this); private final WxMaShopAccountService shopAccountService = new WxMaShopAccountServiceImpl(this); private final WxMaShopCatService shopCatService = new WxMaShopCatServiceImpl(this); + private final WxMaShopImgService shopImgService = new WxMaShopImgServiceImpl(this); private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this); private final WxMaReimburseInvoiceService reimburseInvoiceService = new WxMaReimburseInvoiceServiceImpl(this); private Map configMap; @@ -534,6 +535,11 @@ public WxMaShopCatService getShopCatService() { return this.shopCatService; } + @Override + public WxMaShopImgService getShopImgService() { + return this.shopImgService; + } + @Override public WxMaLinkService getLinkService() { return this.linkService; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImpl.java new file mode 100644 index 0000000000..f253bca280 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImpl.java @@ -0,0 +1,29 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.WxMaShopImgService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.common.util.http.MinishopUploadRequestCustomizeExecutor; + +import java.io.File; + +import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Img.IMG_UPLOAD; + +/** + * @author liming1019 + */ +@RequiredArgsConstructor +@Slf4j +public class WxMaShopImgServiceImpl implements WxMaShopImgService { + private final WxMaService service; + + @Override + public WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException { + WxMinishopImageUploadCustomizeResult result = this.service.execute( + MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp()), IMG_UPLOAD, file); + return result; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java index c6b428db85..c76c8963d6 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java @@ -337,6 +337,10 @@ interface Account { interface Cat { String GET_CAT = "https://api.weixin.qq.com/shop/cat/get"; } + + interface Img { + String IMG_UPLOAD = "https://api.weixin.qq.com/shop/img/upload"; + } } /** diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImplTest.java new file mode 100644 index 0000000000..191b429630 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopImgServiceImplTest.java @@ -0,0 +1,31 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.test.ApiTestModule; +import com.google.inject.Inject; +import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadCustomizeResult; +import me.chanjar.weixin.common.error.WxErrorException; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.io.File; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author liming1019 + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaShopImgServiceImplTest { + + @Inject + private WxMaService wxService; + + @Test + public void testUploadImg() throws WxErrorException { + File file = new File("/Users/liming/Desktop/test.jpeg"); + WxMinishopImageUploadCustomizeResult result = wxService.getShopImgService().uploadImg(file); + assertThat(result).isNotNull(); + } +}