Skip to content

Commit

Permalink
🆕 #2243 【小程序】增加自定义组件申请接入相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
liming1019 committed Aug 6, 2021
1 parent 2d36b4d commit 60663f2
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ public interface WxMaService extends WxService {
*/
WxMaShopSpuService getShopSpuService();

/**
* 返回小程序交易组件-接入申请接口
* @return
*/
WxMaShopRegisterService getShopRegisterService();

/**
* 获取小程序 URL Link服务接口
* @return
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public abstract class BaseWxMaServiceImpl<H, P> 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<String, WxMaConfig> configMap;
Expand Down Expand Up @@ -516,6 +517,11 @@ public WxMaShopOrderService getShopOrderService() {
return this.shopOrderService;
}

@Override
public WxMaShopRegisterService getShopRegisterService() {
return this.shopRegisterService;
}

@Override
public WxMaLinkService getLinkService() {
return this.linkService;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

Original file line number Diff line number Diff line change
@@ -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;
}

Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 60663f2

Please sign in to comment.