🆕 #2249 【小程序】增加自定义组件之商家入驻相关接口

This commit is contained in:
liming1019 2021-08-09 22:08:29 +08:00 committed by GitHub
parent 5c71b2a29f
commit 16d98a6142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 582 additions and 0 deletions

View File

@ -393,30 +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();

View File

@ -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;
}

View File

@ -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;
}

View File

@ -66,6 +66,8 @@ public abstract class BaseWxMaServiceImpl<H, P> 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 WxMaShopCatService shopCatService = new WxMaShopCatServiceImpl(this);
private final WxMaLinkService linkService = new WxMaLinkServiceImpl(this);
private final WxMaReimburseInvoiceService reimburseInvoiceService = new WxMaReimburseInvoiceServiceImpl(this);
private Map<String, WxMaConfig> configMap;
@ -522,6 +524,16 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
return this.shopRegisterService;
}
@Override
public WxMaShopAccountService getShopAccountService() {
return this.shopAccountService;
}
@Override
public WxMaShopCatService getShopCatService() {
return this.shopCatService;
}
@Override
public WxMaLinkService getLinkService() {
return this.linkService;

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<WxMaShopAccountGetBrandListItem> items;
}

View File

@ -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<WxMaShopAccountGetCategoryListItem> items;
}

View File

@ -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;
}

View File

@ -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<WxMaShopCatGetDetail> thirdCatList;
}

View File

@ -326,6 +326,17 @@ public class WxMaApiUrlConstants {
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";
}
interface Cat {
String GET_CAT = "https://api.weixin.qq.com/shop/cat/get";
}
}
/**

View File

@ -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();
}
}

View File

@ -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();
}
}