🎨 统一抽取errcode常量,同步优化规范部分代码

This commit is contained in:
Binary Wang
2023-04-23 13:19:06 +08:00
parent 54d1b92156
commit 0affa26790
47 changed files with 166 additions and 144 deletions

View File

@ -1,9 +1,9 @@
package me.chanjar.weixin.open.api;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.bean.minishopGoods.AddMinishopGoodsSPU;
import me.chanjar.weixin.open.bean.minishopGoods.GoodsCatList;
import me.chanjar.weixin.open.bean.minishopGoods.ParentCatId;
import me.chanjar.weixin.open.bean.minishopgoods.AddMinishopGoodsSPU;
import me.chanjar.weixin.open.bean.minishopgoods.GoodsCatList;
import me.chanjar.weixin.open.bean.minishopgoods.ParentCatId;
import me.chanjar.weixin.open.bean.result.WxOpenResult;
/**

View File

@ -756,7 +756,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
log.info("response: " + response);
JsonObject respJson = GsonParser.parse(response);
MinishopCategories categories = new MinishopCategories();
categories.setErrcode(respJson.get("errcode").getAsInt());
categories.setErrcode(respJson.get(WxConsts.ERR_CODE).getAsInt());
if (categories.getErrcode() == 0) {
JsonArray catListJson = respJson.getAsJsonArray("cat_list");
if (catListJson != null || catListJson.size() > 0) {
@ -786,7 +786,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
MinishopBrandList brandList = new MinishopBrandList();
brandList.setErrcode(respJson.get("errcode").getAsInt());
brandList.setErrcode(respJson.get(WxConsts.ERR_CODE).getAsInt());
if (brandList.getErrcode() == 0) {
JsonArray brandArrayJson = respJson.get("brands").getAsJsonArray();
if (brandArrayJson.size() > 0) {
@ -823,7 +823,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
MinishopDeliveryTemplateResult templateResult = new MinishopDeliveryTemplateResult();
templateResult.setErrCode(respJson.get("errcode").getAsInt());
templateResult.setErrCode(respJson.get(WxConsts.ERR_CODE).getAsInt());
if (templateResult.getErrCode() == 0) {
JsonArray templateArrayJson = respJson.get("template_list").getAsJsonArray();
if (templateArrayJson.size() > 0) {
@ -856,7 +856,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
MinishopShopCatList shopCatList = new MinishopShopCatList();
shopCatList.setErrcode(respJson.get("errcode").getAsInt());
shopCatList.setErrcode(respJson.get(WxConsts.ERR_CODE).getAsInt());
if (shopCatList.getErrcode() == 0) {
JsonArray shopcatArrayJson = respJson.get("shopcat_list").getAsJsonArray();
if (shopcatArrayJson.size() > 0) {
@ -890,7 +890,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
JsonObject respObj = GsonParser.parse(response);
WxMinishopAddGoodsSpuResult result = new WxMinishopAddGoodsSpuResult();
result.setErrcode(respObj.get("errcode").getAsInt());
result.setErrcode(respObj.get(WxConsts.ERR_CODE).getAsInt());
if (result.getErrcode() == 0) {
JsonArray companyArray = respObj.get("company_list").getAsJsonArray();
List<WxMinishopDeliveryCompany> companies = new ArrayList<>();
@ -915,7 +915,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
Integer couponId = -1;
if (respJson.get("errcode").getAsInt() == 0) {
if (respJson.get(WxConsts.ERR_CODE).getAsInt() == 0) {
JsonObject dataJson = respJson.get("data").getAsJsonObject();
couponId = dataJson.get("coupon_id").getAsInt();
}
@ -949,7 +949,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
Integer couponId = -1;
if (respJson.get("errcode").getAsInt() == 0) {
if (respJson.get(WxConsts.ERR_CODE).getAsInt() == 0) {
JsonObject dataJson = respJson.get("data").getAsJsonObject();
couponId = dataJson.get("coupon_id").getAsInt();
}
@ -978,7 +978,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
JsonObject respObj = GsonParser.parse(response);
WxMinishopAddGoodsSpuResult result = new WxMinishopAddGoodsSpuResult();
result.setErrcode(respObj.get("errcode").getAsInt());
result.setErrcode(respObj.get(WxConsts.ERR_CODE).getAsInt());
if (result.getErrcode() == 0) {
JsonObject dataObj = respObj.get("data").getAsJsonObject();
@ -1016,7 +1016,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
JsonObject respObj = GsonParser.parse(response);
WxMinishopAddGoodsSpuResult result = new WxMinishopAddGoodsSpuResult();
result.setErrcode(respObj.get("errcode").getAsInt());
result.setErrcode(respObj.get(WxConsts.ERR_CODE).getAsInt());
if (result.getErrcode() == 0) {
JsonObject dataObj = respObj.get("data").getAsJsonObject();
WxMinishopAddGoodsSpuData resultData = new WxMinishopAddGoodsSpuData();
@ -1066,7 +1066,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
JsonObject respObj = GsonParser.parse(response);
WxMinishopAddGoodsSpuResult result = new WxMinishopAddGoodsSpuResult();
result.setErrcode(respObj.get("errcode").getAsInt());
result.setErrcode(respObj.get(WxConsts.ERR_CODE).getAsInt());
if (result.getErrcode() == 0) {
JsonObject dataObj = respObj.get("data").getAsJsonObject();
WxMinishopAddGoodsSkuData resultData = new WxMinishopAddGoodsSkuData();
@ -1171,7 +1171,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respObj = GsonParser.parse(response);
Integer taskId = 0;
if (respObj.get("errcode").getAsInt() == 0) {
if (respObj.get(WxConsts.ERR_CODE).getAsInt() == 0) {
taskId = respObj.get("task_id").getAsInt();
}
return taskId;
@ -1187,7 +1187,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respObj = GsonParser.parse(response);
List<LimitDiscountGoods> limitDiscountGoodsList = new ArrayList<>();
if (respObj.get("errcode").getAsInt() == 0) {
if (respObj.get(WxConsts.ERR_CODE).getAsInt() == 0) {
//成功获取到秒杀活动列表
JsonArray jsonArray = respObj.get("limited_discount_list").getAsJsonArray();

View File

@ -1,14 +1,12 @@
package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.api.WxOpenMinishopGoodsService;
import me.chanjar.weixin.open.bean.minishopGoods.AddMinishopGoodsSPU;
import me.chanjar.weixin.open.bean.minishopGoods.GoodsCatList;
import me.chanjar.weixin.open.bean.minishopGoods.ParentCatId;
import me.chanjar.weixin.open.bean.minishopgoods.AddMinishopGoodsSPU;
import me.chanjar.weixin.open.bean.minishopgoods.GoodsCatList;
import me.chanjar.weixin.open.bean.minishopgoods.ParentCatId;
import me.chanjar.weixin.open.bean.result.WxOpenResult;
@Slf4j

View File

@ -1,4 +1,4 @@
package me.chanjar.weixin.open.bean.minishopGoods;
package me.chanjar.weixin.open.bean.minishopgoods;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

View File

@ -1,4 +1,4 @@
package me.chanjar.weixin.open.bean.minishopGoods;
package me.chanjar.weixin.open.bean.minishopgoods;
import com.google.gson.JsonObject;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package me.chanjar.weixin.open.bean.minishopGoods;
package me.chanjar.weixin.open.bean.minishopgoods;
import com.google.gson.JsonObject;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package me.chanjar.weixin.open.bean.minishopGoods;
package me.chanjar.weixin.open.bean.minishopgoods;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

View File

@ -1,4 +1,4 @@
package me.chanjar.weixin.open.bean.minishopGoods;
package me.chanjar.weixin.open.bean.minishopgoods;
import com.google.gson.JsonObject;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package me.chanjar.weixin.open.bean.minishopGoods;
package me.chanjar.weixin.open.bean.minishopgoods;
import com.google.gson.JsonObject;
import lombok.Data;

View File

@ -1,12 +1,16 @@
package me.chanjar.weixin.open.bean.minishopGoods;
package me.chanjar.weixin.open.bean.minishopgoods;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.Data;
import lombok.experimental.Accessors;
import me.chanjar.weixin.common.api.WxConsts;
import java.util.List;
/**
* @author kelvenlaw
*/
@Data
@Accessors(chain = true)
public class GoodsCatList {
@ -26,7 +30,7 @@ public class GoodsCatList {
public JsonObject toJsonObject() {
Gson gson = new Gson();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("errcode", errcode);
jsonObject.addProperty(WxConsts.ERR_CODE, errcode);
jsonObject.addProperty("errmsg", errmsg);
jsonObject.addProperty("cat_list", gson.toJson(catList));
return jsonObject;

View File

@ -1,4 +1,4 @@
package me.chanjar.weixin.open.bean.minishopGoods;
package me.chanjar.weixin.open.bean.minishopgoods;
import com.google.gson.JsonObject;
import lombok.Data;

View File

@ -1,11 +1,10 @@
package me.chanjar.weixin.open.bean.minishopGoods;
package me.chanjar.weixin.open.bean.minishopgoods;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Arrays;
import java.util.List;
@Data