Переглянути джерело

:new: #2255 【小程序】增加自定义组件之接入商品前必需的接口

liming1019 3 роки тому
батько
коміт
b3eadb4ffa

+ 7 - 0
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java

@@ -434,6 +434,13 @@ public interface WxMaService extends WxService {
   WxMaShopImgService getShopImgService();
 
   /**
+   * 小程序交易组件-接入商品前必需接口-审核相关接口
+   *
+   * @return
+   */
+  WxMaShopAuditService getShopAuditService();
+
+  /**
    * 获取小程序 URL Link服务接口
    *
    * @return

+ 53 - 0
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;
+}

+ 6 - 0
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java

@@ -69,6 +69,7 @@ public abstract class BaseWxMaServiceImpl<H, P> 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<String, WxMaConfig> configMap;
@@ -541,6 +542,11 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
   }
 
   @Override
+  public WxMaShopAuditService getShopAuditService() {
+    return this.shopAuditService;
+  }
+
+  @Override
   public WxMaLinkService getLinkService() {
     return this.linkService;
   }

+ 101 - 0
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);
+  }
+}

Різницю між файлами не показано, бо вона завелика
+ 93 - 0
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/shop/request/WxMaShopAuditBrandRequest.java


+ 59 - 0
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<String> 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<String> certificate;
+    }
+  }
+}

+ 20 - 0
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;
+}

+ 20 - 0
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;
+}

+ 40 - 0
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;
+  }
+}

+ 7 - 0
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java

@@ -341,6 +341,13 @@ public class WxMaApiUrlConstants {
     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";
+    }
   }
 
   /**

+ 93 - 0
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<String>(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<String>(Arrays.asList("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg")))
+      .trademarkRegistrationCertificate(new ArrayList<String>(Arrays.asList("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg")))
+      .trademarkChangeCertificate(new ArrayList<String>(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<String>(Arrays.asList("https://img.zhls.qq.com/3/609b98f7e0ff43d59ce6d9cca636c3e0.jpg")))
+      .trademarkApplicant("张三")
+      .trademarkApplicationTime("2020-03-25 12:05:25")
+      .importedGoodsForm(new ArrayList<String>(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<String>(Arrays.asList("www.xxxxx.com")));
+    auditReqBean.setCategoryInfo(WxMaShopAuditCategoryRequest.AuditReqBean.CategoryInfoBean.builder()
+      .level1(7419)
+      .level2(7439)
+      .level3(7448)
+      .certificate(new ArrayList<String>(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();
+  }
+}