From 358f74ea211939b5cecb2161fdae5094f4ddfed7 Mon Sep 17 00:00:00 2001 From: liming Date: Fri, 6 Aug 2021 10:27:05 +0800 Subject: [PATCH 1/8] =?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/8] =?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/8] =?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/8] =?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(); + } +} From c47a6046b3b7c2c044ab73606a21abe28bc2eae2 Mon Sep 17 00:00:00 2001 From: liming Date: Thu, 12 Aug 2021 17:04:39 +0800 Subject: [PATCH 5/8] =?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=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=89=8D=E5=BF=85=E9=9C=80=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 | 7 ++ .../wx/miniapp/api/WxMaShopAuditService.java | 53 +++++++++ .../miniapp/api/impl/BaseWxMaServiceImpl.java | 6 ++ .../api/impl/WxMaShopAuditServiceImpl.java | 101 ++++++++++++++++++ .../request/WxMaShopAuditBrandRequest.java | 93 ++++++++++++++++ .../request/WxMaShopAuditCategoryRequest.java | 59 ++++++++++ .../response/WxMaShopAuditBrandResponse.java | 20 ++++ .../WxMaShopAuditCategoryResponse.java | 20 ++++ .../response/WxMaShopAuditResultResponse.java | 40 +++++++ .../miniapp/constant/WxMaApiUrlConstants.java | 7 ++ .../impl/WxMaShopAuditServiceImplTest.java | 93 ++++++++++++++++ 11 files changed, 499 insertions(+) create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAuditService.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImpl.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAuditBrandRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAuditCategoryRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditBrandResponse.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditCategoryResponse.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditResultResponse.java create mode 100644 weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImplTest.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 3115a7d5b9..484968f3d9 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 @@ -433,6 +433,13 @@ public interface WxMaService extends WxService { */ WxMaShopImgService getShopImgService(); + /** + * 小程序交易组件-接入商品前必需接口-审核相关接口 + * + * @return + */ + WxMaShopAuditService getShopAuditService(); + /** * 获取小程序 URL Link服务接口 * diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAuditService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAuditService.java new file mode 100644 index 0000000000..157052b4c0 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAuditService.java @@ -0,0 +1,53 @@ +package cn.binarywang.wx.miniapp.api; + +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAuditBrandRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAuditCategoryRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditBrandResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditCategoryResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditResultResponse; +import com.google.gson.JsonObject; +import me.chanjar.weixin.common.error.WxErrorException; + +/** + * 小程序交易组件-接入商品前必需接口(审核相关接口) + * + * @author liming1019 + * @date 2021/8/12 + */ +public interface WxMaShopAuditService { + /** + * 上传品牌信息(品牌审核) + * + * @param request + * @return WxMaShopAuditBrandResponse + * @throws WxErrorException + */ + WxMaShopAuditBrandResponse auditBrand(WxMaShopAuditBrandRequest request) throws WxErrorException; + + /** + * 上传类目资质(类目审核) + * + * @param request + * @return + * @throws WxErrorException + */ + WxMaShopAuditCategoryResponse auditCategory(WxMaShopAuditCategoryRequest request) throws WxErrorException; + + /** + * 获取审核结果 + * + * @param auditId + * @return WxMaShopAuditResultResponse + * @throws WxErrorException + */ + WxMaShopAuditResultResponse getAuditResult(String auditId) throws WxErrorException; + + /** + * 获取小程序提交过的入驻资质信息 + * + * @param reqType + * @return JsonObject + * @throws WxErrorException + */ + JsonObject getMiniappCertificate(int reqType) 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 1de659e603..fe841a57a0 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 @@ -69,6 +69,7 @@ public abstract class BaseWxMaServiceImpl implements WxMaService, RequestH private final WxMaShopAccountService shopAccountService = new WxMaShopAccountServiceImpl(this); private final WxMaShopCatService shopCatService = new WxMaShopCatServiceImpl(this); private final WxMaShopImgService shopImgService = new WxMaShopImgServiceImpl(this); + private final WxMaShopAuditService shopAuditService = new WxMaShopAuditServiceImpl(this); private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this); private final WxMaReimburseInvoiceService reimburseInvoiceService = new WxMaReimburseInvoiceServiceImpl(this); private Map configMap; @@ -540,6 +541,11 @@ public WxMaShopImgService getShopImgService() { return this.shopImgService; } + @Override + public WxMaShopAuditService getShopAuditService() { + return this.shopAuditService; + } + @Override public WxMaLinkService getLinkService() { return this.linkService; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImpl.java new file mode 100644 index 0000000000..b456410124 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImpl.java @@ -0,0 +1,101 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.api.WxMaShopAuditService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAuditBrandRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAuditCategoryRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditBrandResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditCategoryResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditResultResponse; +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.GsonHelper; +import me.chanjar.weixin.common.util.json.GsonParser; + +import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Audit.*; +import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE; + +/** + * 小程序交易组件-接入商品前必需接口(审核相关接口) + * + * @author liming1019 + * @date 2021/8/12 + */ +@RequiredArgsConstructor +@Slf4j +public class WxMaShopAuditServiceImpl implements WxMaShopAuditService { + private final WxMaService wxMaService; + + /** + * 上传品牌信息(品牌审核) + * + * @param request + * @return WxMaShopAuditBrandResponse + * @throws WxErrorException + */ + @Override + public WxMaShopAuditBrandResponse auditBrand(WxMaShopAuditBrandRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(AUDIT_BRAND, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditBrandResponse.class); + } + + /** + * 上传类目资质(类目审核) + * + * @param request + * @return + * @throws WxErrorException + */ + @Override + public WxMaShopAuditCategoryResponse auditCategory(WxMaShopAuditCategoryRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(AUDIT_CATEGORY, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditCategoryResponse.class); + } + + /** + * 获取审核结果 + * + * @param auditId + * @return WxMaShopAuditResultResponse + * @throws WxErrorException + */ + @Override + public WxMaShopAuditResultResponse getAuditResult(String auditId) throws WxErrorException { + String responseContent = this.wxMaService.post(AUDIT_RESULT, GsonHelper.buildJsonObject("audit_id", auditId)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditResultResponse.class); + } + + /** + * 获取小程序提交过的入驻资质信息 + * + * @param reqType + * @return JsonObject + * @throws WxErrorException + */ + @Override + public JsonObject getMiniappCertificate(int reqType) throws WxErrorException { + String responseContent = this.wxMaService.post(GET_MINIAPP_CERTIFICATE, GsonHelper.buildJsonObject("req_type", reqType)); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, JsonObject.class); + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAuditBrandRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAuditBrandRequest.java new file mode 100644 index 0000000000..fec5e3ee57 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAuditBrandRequest.java @@ -0,0 +1,93 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@Builder +public class WxMaShopAuditBrandRequest implements Serializable { + private static final long serialVersionUID = -969331692973992066L; + + /** + * audit_req : {"license":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"],"brand_info":{"brand_audit_type":1,"trademark_type":"29","brand_management_type":2,"commodity_origin_type":2,"brand_wording":"346225226351203275","sale_authorization":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"],"trademark_registration_certificate":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"],"trademark_change_certificate":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"],"trademark_registrant":"https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg","trademark_registrant_nu":"1249305","trademark_authorization_period":"2020-03-25 12:05:25","trademark_registration_application":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"],"trademark_applicant":"张三","trademark_application_time":"2020-03-25 12:05:25","imported_goods_form":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"]}} + */ + + @SerializedName("audit_req") + private AuditReqBean auditReq; + + @Data + @Builder + public static class AuditReqBean implements Serializable { + /** + * license : ["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"] + * brand_info : {"brand_audit_type":1,"trademark_type":"29","brand_management_type":2,"commodity_origin_type":2,"brand_wording":"346225226351203275","sale_authorization":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"],"trademark_registration_certificate":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"],"trademark_change_certificate":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"],"trademark_registrant":"https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg","trademark_registrant_nu":"1249305","trademark_authorization_period":"2020-03-25 12:05:25","trademark_registration_application":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"],"trademark_applicant":"张三","trademark_application_time":"2020-03-25 12:05:25","imported_goods_form":["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"]} + */ + + @SerializedName("brand_info") + private BrandInfoBean brandInfo; + @SerializedName("license") + private List license; + + @Data + @Builder + public static class BrandInfoBean implements Serializable { + /** + * brand_audit_type : 1 + * trademark_type : 29 + * brand_management_type : 2 + * commodity_origin_type : 2 + * brand_wording : 346225226351203275 + * sale_authorization : ["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"] + * trademark_registration_certificate : ["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"] + * trademark_change_certificate : ["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"] + * trademark_registrant : https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg + * trademark_registrant_nu : 1249305 + * trademark_authorization_period : 2020-03-25 12:05:25 + * trademark_registration_application : ["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"] + * trademark_applicant : 张三 + * trademark_application_time : 2020-03-25 12:05:25 + * imported_goods_form : ["https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"] + */ + + @SerializedName("brand_audit_type") + private Integer brandAuditType; + @SerializedName("trademark_type") + private String trademarkType; + @SerializedName("brand_management_type") + private Integer brandManagementType; + @SerializedName("commodity_origin_type") + private Integer commodityOriginType; + @SerializedName("brand_wording") + private String brandWording; + @SerializedName("trademark_registrant") + private String trademarkRegistrant; + @SerializedName("trademark_registrant_nu") + private String trademarkRegistrantNu; + @SerializedName("trademark_authorization_period") + private String trademarkAuthorizationPeriod; + @SerializedName("trademark_applicant") + private String trademarkApplicant; + @SerializedName("trademark_application_time") + private String trademarkApplicationTime; + @SerializedName("sale_authorization") + private List saleAuthorization; + @SerializedName("trademark_registration_certificate") + private List trademarkRegistrationCertificate; + @SerializedName("trademark_change_certificate") + private List trademarkChangeCertificate; + @SerializedName("trademark_registration_application") + private List trademarkRegistrationApplication; + @SerializedName("imported_goods_form") + private List importedGoodsForm; + } + } +} + diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAuditCategoryRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAuditCategoryRequest.java new file mode 100644 index 0000000000..8fe40176c4 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAuditCategoryRequest.java @@ -0,0 +1,59 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@Builder +public class WxMaShopAuditCategoryRequest implements Serializable { + private static final long serialVersionUID = -6730876344556487071L; + + /** + * audit_req : {"license":["www.xxxxx.com"],"category_info":{"level1":7419,"level2":7439,"level3":7448,"certificate":["www.xxx.com"]}} + */ + + @SerializedName("audit_req") + private AuditReqBean auditReq; + + @Data + @Builder + public static class AuditReqBean implements Serializable { + /** + * license : ["www.xxxxx.com"] + * category_info : {"level1":7419,"level2":7439,"level3":7448,"certificate":["www.xxx.com"]} + */ + + @SerializedName("category_info") + private CategoryInfoBean categoryInfo; + @SerializedName("license") + private List license; + + @Data + @Builder + public static class CategoryInfoBean implements Serializable { + /** + * level1 : 7419 + * level2 : 7439 + * level3 : 7448 + * certificate : ["www.xxx.com"] + */ + + @SerializedName("level1") + private Integer level1; + @SerializedName("level2") + private Integer level2; + @SerializedName("level3") + private Integer level3; + @SerializedName("certificate") + private List certificate; + } + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditBrandResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditBrandResponse.java new file mode 100644 index 0000000000..59f7a6ff9c --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditBrandResponse.java @@ -0,0 +1,20 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopAuditBrandResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = -4643316662725276237L; + + @SerializedName("audit_id") + private String auditId; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditCategoryResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditCategoryResponse.java new file mode 100644 index 0000000000..db157fdddd --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditCategoryResponse.java @@ -0,0 +1,20 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopAuditCategoryResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = -1822188134865177738L; + + @SerializedName("audit_id") + private String auditId; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditResultResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditResultResponse.java new file mode 100644 index 0000000000..5f3fca5cc7 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAuditResultResponse.java @@ -0,0 +1,40 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopAuditResultResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = -1068201722686667490L; + + /** + * data : {"status":9,"brand_id":0,"reject_reason":"请重新提交审核"} + */ + + @SerializedName("data") + private DataBean data; + + @Data + public static class DataBean implements Serializable { + /** + * status : 9 + * brand_id : 0 + * reject_reason : 请重新提交审核 + */ + + @SerializedName("status") + private Integer status; + @SerializedName("brand_id") + private Integer brandId; + @SerializedName("reject_reason") + private String rejectReason; + } +} 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 c76c8963d6..74f656d25d 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 @@ -341,6 +341,13 @@ interface Cat { interface Img { String IMG_UPLOAD = "https://api.weixin.qq.com/shop/img/upload"; } + + interface Audit { + String AUDIT_BRAND = "https://api.weixin.qq.com/shop/audit/audit_brand"; + String AUDIT_CATEGORY = "https://api.weixin.qq.com/shop/audit/audit_category"; + String AUDIT_RESULT = "https://api.weixin.qq.com/shop/audit/result"; + String GET_MINIAPP_CERTIFICATE = "https://api.weixin.qq.com/shop/audit/get_miniapp_certificate"; + } } /** diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImplTest.java new file mode 100644 index 0000000000..c8ec9f081c --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAuditServiceImplTest.java @@ -0,0 +1,93 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAuditBrandRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAuditCategoryRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditBrandResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditCategoryResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAuditResultResponse; +import cn.binarywang.wx.miniapp.test.ApiTestModule; +import com.google.gson.JsonObject; +import com.google.inject.Inject; +import me.chanjar.weixin.common.error.WxErrorException; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author liming1019 + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaShopAuditServiceImplTest { + + @Inject + private WxMaService wxService; + + @Test + public void testAuditBrand() throws WxErrorException { + WxMaShopAuditBrandRequest request = WxMaShopAuditBrandRequest.builder().build(); + WxMaShopAuditBrandRequest.AuditReqBean auditReqBean = WxMaShopAuditBrandRequest.AuditReqBean.builder().build(); + + auditReqBean.setLicense(new ArrayList(Arrays.asList("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"))); + auditReqBean.setBrandInfo(WxMaShopAuditBrandRequest.AuditReqBean.BrandInfoBean.builder() + .brandAuditType(1) + .trademarkType("29") + .brandManagementType(2) + .commodityOriginType(2) + .brandWording("346225226351203275") + .saleAuthorization(new ArrayList(Arrays.asList("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"))) + .trademarkRegistrationCertificate(new ArrayList(Arrays.asList("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"))) + .trademarkChangeCertificate(new ArrayList(Arrays.asList("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"))) + .trademarkRegistrant("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg") + .trademarkRegistrantNu("1249305") + .trademarkAuthorizationPeriod("2020-03-25 12:05:25") + .trademarkRegistrationApplication(new ArrayList(Arrays.asList("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"))) + .trademarkApplicant("张三") + .trademarkApplicationTime("2020-03-25 12:05:25") + .importedGoodsForm(new ArrayList(Arrays.asList("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg"))) + .build()); + request.setAuditReq(auditReqBean); + + WxMaShopAuditBrandResponse response = wxService.getShopAuditService().auditBrand(request); + assertThat(response).isNotNull(); + } + + @Test + public void testAuditCategory() throws WxErrorException { + WxMaShopAuditCategoryRequest request = WxMaShopAuditCategoryRequest.builder().build(); + WxMaShopAuditCategoryRequest.AuditReqBean auditReqBean = WxMaShopAuditCategoryRequest.AuditReqBean.builder().build(); + auditReqBean.setLicense(new ArrayList(Arrays.asList("www.xxxxx.com"))); + auditReqBean.setCategoryInfo(WxMaShopAuditCategoryRequest.AuditReqBean.CategoryInfoBean.builder() + .level1(7419) + .level2(7439) + .level3(7448) + .certificate(new ArrayList(Arrays.asList("www.xxxxx.com"))) + .build()); + request.setAuditReq(auditReqBean); + WxMaShopAuditCategoryResponse response = wxService.getShopAuditService().auditCategory(request); + assertThat(response).isNotNull(); + } + + @Test + public void testGetAuditResult() throws WxErrorException { + WxMaShopAuditResultResponse response = wxService.getShopAuditService().getAuditResult("RQAAAHIOW-QGAAAAveAUYQ"); + assertThat(response).isNotNull(); + } + + @Test + public void testGetMiniappCertificate1() throws WxErrorException { + JsonObject response = wxService.getShopAuditService().getMiniappCertificate(1); + assertThat(response).isNotNull(); + } + + @Test + public void testGetMiniappCertificate2() throws WxErrorException { + JsonObject response = wxService.getShopAuditService().getMiniappCertificate(2); + assertThat(response).isNotNull(); + } +} From 0c673d8b3f053eddfd694547f6a12b6b4e34cea0 Mon Sep 17 00:00:00 2001 From: liming Date: Fri, 13 Aug 2021 17:45:34 +0800 Subject: [PATCH 6/8] =?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=E7=89=A9=E6=B5=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=81=E5=94=AE=E5=90=8E=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 | 26 ++++--- .../miniapp/api/WxMaShopAfterSaleService.java | 34 +++++++++ .../miniapp/api/WxMaShopDeliveryService.java | 32 ++++++++ .../miniapp/api/impl/BaseWxMaServiceImpl.java | 12 +++ .../impl/WxMaShopAfterSaleServiceImpl.java | 65 +++++++++++++++- .../api/impl/WxMaShopDeliveryServiceImpl.java | 65 +++++++++++++++- .../request/WxMaShopAfterSaleAddRequest.java | 69 +++++++++++++++++ .../request/WxMaShopAfterSaleGetRequest.java | 30 ++++++++ .../WxMaShopAfterSaleUpdateRequest.java | 36 +++++++++ .../WxMaShopDeliveryRecieveRequest.java | 30 ++++++++ .../request/WxMaShopDeliverySendRequest.java | 51 +++++++++++++ .../WxMaShopAfterSaleGetResponse.java | 67 +++++++++++++++++ ...xMaShopDeliveryGetCompanyListResponse.java | 30 ++++++++ .../miniapp/constant/WxMaApiUrlConstants.java | 12 +++ .../WxMaShopAfterSaleServiceImplTest.java | 75 +++++++++++++++++++ .../impl/WxMaShopDeliveryServiceImplTest.java | 61 +++++++++++++++ 16 files changed, 681 insertions(+), 14 deletions(-) create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleAddRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleGetRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleUpdateRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopDeliveryRecieveRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopDeliverySendRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAfterSaleGetResponse.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopDeliveryGetCompanyListResponse.java create mode 100644 weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImplTest.java create mode 100644 weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopDeliveryServiceImplTest.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 484968f3d9..a182c245cd 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 @@ -377,18 +377,20 @@ public interface WxMaService extends WxService { */ WxImgProcService getImgProcService(); -// /** -// * 返回小程序交易组件-售后服务接口 -// * @return -// */ -// WxMaShopAfterSaleService getShopAfterSaleService(); -// -// -// /** -// * 返回小程序交易组件-物流服务接口 -// * @return -// */ -// WxMaShopDeliveryService getShopDeliveryService(); + /** + * 返回小程序交易组件-售后服务接口 + * + * @return + */ + WxMaShopAfterSaleService getShopAfterSaleService(); + + + /** + * 返回小程序交易组件-物流服务接口 + * + * @return + */ + WxMaShopDeliveryService getShopDeliveryService(); /** diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAfterSaleService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAfterSaleService.java index 6e9878c9fb..97b8aa56d7 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAfterSaleService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopAfterSaleService.java @@ -1,10 +1,44 @@ package cn.binarywang.wx.miniapp.api; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAfterSaleAddRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAfterSaleGetRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAfterSaleUpdateRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAfterSaleGetResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +import me.chanjar.weixin.common.error.WxErrorException; + /** * 小程序交易组件-售后服务 * * @author boris + * @author liming1019 */ public interface WxMaShopAfterSaleService { + /** + * 创建售后 + * + * @param request + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + WxMaShopBaseResponse add(WxMaShopAfterSaleAddRequest request) throws WxErrorException; + + /** + * 获取订单下售后单 + * + * @param request + * @return WxMaShopAfterSaleGetResponse + * @throws WxErrorException + */ + WxMaShopAfterSaleGetResponse get(WxMaShopAfterSaleGetRequest request) throws WxErrorException; + + /** + * 更新售后 + * + * @param request + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + WxMaShopBaseResponse update(WxMaShopAfterSaleUpdateRequest request) throws WxErrorException; } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopDeliveryService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopDeliveryService.java index 2a3a119862..d6aadbebc2 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopDeliveryService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaShopDeliveryService.java @@ -1,10 +1,42 @@ package cn.binarywang.wx.miniapp.api; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliveryRecieveRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliverySendRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopDeliveryGetCompanyListResponse; +import me.chanjar.weixin.common.error.WxErrorException; + /** * 小程序交易组件-物流发货服务 * * @author boris + * @author liming1019 */ public interface WxMaShopDeliveryService { + /** + * 获取快递公司列表 + * + * @return WxMaShopDeliveryGetCompanyListResponse + * @throws WxErrorException + */ + WxMaShopDeliveryGetCompanyListResponse getCompanyList() throws WxErrorException; + + /** + * 订单发货 + * + * @param request + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + WxMaShopBaseResponse send(WxMaShopDeliverySendRequest request) throws WxErrorException; + + /** + * 订单确认收货 + * + * @param request + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + WxMaShopBaseResponse receive(WxMaShopDeliveryRecieveRequest 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 fe841a57a0..096eedd5bf 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 @@ -70,6 +70,8 @@ public abstract class BaseWxMaServiceImpl implements WxMaService, RequestH private final WxMaShopCatService shopCatService = new WxMaShopCatServiceImpl(this); private final WxMaShopImgService shopImgService = new WxMaShopImgServiceImpl(this); private final WxMaShopAuditService shopAuditService = new WxMaShopAuditServiceImpl(this); + private final WxMaShopAfterSaleService shopAfterSaleService = new WxMaShopAfterSaleServiceImpl(this); + private final WxMaShopDeliveryService shopDeliveryService = new WxMaShopDeliveryServiceImpl(this); private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this); private final WxMaReimburseInvoiceService reimburseInvoiceService = new WxMaReimburseInvoiceServiceImpl(this); private Map configMap; @@ -546,6 +548,16 @@ public WxMaShopAuditService getShopAuditService() { return this.shopAuditService; } + @Override + public WxMaShopAfterSaleService getShopAfterSaleService() { + return this.shopAfterSaleService; + } + + @Override + public WxMaShopDeliveryService getShopDeliveryService() { + return this.shopDeliveryService; + } + @Override public WxMaLinkService getLinkService() { return this.linkService; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImpl.java index 85fdb90b61..9fd24350a5 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImpl.java @@ -2,18 +2,81 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaShopAfterSaleService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAfterSaleAddRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAfterSaleGetRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAfterSaleUpdateRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAfterSaleGetResponse; +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.Aftersale.*; +import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE; /** * @author boris + * @author liming1019 */ @RequiredArgsConstructor @Slf4j public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService { - private final WxMaService service; + private final WxMaService wxMaService; + /** + * 创建售后 + * + * @param request + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + @Override + public WxMaShopBaseResponse add(WxMaShopAfterSaleAddRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(AFTERSALE_ADD, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); + } + /** + * 获取订单下售后单 + * + * @param request + * @return WxMaShopAfterSaleGetResponse + * @throws WxErrorException + */ + @Override + public WxMaShopAfterSaleGetResponse get(WxMaShopAfterSaleGetRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(AFTERSALE_GET, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAfterSaleGetResponse.class); + } + /** + * 更新售后 + * + * @param request + * @return + * @throws WxErrorException + */ + @Override + public WxMaShopBaseResponse update(WxMaShopAfterSaleUpdateRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(AFTERSALE_UPDATE, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).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/api/impl/WxMaShopDeliveryServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopDeliveryServiceImpl.java index 9b6a093eb8..8fd9d63f95 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopDeliveryServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopDeliveryServiceImpl.java @@ -2,15 +2,78 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaShopDeliveryService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliveryRecieveRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliverySendRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopDeliveryGetCompanyListResponse; +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.Delivery.*; +import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE; /** * @author boris + * @author liming1019 */ @RequiredArgsConstructor @Slf4j public class WxMaShopDeliveryServiceImpl implements WxMaShopDeliveryService { - private final WxMaService service; + private final WxMaService wxMaService; + + /** + * 获取快递公司列表 + * + * @return WxMaShopDeliveryGetCompanyListResponse + * @throws WxErrorException + */ + @Override + public WxMaShopDeliveryGetCompanyListResponse getCompanyList() throws WxErrorException { + String responseContent = this.wxMaService.post(GET_COMPANY_LIST, 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, WxMaShopDeliveryGetCompanyListResponse.class); + } + + /** + * 订单发货 + * + * @param request + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + @Override + public WxMaShopBaseResponse send(WxMaShopDeliverySendRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(DELIVERY_SEND, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); + } + return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); + } + /** + * 订单确认收货 + * + * @param request + * @return WxMaShopBaseResponse + * @throws WxErrorException + */ + @Override + public WxMaShopBaseResponse receive(WxMaShopDeliveryRecieveRequest request) throws WxErrorException { + String responseContent = this.wxMaService.post(DELIVERY_RECEIVE, request); + JsonObject jsonObject = GsonParser.parse(responseContent); + if (jsonObject.get(ERRCODE).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/WxMaShopAfterSaleAddRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleAddRequest.java new file mode 100644 index 0000000000..9f9c13e988 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleAddRequest.java @@ -0,0 +1,69 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@Builder +public class WxMaShopAfterSaleAddRequest implements Serializable { + private static final long serialVersionUID = 6652525413062887786L; + + /** + * out_order_id : xxxxx + * out_aftersale_id : xxxxxx + * openid : oTVP50O53a7jgmawAmxKukNlq3XI + * type : 1 + * create_time : 2020-12-01 00:00:00 + * status : 1 + * finish_all_aftersale : 0 + * path : /pages/aftersale.html?out_aftersale_id=xxxxx + * refund : 100 + * product_infos : [{"out_product_id":"234245","out_sku_id":"23424","product_cnt":5}] + */ + + @SerializedName("out_order_id") + private String outOrderId; + @SerializedName("out_aftersale_id") + private String outAftersaleId; + @SerializedName("openid") + private String openid; + @SerializedName("type") + private Integer type; + @SerializedName("create_time") + private String createTime; + @SerializedName("status") + private Integer status; + @SerializedName("finish_all_aftersale") + private Integer finishAllAftersale; + @SerializedName("path") + private String path; + @SerializedName("refund") + private Long refund; + @SerializedName("product_infos") + private List productInfos; + + @Data + @Builder + public static class ProductInfosBean implements Serializable { + /** + * out_product_id : 234245 + * out_sku_id : 23424 + * product_cnt : 5 + */ + + @SerializedName("out_product_id") + private String outProductId; + @SerializedName("out_sku_id") + private String outSkuId; + @SerializedName("product_cnt") + private Integer productCnt; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleGetRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleGetRequest.java new file mode 100644 index 0000000000..31afee26ce --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleGetRequest.java @@ -0,0 +1,30 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@Builder +public class WxMaShopAfterSaleGetRequest implements Serializable { + private static final long serialVersionUID = -1275475147400719521L; + + /** + * order_id : 32434234 + * out_order_id : xxxxx + * openid : oTVP50O53a7jgmawAmxKukNlq3XI + */ + + @SerializedName("order_id") + private Long orderId; + @SerializedName("out_order_id") + private String outOrderId; + @SerializedName("openid") + private String openid; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleUpdateRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleUpdateRequest.java new file mode 100644 index 0000000000..8bbeadb1af --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAfterSaleUpdateRequest.java @@ -0,0 +1,36 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@Builder +public class WxMaShopAfterSaleUpdateRequest implements Serializable { + private static final long serialVersionUID = 2712027510252221370L; + + /** + * out_order_id : xxxxx + * openid : oTVP50O53a7jgmawAmxKukNlq3XI + * out_aftersale_id : xxxxxx + * status : 1 + * finish_all_aftersale : 0 + */ + + @SerializedName("out_order_id") + private String outOrderId; + @SerializedName("openid") + private String openid; + @SerializedName("out_aftersale_id") + private String outAftersaleId; + @SerializedName("status") + private Integer status; + @SerializedName("finish_all_aftersale") + private Integer finishAllAftersale; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopDeliveryRecieveRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopDeliveryRecieveRequest.java new file mode 100644 index 0000000000..50ef7a63ef --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopDeliveryRecieveRequest.java @@ -0,0 +1,30 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@Builder +public class WxMaShopDeliveryRecieveRequest implements Serializable { + private static final long serialVersionUID = 1540854758624081221L; + + /** + * order_id : 123456 + * out_order_id : xxxxx + * openid : oTVP50O53a7jgmawAmxKukNlq3XI + */ + + @SerializedName("order_id") + private Long orderId; + @SerializedName("out_order_id") + private String outOrderId; + @SerializedName("openid") + private String openid; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopDeliverySendRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopDeliverySendRequest.java new file mode 100644 index 0000000000..6636b64055 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopDeliverySendRequest.java @@ -0,0 +1,51 @@ +package cn.binarywang.wx.miniapp.bean.shop.request; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author liming1019 + * @date 2021/8/12 + */ +@Data +@Builder +public class WxMaShopDeliverySendRequest implements Serializable { + private static final long serialVersionUID = -4034672301224469057L; + + /** + * order_id : 123456 + * out_order_id : xxxxx + * openid : oTVP50O53a7jgmawAmxKukNlq3XI + * finish_all_delivery : 0 + * delivery_list : [{"delivery_id":"SF","waybill_id":"23424324253"}] + */ + + @SerializedName("order_id") + private Long orderId; + @SerializedName("out_order_id") + private String outOrderId; + @SerializedName("openid") + private String openid; + @SerializedName("finish_all_delivery") + private Integer finishAllDelivery; + @SerializedName("delivery_list") + private List deliveryList; + + @Data + @Builder + public static class DeliveryListBean implements Serializable { + /** + * delivery_id : SF + * waybill_id : 23424324253 + */ + + @SerializedName("delivery_id") + private String deliveryId; + @SerializedName("waybill_id") + private String waybillId; + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAfterSaleGetResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAfterSaleGetResponse.java new file mode 100644 index 0000000000..ac8f68db66 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopAfterSaleGetResponse.java @@ -0,0 +1,67 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopAfterSaleGetResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = 213666907103837748L; + + @SerializedName("aftersale_infos") + private List aftersaleInfos; + + @Data + public static class AftersaleInfosBean implements Serializable { + /** + * out_order_id : xxxxx + * out_aftersale_id : xxxxxx + * openid : oTVP50O53a7jgmawAmxKukNlq3XI + * type : 1 + * create_time : 2020-12-01 00:00:00 + * path : /pages/order.html?out_order_id=xxxxx + * status : 1 + * refund : 100 + * product_infos : [{"out_product_id":"234245","out_sku_id":"23424","product_cnt":5}] + */ + + @SerializedName("out_order_id") + private String outOrderId; + @SerializedName("out_aftersale_id") + private String outAftersaleId; + @SerializedName("openid") + private String openid; + @SerializedName("type") + private Integer type; + @SerializedName("create_time") + private String createTime; + @SerializedName("path") + private String path; + @SerializedName("status") + private Integer status; + @SerializedName("refund") + private Long refund; + @SerializedName("product_infos") + private List productInfos; + + @Data + public static class ProductInfosBean implements Serializable { + /** + * out_product_id : 234245 + * out_sku_id : 23424 + * product_cnt : 5 + */ + + @SerializedName("out_product_id") + private String outProductId; + @SerializedName("out_sku_id") + private String outSkuId; + @SerializedName("product_cnt") + private Integer productCnt; + } + } +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopDeliveryGetCompanyListResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopDeliveryGetCompanyListResponse.java new file mode 100644 index 0000000000..096d92e38e --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/response/WxMaShopDeliveryGetCompanyListResponse.java @@ -0,0 +1,30 @@ +package cn.binarywang.wx.miniapp.bean.shop.response; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = true) +public class WxMaShopDeliveryGetCompanyListResponse extends WxMaShopBaseResponse implements Serializable { + private static final long serialVersionUID = -1478684494303814483L; + + @SerializedName("company_list") + private List companyList; + + @Data + public static class CompanyListBean implements Serializable { + /** + * delivery_id : SF + * delivery_name : 顺丰速运 + */ + + @SerializedName("delivery_id") + private String deliveryId; + @SerializedName("delivery_name") + private String deliveryName; + } +} 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 74f656d25d..28a38a1f20 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 @@ -348,6 +348,18 @@ interface Audit { String AUDIT_RESULT = "https://api.weixin.qq.com/shop/audit/result"; String GET_MINIAPP_CERTIFICATE = "https://api.weixin.qq.com/shop/audit/get_miniapp_certificate"; } + + interface Delivery { + String GET_COMPANY_LIST = "https://api.weixin.qq.com/shop/delivery/get_company_list"; + String DELIVERY_SEND = "https://api.weixin.qq.com/shop/delivery/send"; + String DELIVERY_RECEIVE = "https://api.weixin.qq.com/shop/delivery/recieve"; + } + + interface Aftersale { + String AFTERSALE_ADD = "https://api.weixin.qq.com/shop/aftersale/add"; + String AFTERSALE_GET = "https://api.weixin.qq.com/shop/aftersale/get"; + String AFTERSALE_UPDATE = "https://api.weixin.qq.com/shop/aftersale/update"; + } } /** diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImplTest.java new file mode 100644 index 0000000000..3d38d82e01 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopAfterSaleServiceImplTest.java @@ -0,0 +1,75 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAfterSaleAddRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAfterSaleGetRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopAfterSaleUpdateRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopAfterSaleGetResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +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 java.util.ArrayList; +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author liming1019 + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaShopAfterSaleServiceImplTest { + @Inject + private WxMaService wxService; + + @Test + public void testAdd() throws WxErrorException { + WxMaShopAfterSaleAddRequest.ProductInfosBean productInfosBean = WxMaShopAfterSaleAddRequest.ProductInfosBean.builder() + .outProductId("234245") + .outSkuId("23424") + .productCnt(5) + .build(); + WxMaShopAfterSaleAddRequest request = WxMaShopAfterSaleAddRequest.builder() + .outOrderId("xxxxx") + .outAftersaleId("xxxxxx") + .openid("oTVP50O53a7jgmawAmxKukNlq3XI") + .type(1) + .createTime("2020-12-01 00:00:00") + .status(1) + .finishAllAftersale(0) + .path("/pages/aftersale.html?out_aftersale_id=xxxxx") + .refund(100L) + .productInfos(new ArrayList<>(Arrays.asList(productInfosBean))) + .build(); + WxMaShopBaseResponse response = wxService.getShopAfterSaleService().add(request); + assertThat(response).isNotNull(); + } + + @Test + public void testGet() throws WxErrorException { + WxMaShopAfterSaleGetRequest request = WxMaShopAfterSaleGetRequest.builder() + .openid("oTVP50O53a7jgmawAmxKukNlq3XI") + .orderId(32434234L) + .outOrderId("xxxxx") + .build(); + WxMaShopAfterSaleGetResponse response = wxService.getShopAfterSaleService().get(request); + assertThat(response).isNotNull(); + } + + @Test + public void testUpdate() throws WxErrorException { + WxMaShopAfterSaleUpdateRequest request = WxMaShopAfterSaleUpdateRequest.builder() + .outOrderId("xxxxx") + .openid("oTVP50O53a7jgmawAmxKukNlq3XI") + .outAftersaleId("xxxxxx") + .status(1) + .finishAllAftersale(0) + .build(); + WxMaShopBaseResponse response = wxService.getShopAfterSaleService().update(request); + assertThat(response).isNotNull(); + } +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopDeliveryServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopDeliveryServiceImplTest.java new file mode 100644 index 0000000000..e19a9c0862 --- /dev/null +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaShopDeliveryServiceImplTest.java @@ -0,0 +1,61 @@ +package cn.binarywang.wx.miniapp.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliveryRecieveRequest; +import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopDeliverySendRequest; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopBaseResponse; +import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopDeliveryGetCompanyListResponse; +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 java.util.ArrayList; +import java.util.Arrays; + +import static org.testng.Assert.assertNotNull; + +/** + * @author liming1019 + */ +@Test +@Guice(modules = ApiTestModule.class) +public class WxMaShopDeliveryServiceImplTest { + @Inject + private WxMaService wxService; + + @Test + public void testGetCompanyList() throws WxErrorException { + WxMaShopDeliveryGetCompanyListResponse response = wxService.getShopDeliveryService().getCompanyList(); + assertNotNull(response); + } + + @Test + public void testSend() throws WxErrorException { + WxMaShopDeliverySendRequest.DeliveryListBean deliveryListBean = WxMaShopDeliverySendRequest.DeliveryListBean.builder() + .deliveryId("SF") + .waybillId("23424324253") + .build(); + WxMaShopDeliverySendRequest request = WxMaShopDeliverySendRequest.builder() + .orderId(123456L) + .outOrderId("xxxxx") + .openid("oTVP50O53a7jgmawAmxKukNlq3XI") + .finishAllDelivery(0) + .deliveryList(new ArrayList<>(Arrays.asList(deliveryListBean))) + .build(); + WxMaShopBaseResponse response = wxService.getShopDeliveryService().send(request); + assertNotNull(response); + } + + @Test + public void testReceive() throws WxErrorException { + WxMaShopDeliveryRecieveRequest request = WxMaShopDeliveryRecieveRequest.builder() + .openid("oTVP50O53a7jgmawAmxKukNlq3XI") + .orderId(123456L) + .outOrderId("xxxxx") + .build(); + WxMaShopBaseResponse response = wxService.getShopDeliveryService().receive(request); + assertNotNull(response); + } +} From 708553cf404f3c3a6a0465db8686be8c191c5988 Mon Sep 17 00:00:00 2001 From: liming Date: Tue, 17 Aug 2021 12:14:59 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=86=85=E5=AE=B9=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wx/miniapp/api/WxMaSecCheckService.java | 13 ++++ .../api/impl/WxMaSecCheckServiceImpl.java | 16 +++++ .../wx/miniapp/bean/WxMaBaseResponse.java | 32 +++++++++ .../security/WxMaMsgSecCheckCheckRequest.java | 37 ++++++++++ .../WxMaMsgSecCheckCheckResponse.java | 72 +++++++++++++++++++ .../api/impl/WxMaSecCheckServiceImplTest.java | 14 ++++ 6 files changed, 184 insertions(+) create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaBaseResponse.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/security/WxMaMsgSecCheckCheckRequest.java create mode 100644 weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/security/WxMaMsgSecCheckCheckResponse.java diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSecCheckService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSecCheckService.java index 50e03b30d6..8b135adcdf 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSecCheckService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSecCheckService.java @@ -1,6 +1,8 @@ package cn.binarywang.wx.miniapp.api; import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult; +import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest; +import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse; import me.chanjar.weixin.common.error.WxErrorException; import java.io.File; @@ -55,6 +57,17 @@ public interface WxMaSecCheckService { boolean checkMessage(String msgString) throws WxErrorException; + /** + *
+   * 检查一段文本是否含有违法违规内容(新版本接口,主要是request和response做了参数优化)
+   * 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html
+   * 
+ * @param msgRequest + * @return WxMaMsgSecCheckCheckResponse + * @throws WxErrorException + */ + WxMaMsgSecCheckCheckResponse checkMessage(WxMaMsgSecCheckCheckRequest msgRequest) throws WxErrorException; + /** *
    * 异步校验图片/音频是否含有违法违规内容。
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImpl.java
index fbff2f3203..332a47ad7a 100644
--- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImpl.java
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImpl.java
@@ -3,12 +3,17 @@
 import cn.binarywang.wx.miniapp.api.WxMaSecCheckService;
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.bean.WxMaMediaAsyncCheckResult;
+import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest;
+import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse;
+import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
 import com.google.gson.JsonObject;
 import lombok.RequiredArgsConstructor;
 import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
+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.MediaUploadRequestExecutor;
+import me.chanjar.weixin.common.util.json.GsonParser;
 import org.apache.commons.io.FileUtils;
 
 import java.io.File;
@@ -16,6 +21,7 @@
 import java.net.URL;
 
 import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.SecCheck.*;
+import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE;
 
 /**
  * 
@@ -59,6 +65,16 @@ public boolean checkMessage(String msgString) throws WxErrorException {
     return true;
   }
 
+  @Override
+  public WxMaMsgSecCheckCheckResponse checkMessage(WxMaMsgSecCheckCheckRequest msgRequest) throws WxErrorException {
+    String response = this.service.post(MSG_SEC_CHECK_URL, msgRequest);
+    JsonObject jsonObject = GsonParser.parse(response);
+    if (jsonObject.get(ERRCODE).getAsInt() != 0) {
+      throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
+    }
+    return WxMaGsonBuilder.create().fromJson(response, WxMaMsgSecCheckCheckResponse.class);
+  }
+
   @Override
   public WxMaMediaAsyncCheckResult mediaCheckAsync(String mediaUrl, int mediaType)
     throws WxErrorException {
diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaBaseResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaBaseResponse.java
new file mode 100644
index 0000000000..a0f524d324
--- /dev/null
+++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaBaseResponse.java
@@ -0,0 +1,32 @@
+package cn.binarywang.wx.miniapp.bean;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author liming1019
+ * @date 2021/8/17
+ */
+@Data
+public class WxMaBaseResponse implements Serializable {
+  private static final long serialVersionUID = 3932406255203539965L;
+  /**
+   * 错误码
+   * 
+   * 是否必填:
+   * 
+ */ + @SerializedName("errcode") + private Integer errcode; + + /** + * 错误信息 + *
+   * 是否必填:
+   * 
+ */ + @SerializedName("errmsg") + private String errmsg; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/security/WxMaMsgSecCheckCheckRequest.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/security/WxMaMsgSecCheckCheckRequest.java new file mode 100644 index 0000000000..2379f14b3c --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/security/WxMaMsgSecCheckCheckRequest.java @@ -0,0 +1,37 @@ +package cn.binarywang.wx.miniapp.bean.security; + +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author liming1019 + */ +@Data +@Builder +public class WxMaMsgSecCheckCheckRequest implements Serializable { + private static final long serialVersionUID = 3233176903681625506L; + + @SerializedName("version") + private String version; + + @SerializedName("openid") + private String openid; + + @SerializedName("scene") + private Integer scene; + + @SerializedName("content") + private String content; + + @SerializedName("nickname") + private String nickname; + + @SerializedName("title") + private String title; + + @SerializedName("signature") + private String signature; +} diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/security/WxMaMsgSecCheckCheckResponse.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/security/WxMaMsgSecCheckCheckResponse.java new file mode 100644 index 0000000000..6e6a93afe3 --- /dev/null +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/security/WxMaMsgSecCheckCheckResponse.java @@ -0,0 +1,72 @@ +package cn.binarywang.wx.miniapp.bean.security; + +import cn.binarywang.wx.miniapp.bean.WxMaBaseResponse; +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author liming1019 + */ +@Data +@Builder +public class WxMaMsgSecCheckCheckResponse extends WxMaBaseResponse implements Serializable { + private static final long serialVersionUID = 1903247824980080974L; + /** + * result : {"suggest":"risky","label":20001} + * detail : [{"strategy":"content_model","errcode":0,"suggest":"risky","label":20006,"prob":90},{"strategy":"keyword","errcode":0,"suggest":"pass","label":20006,"level":20,"keyword":"命中的关键词1"},{"strategy":"keyword","errcode":0,"suggest":"risky","label":20006,"level":90,"keyword":"命中的关键词2"}] + * trace_id : 60ae120f-371d5872-7941a05b + */ + @SerializedName("result") + private ResultBean result; + @SerializedName("trace_id") + private String traceId; + @SerializedName("detail") + private List detail; + + @Data + @Builder + public static class ResultBean implements Serializable { + /** + * suggest : risky + * label : 20001 + */ + + @SerializedName("suggest") + private String suggest; + @SerializedName("label") + private String label; + } + + @Data + @Builder + public static class DetailBean implements Serializable { + /** + * strategy : content_model + * errcode : 0 + * suggest : risky + * label : 20006 + * prob : 90 + * level : 20 + * keyword : 命中的关键词1 + */ + + @SerializedName("strategy") + private String strategy; + @SerializedName("errcode") + private Integer errcode; + @SerializedName("suggest") + private String suggest; + @SerializedName("label") + private String label; + @SerializedName("prob") + private Integer prob; + @SerializedName("level") + private String level; + @SerializedName("keyword") + private String keyword; + } +} diff --git a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImplTest.java b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImplTest.java index 19bca1ca4f..f55ce9c487 100644 --- a/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImplTest.java +++ b/weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImplTest.java @@ -2,6 +2,8 @@ import java.io.File; +import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckRequest; +import cn.binarywang.wx.miniapp.bean.security.WxMaMsgSecCheckCheckResponse; import org.testng.annotations.*; import cn.binarywang.wx.miniapp.api.WxMaService; @@ -49,4 +51,16 @@ public void testCheckMessage(String msg, boolean result) throws WxErrorException .checkMessage(msg)) .isEqualTo(result); } + + @Test(dataProvider = "secData") + public void testCheckMessage2(String msg, boolean result) throws WxErrorException { + WxMaMsgSecCheckCheckRequest request = WxMaMsgSecCheckCheckRequest.builder() + .content(msg) + .scene(1) + .version("2") + .openid("xxx") + .build(); + WxMaMsgSecCheckCheckResponse response = this.wxService.getSecCheckService().checkMessage(request); + assertThat(response).isNotNull(); + } } From fafb6b6121994a283b5a5d404fc6fe48d8ca9900 Mon Sep 17 00:00:00 2001 From: liming Date: Tue, 17 Aug 2021 16:50:02 +0800 Subject: [PATCH 8/8] =?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=B8=8A=E4=BC=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0resp=5Ftype?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../result/WxMinishopImageUploadCustomizeResult.java | 5 +++-- .../http/MinishopUploadRequestCustomizeExecutor.java | 12 +++++++----- ...eMinishopMediaUploadRequestCustomizeExecutor.java | 5 +++-- ...pMinishopMediaUploadRequestCustomizeExecutor.java | 4 ++-- ...pMinishopMediaUploadRequestCustomizeExecutor.java | 4 ++-- .../wx/miniapp/api/WxMaShopImgService.java | 11 +++++++++++ .../wx/miniapp/api/impl/WxMaShopImgServiceImpl.java | 9 ++++++++- .../miniapp/api/impl/WxMaShopImgServiceImplTest.java | 7 +++++++ 8 files changed, 43 insertions(+), 14 deletions(-) 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 index e3077fd00a..515189e469 100644 --- 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 @@ -21,12 +21,13 @@ public static WxMinishopImageUploadCustomizeResult fromJson(String json) { 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("media_id")) { + 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; } 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 index d782466c3b..23309202d7 100644 --- 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 @@ -12,9 +12,11 @@ public abstract class MinishopUploadRequestCustomizeExecutor implements RequestExecutor { protected RequestHttp requestHttp; + protected String respType; - public MinishopUploadRequestCustomizeExecutor(RequestHttp requestHttp) { + public MinishopUploadRequestCustomizeExecutor(RequestHttp requestHttp, String respType) { this.requestHttp = requestHttp; + this.respType = respType; } @Override @@ -22,14 +24,14 @@ public void execute(String uri, File data, ResponseHandler create(RequestHttp requestHttp) { + public static RequestExecutor create(RequestHttp requestHttp, String respType) { switch (requestHttp.getRequestType()) { case APACHE_HTTP: - return new ApacheMinishopMediaUploadRequestCustomizeExecutor(requestHttp); + return new ApacheMinishopMediaUploadRequestCustomizeExecutor(requestHttp, respType); case JODD_HTTP: - return new JoddHttpMinishopMediaUploadRequestCustomizeExecutor(requestHttp); + return new JoddHttpMinishopMediaUploadRequestCustomizeExecutor(requestHttp, respType); case OK_HTTP: - return new OkHttpMinishopMediaUploadRequestCustomizeExecutor(requestHttp); + return new OkHttpMinishopMediaUploadRequestCustomizeExecutor(requestHttp, respType); 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 index dc38fbae5a..64888c08d6 100644 --- 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 @@ -24,8 +24,8 @@ */ @Slf4j public class ApacheMinishopMediaUploadRequestCustomizeExecutor extends MinishopUploadRequestCustomizeExecutor { - public ApacheMinishopMediaUploadRequestCustomizeExecutor(RequestHttp requestHttp) { - super(requestHttp); + public ApacheMinishopMediaUploadRequestCustomizeExecutor(RequestHttp requestHttp, String respType) { + super(requestHttp, respType); } @Override @@ -39,6 +39,7 @@ public WxMinishopImageUploadCustomizeResult execute(String uri, File file, WxTyp HttpEntity entity = MultipartEntityBuilder .create() .addBinaryBody("media", file) + .addTextBody("resp_type", this.respType) .setMode(HttpMultipartMode.RFC6532) .build(); httpPost.setEntity(entity); 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 index 8fa1de4279..a79eb8eda5 100644 --- 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 @@ -22,8 +22,8 @@ */ @Slf4j public class JoddHttpMinishopMediaUploadRequestCustomizeExecutor extends MinishopUploadRequestCustomizeExecutor { - public JoddHttpMinishopMediaUploadRequestCustomizeExecutor(RequestHttp requestHttp) { - super(requestHttp); + public JoddHttpMinishopMediaUploadRequestCustomizeExecutor(RequestHttp requestHttp, String respType) { + super(requestHttp, respType); } @Override 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 index 8b2cdc7b6c..45d112cd6c 100644 --- 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 @@ -18,8 +18,8 @@ */ @Slf4j public class OkHttpMinishopMediaUploadRequestCustomizeExecutor extends MinishopUploadRequestCustomizeExecutor { - public OkHttpMinishopMediaUploadRequestCustomizeExecutor(RequestHttp requestHttp) { - super(requestHttp); + public OkHttpMinishopMediaUploadRequestCustomizeExecutor(RequestHttp requestHttp, String respType) { + super(requestHttp, respType); } @Override 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 index c44bc7df35..2cb9334fc2 100644 --- 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 @@ -14,8 +14,19 @@ public interface WxMaShopImgService { /** * 上传图片 * + * @param file * @return WxMinishopImageUploadCustomizeResult * @throws WxErrorException */ WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException; + + /** + * 上传图片,带respType参数 + * + * @param file + * @param respType + * @return WxMinishopImageUploadCustomizeResult + * @throws WxErrorException + */ + WxMinishopImageUploadCustomizeResult uploadImg(File file, String respType) throws WxErrorException; } 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 index f253bca280..1c69f8dc80 100644 --- 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 @@ -23,7 +23,14 @@ public class WxMaShopImgServiceImpl implements WxMaShopImgService { @Override public WxMinishopImageUploadCustomizeResult uploadImg(File file) throws WxErrorException { WxMinishopImageUploadCustomizeResult result = this.service.execute( - MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp()), IMG_UPLOAD, file); + MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp(), "0"), IMG_UPLOAD, file); + return result; + } + + @Override + public WxMinishopImageUploadCustomizeResult uploadImg(File file, String respType) throws WxErrorException { + WxMinishopImageUploadCustomizeResult result = this.service.execute( + MinishopUploadRequestCustomizeExecutor.create(this.service.getRequestHttp(), respType), IMG_UPLOAD, file); return result; } } 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 index 191b429630..060896ab09 100644 --- 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 @@ -28,4 +28,11 @@ public void testUploadImg() throws WxErrorException { WxMinishopImageUploadCustomizeResult result = wxService.getShopImgService().uploadImg(file); assertThat(result).isNotNull(); } + + @Test + public void testUploadImg2() throws WxErrorException { + File file = new File("/Users/liming/Desktop/test.jpeg"); + WxMinishopImageUploadCustomizeResult result = wxService.getShopImgService().uploadImg(file, "1"); + assertThat(result).isNotNull(); + } }