From 60663f2f7acaa7af5ee6092f2e7a887a38767c4c Mon Sep 17 00:00:00 2001 From: liming1019 Date: Fri, 6 Aug 2021 10:33:32 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#2243=20=E3=80=90=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E3=80=91=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=94=B3=E8=AF=B7=E6=8E=A5=E5=85=A5=E7=9B=B8?= =?UTF-8?q?=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(); + } +}