🎨 统一抽取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,5 +1,7 @@
package me.chanjar.weixin.common.api; package me.chanjar.weixin.common.api;
import lombok.experimental.UtilityClass;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -12,6 +14,7 @@ import static me.chanjar.weixin.common.error.WxMpErrorMsgEnum.*;
* *
* @author Daniel Qian & binarywang & Wang_Wong * @author Daniel Qian & binarywang & Wang_Wong
*/ */
@UtilityClass
public class WxConsts { public class WxConsts {
/** /**
* access_token 相关错误代码 * access_token 相关错误代码
@ -25,9 +28,15 @@ public class WxConsts {
public static final List<Integer> ACCESS_TOKEN_ERROR_CODES = Arrays.asList(CODE_40001.getCode(), public static final List<Integer> ACCESS_TOKEN_ERROR_CODES = Arrays.asList(CODE_40001.getCode(),
CODE_40014.getCode(), CODE_42001.getCode()); CODE_40014.getCode(), CODE_42001.getCode());
/**
* 微信接口返回的参数errcode.
*/
public static final String ERR_CODE = "errcode";
/** /**
* 微信推送过来的消息的类型和发送给微信xml格式消息的消息类型. * 微信推送过来的消息的类型和发送给微信xml格式消息的消息类型.
*/ */
@UtilityClass
public static class XmlMsgType { public static class XmlMsgType {
public static final String TEXT = "text"; public static final String TEXT = "text";
public static final String IMAGE = "image"; public static final String IMAGE = "image";
@ -51,6 +60,7 @@ public class WxConsts {
/** /**
* 主动发送消息(即客服消息)的消息类型. * 主动发送消息(即客服消息)的消息类型.
*/ */
@UtilityClass
public static class KefuMsgType { public static class KefuMsgType {
/** /**
* 文本消息. * 文本消息.
@ -137,6 +147,7 @@ public class WxConsts {
* 发送学校通知类型 * 发送学校通知类型
* https://developer.work.weixin.qq.com/document/path/92321 * https://developer.work.weixin.qq.com/document/path/92321
*/ */
@UtilityClass
public static class SchoolContactMsgType { public static class SchoolContactMsgType {
/** /**
@ -184,6 +195,7 @@ public class WxConsts {
/** /**
* 企业微信模板卡片消息的卡片类型 * 企业微信模板卡片消息的卡片类型
*/ */
@UtilityClass
public static class TemplateCardType { public static class TemplateCardType {
/** /**
* 文本通知型卡片 * 文本通知型卡片
@ -210,6 +222,7 @@ public class WxConsts {
/** /**
* 表示是否是保密消息0表示否1表示是默认0. * 表示是否是保密消息0表示否1表示是默认0.
*/ */
@UtilityClass
public static class KefuMsgSafe { public static class KefuMsgSafe {
public static final String NO = "0"; public static final String NO = "0";
public static final String YES = "1"; public static final String YES = "1";
@ -218,6 +231,7 @@ public class WxConsts {
/** /**
* 群发消息的消息类型. * 群发消息的消息类型.
*/ */
@UtilityClass
public static class MassMsgType { public static class MassMsgType {
public static final String MPNEWS = "mpnews"; public static final String MPNEWS = "mpnews";
public static final String TEXT = "text"; public static final String TEXT = "text";
@ -230,6 +244,7 @@ public class WxConsts {
/** /**
* 群发消息后微信端推送给服务器的反馈消息. * 群发消息后微信端推送给服务器的反馈消息.
*/ */
@UtilityClass
public static class MassMsgStatus { public static class MassMsgStatus {
public static final String SEND_SUCCESS = "send success"; public static final String SEND_SUCCESS = "send success";
public static final String SEND_FAIL = "send fail"; public static final String SEND_FAIL = "send fail";
@ -277,6 +292,7 @@ public class WxConsts {
/** /**
* 微信端推送过来的事件类型. * 微信端推送过来的事件类型.
*/ */
@UtilityClass
public static class EventType { public static class EventType {
public static final String SUBSCRIBE = "subscribe"; public static final String SUBSCRIBE = "subscribe";
public static final String UNSUBSCRIBE = "unsubscribe"; public static final String UNSUBSCRIBE = "unsubscribe";
@ -417,7 +433,7 @@ public class WxConsts {
/** /**
* 小程序自定义交易组件支付通知 * 小程序自定义交易组件支付通知
*/ */
public static final String OPEN_PRODUCT_ORDER_PAY = "open_product_order_pay"; public static final String OPEN_PRODUCT_ORDER_PAY = "open_product_order_pay";
/** /**
* 点击菜单跳转小程序的事件推送 * 点击菜单跳转小程序的事件推送
*/ */
@ -453,6 +469,7 @@ public class WxConsts {
/** /**
* 自定义菜单的按钮类型. * 自定义菜单的按钮类型.
*/ */
@UtilityClass
public static class MenuButtonType { public static class MenuButtonType {
/** /**
* 点击推事件. * 点击推事件.
@ -503,6 +520,7 @@ public class WxConsts {
/** /**
* oauth2网页授权的scope. * oauth2网页授权的scope.
*/ */
@UtilityClass
public static class OAuth2Scope { public static class OAuth2Scope {
/** /**
* 不弹出授权页面直接跳转只能获取用户openid. * 不弹出授权页面直接跳转只能获取用户openid.
@ -523,6 +541,7 @@ public class WxConsts {
/** /**
* 网页应用登录授权作用域. * 网页应用登录授权作用域.
*/ */
@UtilityClass
public static class QrConnectScope { public static class QrConnectScope {
public static final String SNSAPI_LOGIN = "snsapi_login"; public static final String SNSAPI_LOGIN = "snsapi_login";
} }
@ -530,6 +549,7 @@ public class WxConsts {
/** /**
* 永久素材类型. * 永久素材类型.
*/ */
@UtilityClass
public static class MaterialType { public static class MaterialType {
public static final String NEWS = "news"; public static final String NEWS = "news";
public static final String VOICE = "voice"; public static final String VOICE = "voice";
@ -541,6 +561,7 @@ public class WxConsts {
/** /**
* 网络检测入参. * 网络检测入参.
*/ */
@UtilityClass
public static class NetCheckArgs { public static class NetCheckArgs {
public static final String ACTIONDNS = "dns"; public static final String ACTIONDNS = "dns";
public static final String ACTIONPING = "ping"; public static final String ACTIONPING = "ping";
@ -554,6 +575,7 @@ public class WxConsts {
/** /**
* appId 类型 * appId 类型
*/ */
@UtilityClass
public static class AppIdType { public static class AppIdType {
/** /**
* 公众号appId类型 * 公众号appId类型

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.common.bean.result;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import lombok.Data; import lombok.Data;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.io.Serializable; import java.io.Serializable;
@ -17,7 +18,7 @@ public class WxMinishopImageUploadCustomizeResult implements Serializable {
public static WxMinishopImageUploadCustomizeResult fromJson(String json) { public static WxMinishopImageUploadCustomizeResult fromJson(String json) {
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject(); JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
WxMinishopImageUploadCustomizeResult result = new WxMinishopImageUploadCustomizeResult(); WxMinishopImageUploadCustomizeResult result = new WxMinishopImageUploadCustomizeResult();
result.setErrcode(jsonObject.get("errcode").getAsNumber().toString()); result.setErrcode(jsonObject.get(WxConsts.ERR_CODE).getAsNumber().toString());
if (result.getErrcode().equals("0")) { if (result.getErrcode().equals("0")) {
WxMinishopPicFileCustomizeResult picFileResult = new WxMinishopPicFileCustomizeResult(); WxMinishopPicFileCustomizeResult picFileResult = new WxMinishopPicFileCustomizeResult();
JsonObject picObject = jsonObject.get("img_info").getAsJsonObject(); JsonObject picObject = jsonObject.get("img_info").getAsJsonObject();

View File

@ -4,6 +4,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import lombok.Data; import lombok.Data;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.json.WxGsonBuilder; import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.io.Serializable; import java.io.Serializable;
@ -22,7 +23,7 @@ public class WxMinishopImageUploadResult implements Serializable {
public static WxMinishopImageUploadResult fromJson(String json) { public static WxMinishopImageUploadResult fromJson(String json) {
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject(); JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
WxMinishopImageUploadResult result = new WxMinishopImageUploadResult(); WxMinishopImageUploadResult result = new WxMinishopImageUploadResult();
result.setErrcode(jsonObject.get("errcode").getAsNumber().toString()); result.setErrcode(jsonObject.get(WxConsts.ERR_CODE).getAsNumber().toString());
if (result.getErrcode().equals("0")) { if (result.getErrcode().equals("0")) {
WxMinishopPicFileResult picFileResult = new WxMinishopPicFileResult(); WxMinishopPicFileResult picFileResult = new WxMinishopPicFileResult();
JsonObject picObject = jsonObject.get("pic_file").getAsJsonObject(); JsonObject picObject = jsonObject.get("pic_file").getAsJsonObject();

View File

@ -1,6 +1,7 @@
package me.chanjar.weixin.common.util.json; package me.chanjar.weixin.common.util.json;
import com.google.gson.*; import com.google.gson.*;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -16,8 +17,8 @@ public class WxErrorAdapter implements JsonDeserializer<WxError> {
WxError.WxErrorBuilder errorBuilder = WxError.builder(); WxError.WxErrorBuilder errorBuilder = WxError.builder();
JsonObject wxErrorJsonObject = json.getAsJsonObject(); JsonObject wxErrorJsonObject = json.getAsJsonObject();
if (wxErrorJsonObject.get("errcode") != null && !wxErrorJsonObject.get("errcode").isJsonNull()) { if (wxErrorJsonObject.get(WxConsts.ERR_CODE) != null && !wxErrorJsonObject.get(WxConsts.ERR_CODE).isJsonNull()) {
errorBuilder.errorCode(GsonHelper.getAsPrimitiveInt(wxErrorJsonObject.get("errcode"))); errorBuilder.errorCode(GsonHelper.getAsPrimitiveInt(wxErrorJsonObject.get(WxConsts.ERR_CODE)));
} }
if (wxErrorJsonObject.get("errmsg") != null && !wxErrorJsonObject.get("errmsg").isJsonNull()) { if (wxErrorJsonObject.get("errmsg") != null && !wxErrorJsonObject.get("errmsg").isJsonNull()) {
errorBuilder.errorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg"))); errorBuilder.errorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg")));

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -46,7 +47,7 @@ public class WxCpAgentServiceImpl implements WxCpAgentService {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_SET); String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_SET);
String responseContent = this.mainService.post(url, agentInfo.toJson()); String responseContent = this.mainService.post(url, agentInfo.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP));
} }
} }
@ -56,7 +57,7 @@ public class WxCpAgentServiceImpl implements WxCpAgentService {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_LIST); String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_LIST);
String responseContent = this.mainService.get(url, null); String responseContent = this.mainService.get(url, null);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP));
} }

View File

@ -5,6 +5,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
@ -163,7 +164,7 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
"type=agent_config&access_token=" + this.configStorage.getAccessToken(authCorpId), true); "type=agent_config&access_token=" + this.configStorage.getAccessToken(authCorpId), true);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get("errcode").getAsInt() == 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() == 0) {
String jsApiTicket = jsonObject.get("ticket").getAsString(); String jsApiTicket = jsonObject.get("ticket").getAsString();
int expiredInSeconds = jsonObject.get("expires_in").getAsInt(); int expiredInSeconds = jsonObject.get("expires_in").getAsInt();
synchronized (globalJsApiTicketRefreshLock) { synchronized (globalJsApiTicketRefreshLock) {
@ -193,7 +194,7 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
"access_token=" + this.configStorage.getAccessToken(authCorpId), true); "access_token=" + this.configStorage.getAccessToken(authCorpId), true);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get("errcode").getAsInt() == 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() == 0) {
String jsApiTicket = jsonObject.get("ticket").getAsString(); String jsApiTicket = jsonObject.get("ticket").getAsString();
int expiredInSeconds = jsonObject.get("expires_in").getAsInt(); int expiredInSeconds = jsonObject.get("expires_in").getAsInt();

View File

@ -4,7 +4,6 @@ import cn.binarywang.wx.miniapp.api.WxMaCloudService;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.cloud.*; import cn.binarywang.wx.miniapp.bean.cloud.*;
import cn.binarywang.wx.miniapp.bean.cloud.request.WxCloudSendSmsV2Request; import cn.binarywang.wx.miniapp.bean.cloud.request.WxCloudSendSmsV2Request;
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import cn.binarywang.wx.miniapp.util.JoinerUtils; import cn.binarywang.wx.miniapp.util.JoinerUtils;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -14,6 +13,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
@ -65,7 +65,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
String responseContent = wxMaService.post(DATABASE_ADD_URL, params.toString()); String responseContent = wxMaService.post(DATABASE_ADD_URL, params.toString());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent)); throw new WxErrorException(WxError.fromJson(responseContent));
} }
JsonArray idArray = jsonObject.getAsJsonArray("id_list"); JsonArray idArray = jsonObject.getAsJsonArray("id_list");
@ -89,7 +89,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
String responseContent = wxMaService.post(DATABASE_ADD_URL, params.toString()); String responseContent = wxMaService.post(DATABASE_ADD_URL, params.toString());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent)); throw new WxErrorException(WxError.fromJson(responseContent));
} }
JsonArray idArray = jsonObject.getAsJsonArray("id_list"); JsonArray idArray = jsonObject.getAsJsonArray("id_list");
@ -120,7 +120,7 @@ public class WxMaCloudServiceImpl implements WxMaCloudService {
String responseContent = wxMaService.post(DATABASE_DELETE_URL, params.toString()); String responseContent = wxMaService.post(DATABASE_DELETE_URL, params.toString());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent)); throw new WxErrorException(WxError.fromJson(responseContent));
} }
return jsonObject.get("deleted").getAsInt(); return jsonObject.get("deleted").getAsInt();

View File

@ -7,6 +7,7 @@ import cn.binarywang.wx.miniapp.bean.device.WxMaDeviceTicketRequest;
import cn.binarywang.wx.miniapp.constant.WxMaConstants; import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -32,7 +33,7 @@ public class WxMaDeviceSubscribeServiceImpl implements WxMaDeviceSubscribeServic
public String getSnTicket(WxMaDeviceTicketRequest deviceTicketRequest) throws WxErrorException { public String getSnTicket(WxMaDeviceTicketRequest deviceTicketRequest) throws WxErrorException {
String responseContent = this.service.post(GET_SN_TICKET_URL, deviceTicketRequest.toJson()); String responseContent = this.service.post(GET_SN_TICKET_URL, deviceTicketRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
String snTicket = jsonObject.get("sn_ticket").getAsString(); String snTicket = jsonObject.get("sn_ticket").getAsString();
@ -43,7 +44,7 @@ public class WxMaDeviceSubscribeServiceImpl implements WxMaDeviceSubscribeServic
public void sendDeviceSubscribeMsg(WxMaDeviceSubscribeMessageRequest deviceSubscribeMessageRequest) throws WxErrorException { public void sendDeviceSubscribeMsg(WxMaDeviceSubscribeMessageRequest deviceSubscribeMessageRequest) throws WxErrorException {
String responseContent = this.service.post(SEND_DEVICE_SUBSCRIBE_MSG_URL, deviceSubscribeMessageRequest.toJson()); String responseContent = this.service.post(SEND_DEVICE_SUBSCRIBE_MSG_URL, deviceSubscribeMessageRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
} }

View File

@ -36,6 +36,8 @@ import me.chanjar.weixin.common.util.json.GsonParser;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* 微信小程序即时配送服务. * 微信小程序即时配送服务.
* <pre> * <pre>
@ -49,11 +51,6 @@ import org.apache.commons.lang3.StringUtils;
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxMaImmediateDeliveryServiceImpl implements WxMaImmediateDeliveryService { public class WxMaImmediateDeliveryServiceImpl implements WxMaImmediateDeliveryService {
/**
* 微信响应码.
*/
public static final String ERR_CODE = "errcode";
/** /**
* 顺丰同城响应码. * 顺丰同城响应码.
*/ */

View File

@ -19,6 +19,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Room; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Room;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* <pre> * <pre>
@ -30,7 +31,6 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Ro
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxMaLiveServiceImpl implements WxMaLiveService { public class WxMaLiveServiceImpl implements WxMaLiveService {
private static final String ERR_CODE = "errcode";
private static final String ROOM_ID = "roomId"; private static final String ROOM_ID = "roomId";
private final WxMaService wxMaService; private final WxMaService wxMaService;

View File

@ -10,6 +10,7 @@ import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -34,7 +35,7 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException { public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException {
String responseContent = this.service.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson()); String responseContent = this.service.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
} }
@ -43,7 +44,7 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
public void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException { public void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException {
String responseContent = this.service.post(UNIFORM_MSG_SEND_URL, uniformMessage.toJson()); String responseContent = this.service.post(UNIFORM_MSG_SEND_URL, uniformMessage.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
} }

View File

@ -22,6 +22,7 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_GET_URL; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_GET_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_LISTING_URL; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_LISTING_URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_UPDATE_URL; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Product.Spu.PRODUCT_SPU_UPDATE_URL;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
import cn.binarywang.wx.miniapp.api.WxMaProductService; import cn.binarywang.wx.miniapp.api.WxMaProductService;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
@ -51,6 +52,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult; import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
@ -68,8 +70,6 @@ import me.chanjar.weixin.common.util.json.GsonParser;
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
public class WxMaProductServiceImpl implements WxMaProductService { public class WxMaProductServiceImpl implements WxMaProductService {
private static final String ERR_CODE = "errcode";
private final WxMaService wxMaService; private final WxMaService wxMaService;
@Override @Override
@ -143,7 +143,7 @@ public class WxMaProductServiceImpl implements WxMaProductService {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
} }
WxMinishopResult result = new WxMinishopResult(); WxMinishopResult result = new WxMinishopResult();
result.setErrcode(respObj.get("errcode").getAsInt()); result.setErrcode(respObj.get(ERR_CODE).getAsInt());
JsonObject dataObj = respObj.get("data").getAsJsonObject(); JsonObject dataObj = respObj.get("data").getAsJsonObject();
WxMinishopAddGoodsSpuData resultData = new WxMinishopAddGoodsSpuData(); WxMinishopAddGoodsSpuData resultData = new WxMinishopAddGoodsSpuData();
resultData.setProductId(dataObj.get("product_id").getAsLong()); resultData.setProductId(dataObj.get("product_id").getAsLong());
@ -201,7 +201,7 @@ public class WxMaProductServiceImpl implements WxMaProductService {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
} }
WxMinishopResult result = new WxMinishopResult(); WxMinishopResult result = new WxMinishopResult();
result.setErrcode(respObj.get("errcode").getAsInt()); result.setErrcode(respObj.get(ERR_CODE).getAsInt());
JsonObject dataObj = respObj.get("data").getAsJsonObject(); JsonObject dataObj = respObj.get("data").getAsJsonObject();
WxMinishopAddGoodsSpuData resultData = new WxMinishopAddGoodsSpuData(); WxMinishopAddGoodsSpuData resultData = new WxMinishopAddGoodsSpuData();
resultData.setProductId(dataObj.get("product_id").getAsLong()); resultData.setProductId(dataObj.get("product_id").getAsLong());
@ -260,7 +260,7 @@ public class WxMaProductServiceImpl implements WxMaProductService {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
} }
WxMinishopResult result = new WxMinishopResult(); WxMinishopResult result = new WxMinishopResult();
result.setErrcode(jsonObject.get("errcode").getAsInt()); result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonObject dataObj = jsonObject.get("data").getAsJsonObject(); JsonObject dataObj = jsonObject.get("data").getAsJsonObject();
WxMinishopAddGoodsSkuData resultData = new WxMinishopAddGoodsSkuData(); WxMinishopAddGoodsSkuData resultData = new WxMinishopAddGoodsSkuData();
resultData.setSkuId(dataObj.get("sku_id").getAsLong()); resultData.setSkuId(dataObj.get("sku_id").getAsLong());
@ -280,7 +280,7 @@ public class WxMaProductServiceImpl implements WxMaProductService {
} }
WxMinishopResult result = new WxMinishopResult(); WxMinishopResult result = new WxMinishopResult();
result.setErrcode(jsonObject.get("errcode").getAsInt()); result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonArray jsonArray = jsonObject.get("data").getAsJsonArray(); JsonArray jsonArray = jsonObject.get("data").getAsJsonArray();
List<WxMinishopAddGoodsSkuData> skuData = new ArrayList<>(); List<WxMinishopAddGoodsSkuData> skuData = new ArrayList<>();
for (JsonElement jsonElement : jsonArray) { for (JsonElement jsonElement : jsonArray) {
@ -318,7 +318,7 @@ public class WxMaProductServiceImpl implements WxMaProductService {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
} }
WxMinishopResult result = new WxMinishopResult(); WxMinishopResult result = new WxMinishopResult();
result.setErrcode(jsonObject.get("errcode").getAsInt()); result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonObject dataObj = jsonObject.get("data").getAsJsonObject(); JsonObject dataObj = jsonObject.get("data").getAsJsonObject();
WxMinishopUpdateGoodsSkuData resultData = new WxMinishopUpdateGoodsSkuData(); WxMinishopUpdateGoodsSkuData resultData = new WxMinishopUpdateGoodsSkuData();
resultData.setUpdateTime(dataObj.get("update_time").getAsString()); resultData.setUpdateTime(dataObj.get("update_time").getAsString());
@ -340,7 +340,7 @@ public class WxMaProductServiceImpl implements WxMaProductService {
} }
WxMinishopResult result = new WxMinishopResult(); WxMinishopResult result = new WxMinishopResult();
result.setErrcode(jsonObject.get("errcode").getAsInt()); result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonObject dataObj = jsonObject.get("data").getAsJsonObject(); JsonObject dataObj = jsonObject.get("data").getAsJsonObject();
WxMinishopUpdateGoodsSkuData resultData = new WxMinishopUpdateGoodsSkuData(); WxMinishopUpdateGoodsSkuData resultData = new WxMinishopUpdateGoodsSkuData();
resultData.setUpdateTime(dataObj.get("update_time").getAsString()); resultData.setUpdateTime(dataObj.get("update_time").getAsString());
@ -362,7 +362,7 @@ public class WxMaProductServiceImpl implements WxMaProductService {
} }
WxMinishopResult result = new WxMinishopResult(); WxMinishopResult result = new WxMinishopResult();
result.setErrcode(jsonObject.get("errcode").getAsInt()); result.setErrcode(jsonObject.get(ERR_CODE).getAsInt());
JsonObject dataObj = jsonObject.get("data").getAsJsonObject(); JsonObject dataObj = jsonObject.get("data").getAsJsonObject();
WxMinishopUpdateGoodsSkuData resultData = new WxMinishopUpdateGoodsSkuData(); WxMinishopUpdateGoodsSkuData resultData = new WxMinishopUpdateGoodsSkuData();
resultData.setUpdateTime(dataObj.get("update_time").getAsString()); resultData.setUpdateTime(dataObj.get("update_time").getAsString());

View File

@ -7,6 +7,7 @@ import cn.binarywang.wx.miniapp.bean.safety.response.WxMaUserSafetyRiskRankRespo
import cn.binarywang.wx.miniapp.constant.WxMaConstants; import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -27,7 +28,7 @@ public class WxMaSafetyRiskControlServiceImpl implements WxMaSafetyRiskControlSe
public WxMaUserSafetyRiskRankResponse getUserRiskRank(WxMaUserSafetyRiskRankRequest wxMaUserSafetyRiskRankRequest) throws WxErrorException { public WxMaUserSafetyRiskRankResponse getUserRiskRank(WxMaUserSafetyRiskRankRequest wxMaUserSafetyRiskRankRequest) throws WxErrorException {
String responseContent = this.service.post(GET_USER_RISK_RANK, wxMaUserSafetyRiskRankRequest.toJson()); String responseContent = this.service.post(GET_USER_RISK_RANK, wxMaUserSafetyRiskRankRequest.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaUserSafetyRiskRankResponse.fromJson(responseContent); return WxMaUserSafetyRiskRankResponse.fromJson(responseContent);

View File

@ -5,6 +5,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest; import cn.binarywang.wx.miniapp.bean.scheme.WxMaGenerateSchemeRequest;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -18,14 +19,13 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Scheme.GENER
*/ */
@AllArgsConstructor @AllArgsConstructor
public class WxMaSchemeServiceImpl implements WxMaSchemeService { public class WxMaSchemeServiceImpl implements WxMaSchemeService {
private static final String ERR_CODE = "errcode";
private final WxMaService wxMaService; private final WxMaService wxMaService;
@Override @Override
public String generate(WxMaGenerateSchemeRequest request) throws WxErrorException { public String generate(WxMaGenerateSchemeRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(GENERATE_SCHEME_URL, request.toJson()); String responseContent = this.wxMaService.post(GENERATE_SCHEME_URL, request.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return jsonObject.get("openlink").getAsString(); return jsonObject.get("openlink").getAsString();

View File

@ -22,7 +22,7 @@ import java.io.IOException;
import java.net.URL; import java.net.URL;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.SecCheck.*; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.SecCheck.*;
import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE; import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* <pre> * <pre>
@ -93,7 +93,7 @@ public class WxMaSecCheckServiceImpl implements WxMaSecCheckService {
private void parseErrorResponse(String response) throws WxErrorException { private void parseErrorResponse(String response) throws WxErrorException {
JsonObject jsonObject = GsonParser.parse(response); JsonObject jsonObject = GsonParser.parse(response);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(response, WxType.MiniApp));
} }
} }

View File

@ -11,6 +11,7 @@ import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -24,14 +25,13 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Account
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
public class WxMaShopAccountServiceImpl implements WxMaShopAccountService { public class WxMaShopAccountServiceImpl implements WxMaShopAccountService {
private static final String ERR_CODE = "errcode";
private final WxMaService wxMaService; private final WxMaService wxMaService;
@Override @Override
public WxMaShopAccountGetCategoryListResponse getCategoryList() throws WxErrorException { public WxMaShopAccountGetCategoryListResponse getCategoryList() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_CATEGORY_LIST, new JsonObject()); String responseContent = this.wxMaService.post(GET_CATEGORY_LIST, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetCategoryListResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetCategoryListResponse.class);
@ -41,7 +41,7 @@ public class WxMaShopAccountServiceImpl implements WxMaShopAccountService {
public WxMaShopAccountGetBrandListResponse getBrandList() throws WxErrorException { public WxMaShopAccountGetBrandListResponse getBrandList() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_BRAND_LIST, new JsonObject()); String responseContent = this.wxMaService.post(GET_BRAND_LIST, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetBrandListResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetBrandListResponse.class);
@ -51,7 +51,7 @@ public class WxMaShopAccountServiceImpl implements WxMaShopAccountService {
public WxMaShopBaseResponse updateInfo(WxMaShopAccountUpdateInfoRequest request) throws WxErrorException { public WxMaShopBaseResponse updateInfo(WxMaShopAccountUpdateInfoRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(UPDATE_INFO, request); String responseContent = this.wxMaService.post(UPDATE_INFO, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
@ -61,7 +61,7 @@ public class WxMaShopAccountServiceImpl implements WxMaShopAccountService {
public WxMaShopAccountGetInfoResponse getInfo() throws WxErrorException { public WxMaShopAccountGetInfoResponse getInfo() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_INFO, new JsonObject()); String responseContent = this.wxMaService.post(GET_INFO, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetInfoResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAccountGetInfoResponse.class);

View File

@ -15,7 +15,7 @@ import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Aftersale.*; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Aftersale.*;
import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE; import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* @author boris * @author boris
@ -38,7 +38,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
public WxMaShopAfterSaleAddResponse add(WxMaShopAfterSaleAddRequest request) throws WxErrorException { public WxMaShopAfterSaleAddResponse add(WxMaShopAfterSaleAddRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AFTERSALE_ADD, request); String responseContent = this.wxMaService.post(AFTERSALE_ADD, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAfterSaleAddResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAfterSaleAddResponse.class);
@ -55,7 +55,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
public WxMaShopAfterSaleGetResponse get(WxMaShopAfterSaleGetRequest request) throws WxErrorException { public WxMaShopAfterSaleGetResponse get(WxMaShopAfterSaleGetRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AFTERSALE_GET, request); String responseContent = this.wxMaService.post(AFTERSALE_GET, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAfterSaleGetResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAfterSaleGetResponse.class);
@ -72,7 +72,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
public WxMaShopEcAfterSaleGetResponse get(WxMaShopEcAfterSaleGetRequest request) throws WxErrorException { public WxMaShopEcAfterSaleGetResponse get(WxMaShopEcAfterSaleGetRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(ECAFTERSALE_GET, request); String responseContent = this.wxMaService.post(ECAFTERSALE_GET, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopEcAfterSaleGetResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopEcAfterSaleGetResponse.class);
@ -89,7 +89,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
public WxMaShopBaseResponse update(WxMaShopAfterSaleUpdateRequest request) throws WxErrorException { public WxMaShopBaseResponse update(WxMaShopAfterSaleUpdateRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AFTERSALE_UPDATE, request); String responseContent = this.wxMaService.post(AFTERSALE_UPDATE, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
@ -99,7 +99,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
public WxMaShopBaseResponse update(WxMaShopEcAfterSaleUpdateRequest request) throws WxErrorException { public WxMaShopBaseResponse update(WxMaShopEcAfterSaleUpdateRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(EC_AFTERSALE_UPDATE, request); String responseContent = this.wxMaService.post(EC_AFTERSALE_UPDATE, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
@ -120,7 +120,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
"aftersale_id", afterSaleId, "openid", openId); "aftersale_id", afterSaleId, "openid", openId);
String resp = this.wxMaService.post(AFTERSALE_CANCEL, request); String resp = this.wxMaService.post(AFTERSALE_CANCEL, request);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
@ -137,7 +137,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
throws WxErrorException { throws WxErrorException {
String resp = this.wxMaService.post(AFTERSALE_UPLOAD_RETURN_INFO, request); String resp = this.wxMaService.post(AFTERSALE_UPLOAD_RETURN_INFO, request);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
@ -157,7 +157,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
"aftersale_id", afterSaleId); "aftersale_id", afterSaleId);
String resp = this.wxMaService.post(AFTERSALE_ACCEPT_REFUND, request); String resp = this.wxMaService.post(AFTERSALE_ACCEPT_REFUND, request);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
@ -174,7 +174,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
throws WxErrorException { throws WxErrorException {
String resp = this.wxMaService.post(AFTERSALE_ACCEPT_RETURN, request); String resp = this.wxMaService.post(AFTERSALE_ACCEPT_RETURN, request);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
@ -194,7 +194,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
"aftersale_id", afterSaleId); "aftersale_id", afterSaleId);
String resp = this.wxMaService.post(AFTERSALE_REJECT, request); String resp = this.wxMaService.post(AFTERSALE_REJECT, request);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
@ -211,7 +211,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
throws WxErrorException { throws WxErrorException {
String resp = this.wxMaService.post(AFTERSALE_UPLOAD_CERTIFICATES, request); String resp = this.wxMaService.post(AFTERSALE_UPLOAD_CERTIFICATES, request);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
@ -233,7 +233,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
"order_id", orderId, "openid", openid, "after_sale_deadline", afterSaleDeadline); "order_id", orderId, "openid", openid, "after_sale_deadline", afterSaleDeadline);
String resp = this.wxMaService.post(AFTERSALE_UPLOAD_DEADLINE, request); String resp = this.wxMaService.post(AFTERSALE_UPLOAD_DEADLINE, request);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(resp, WxMaShopBaseResponse.class);
@ -249,7 +249,7 @@ public class WxMaShopAfterSaleServiceImpl implements WxMaShopAfterSaleService {
public WxMaShopAfterSaleListResponse list(WxMaShopAfterSaleListRequest request) throws WxErrorException { public WxMaShopAfterSaleListResponse list(WxMaShopAfterSaleListRequest request) throws WxErrorException {
String resp = this.wxMaService.post(AFTERSALE_GET_LIST, request); String resp = this.wxMaService.post(AFTERSALE_GET_LIST, request);
JsonObject jsonObject = GsonParser.parse(resp); JsonObject jsonObject = GsonParser.parse(resp);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(resp, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(resp, WxMaShopAfterSaleListResponse.class); return WxMaGsonBuilder.create().fromJson(resp, WxMaShopAfterSaleListResponse.class);

View File

@ -18,7 +18,7 @@ import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser; 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.WxMaApiUrlConstants.Shop.Audit.*;
import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE; import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* 小程序交易组件-接入商品前必需接口(审核相关接口) * 小程序交易组件-接入商品前必需接口(审核相关接口)
@ -42,7 +42,7 @@ public class WxMaShopAuditServiceImpl implements WxMaShopAuditService {
public WxMaShopAuditBrandResponse auditBrand(WxMaShopAuditBrandRequest request) throws WxErrorException { public WxMaShopAuditBrandResponse auditBrand(WxMaShopAuditBrandRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AUDIT_BRAND, request); String responseContent = this.wxMaService.post(AUDIT_BRAND, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditBrandResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditBrandResponse.class);
@ -59,7 +59,7 @@ public class WxMaShopAuditServiceImpl implements WxMaShopAuditService {
public WxMaShopAuditCategoryResponse auditCategory(WxMaShopAuditCategoryRequest request) throws WxErrorException { public WxMaShopAuditCategoryResponse auditCategory(WxMaShopAuditCategoryRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(AUDIT_CATEGORY, request); String responseContent = this.wxMaService.post(AUDIT_CATEGORY, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditCategoryResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditCategoryResponse.class);
@ -76,7 +76,7 @@ public class WxMaShopAuditServiceImpl implements WxMaShopAuditService {
public WxMaShopAuditResultResponse getAuditResult(String auditId) throws WxErrorException { public WxMaShopAuditResultResponse getAuditResult(String auditId) throws WxErrorException {
String responseContent = this.wxMaService.post(AUDIT_RESULT, GsonHelper.buildJsonObject("audit_id", auditId)); String responseContent = this.wxMaService.post(AUDIT_RESULT, GsonHelper.buildJsonObject("audit_id", auditId));
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditResultResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopAuditResultResponse.class);
@ -93,7 +93,7 @@ public class WxMaShopAuditServiceImpl implements WxMaShopAuditService {
public JsonObject getMiniappCertificate(int reqType) throws WxErrorException { public JsonObject getMiniappCertificate(int reqType) throws WxErrorException {
String responseContent = this.wxMaService.post(GET_MINIAPP_CERTIFICATE, GsonHelper.buildJsonObject("req_type", reqType)); String responseContent = this.wxMaService.post(GET_MINIAPP_CERTIFICATE, GsonHelper.buildJsonObject("req_type", reqType));
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, JsonObject.class); return WxMaGsonBuilder.create().fromJson(responseContent, JsonObject.class);

View File

@ -13,7 +13,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser; 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.WxMaApiUrlConstants.Shop.Cat.GET_CAT;
import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE; import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* @author liming1019 * @author liming1019
@ -27,7 +27,7 @@ public class WxMaShopCatServiceImpl implements WxMaShopCatService {
public WxMaShopCatGetResponse getCat() throws WxErrorException { public WxMaShopCatGetResponse getCat() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_CAT, new JsonObject()); String responseContent = this.wxMaService.post(GET_CAT, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopCatGetResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopCatGetResponse.class);

View File

@ -1,6 +1,5 @@
package cn.binarywang.wx.miniapp.api.impl; package cn.binarywang.wx.miniapp.api.impl;
import static cn.binarywang.wx.miniapp.api.impl.WxMaImmediateDeliveryServiceImpl.ERR_CODE;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopCouponService; import cn.binarywang.wx.miniapp.api.WxMaShopCouponService;
@ -20,6 +19,8 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* @author leiin * @author leiin
* created on 2022/7/1 2:49 下午 * created on 2022/7/1 2:49 下午
@ -100,7 +101,7 @@ public class WxMaShopCouponServiceImpl implements WxMaShopCouponService {
@Override @Override
public WxMaShopBaseResponse addUserCoupon(String openid, String outUserCouponId, public WxMaShopBaseResponse addUserCoupon(String openid, String outUserCouponId,
String outCouponId, Integer status, Long recvTime) throws WxErrorException { String outCouponId, Integer status, Long recvTime) throws WxErrorException {
JsonObject userCoupon = GsonHelper.buildJsonObject("out_user_coupon_id", outUserCouponId, JsonObject userCoupon = GsonHelper.buildJsonObject("out_user_coupon_id", outUserCouponId,
"out_coupon_id", outCouponId, "out_coupon_id", outCouponId,
"status", status); "status", status);
@ -129,7 +130,7 @@ public class WxMaShopCouponServiceImpl implements WxMaShopCouponService {
@Override @Override
public WxMaShopBaseResponse updateUserCoupon(String openid, String outUserCouponId, public WxMaShopBaseResponse updateUserCoupon(String openid, String outUserCouponId,
String outCouponId, Long useTime, Long recvTime) throws WxErrorException { String outCouponId, Long useTime, Long recvTime) throws WxErrorException {
JsonObject extInfo = GsonHelper.buildJsonObject("use_time", useTime); JsonObject extInfo = GsonHelper.buildJsonObject("use_time", useTime);
JsonObject userCoupon = GsonHelper.buildJsonObject("out_user_coupon_id", outUserCouponId, JsonObject userCoupon = GsonHelper.buildJsonObject("out_user_coupon_id", outUserCouponId,
@ -148,7 +149,7 @@ public class WxMaShopCouponServiceImpl implements WxMaShopCouponService {
@Override @Override
public WxMaShopBaseResponse updateUserCouponStatus(String openid, String outUserCouponId, public WxMaShopBaseResponse updateUserCouponStatus(String openid, String outUserCouponId,
String outCouponId, Integer status) throws WxErrorException { String outCouponId, Integer status) throws WxErrorException {
JsonObject json = GsonHelper.buildJsonObject("openid", openid, JsonObject json = GsonHelper.buildJsonObject("openid", openid,
"out_user_coupon_id", outUserCouponId, "out_user_coupon_id", outUserCouponId,

View File

@ -16,7 +16,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Delivery.*; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Delivery.*;
import static cn.binarywang.wx.miniapp.constant.WxMaConstants.ERRCODE; import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* @author boris * @author boris
@ -37,7 +37,7 @@ public class WxMaShopDeliveryServiceImpl implements WxMaShopDeliveryService {
public WxMaShopDeliveryGetCompanyListResponse getCompanyList() throws WxErrorException { public WxMaShopDeliveryGetCompanyListResponse getCompanyList() throws WxErrorException {
String responseContent = this.wxMaService.post(GET_COMPANY_LIST, new JsonObject()); String responseContent = this.wxMaService.post(GET_COMPANY_LIST, new JsonObject());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopDeliveryGetCompanyListResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopDeliveryGetCompanyListResponse.class);
@ -54,7 +54,7 @@ public class WxMaShopDeliveryServiceImpl implements WxMaShopDeliveryService {
public WxMaShopBaseResponse send(WxMaShopDeliverySendRequest request) throws WxErrorException { public WxMaShopBaseResponse send(WxMaShopDeliverySendRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(DELIVERY_SEND, request); String responseContent = this.wxMaService.post(DELIVERY_SEND, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);
@ -71,7 +71,7 @@ public class WxMaShopDeliveryServiceImpl implements WxMaShopDeliveryService {
public WxMaShopBaseResponse receive(WxMaShopDeliveryRecieveRequest request) throws WxErrorException { public WxMaShopBaseResponse receive(WxMaShopDeliveryRecieveRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(DELIVERY_RECEIVE, request); String responseContent = this.wxMaService.post(DELIVERY_RECEIVE, request);
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERRCODE).getAsInt() != 0) { if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class); return WxMaGsonBuilder.create().fromJson(responseContent, WxMaShopBaseResponse.class);

View File

@ -20,6 +20,7 @@ import java.text.Format;
import java.util.Date; import java.util.Date;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.*; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Order.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* @author boris * @author boris
@ -30,7 +31,6 @@ public class WxMaShopOrderServiceImpl implements WxMaShopOrderService {
private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); private final Format dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
private static final String ERR_CODE = "errcode";
private static final String MATCH_KEY = "is_matched"; private static final String MATCH_KEY = "is_matched";
private final WxMaService wxMaService; private final WxMaService wxMaService;

View File

@ -1,6 +1,7 @@
package cn.binarywang.wx.miniapp.api.impl; package cn.binarywang.wx.miniapp.api.impl;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Sharer; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Sharer;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopSharerService; import cn.binarywang.wx.miniapp.api.WxMaShopSharerService;
@ -28,7 +29,6 @@ import me.chanjar.weixin.common.util.json.GsonParser;
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
public class WxMaShopSharerServiceImpl implements WxMaShopSharerService { public class WxMaShopSharerServiceImpl implements WxMaShopSharerService {
private static final String ERR_CODE = "errcode";
private final WxMaService wxMaService; private final WxMaService wxMaService;
@Override @Override

View File

@ -20,6 +20,7 @@ import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.*; import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
/** /**
* @author boris * @author boris
@ -27,8 +28,6 @@ import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Spu.*;
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
public class WxMaShopSpuServiceImpl implements WxMaShopSpuService { public class WxMaShopSpuServiceImpl implements WxMaShopSpuService {
private static final String ERR_CODE = "errcode";
private final WxMaService wxMaService; private final WxMaService wxMaService;
@Override @Override

View File

@ -3,6 +3,7 @@ package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaSubscribeService; import cn.binarywang.wx.miniapp.api.WxMaSubscribeService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.subscribemsg.CategoryData; import me.chanjar.weixin.common.bean.subscribemsg.CategoryData;
import me.chanjar.weixin.common.bean.subscribemsg.PubTemplateKeyword; import me.chanjar.weixin.common.bean.subscribemsg.PubTemplateKeyword;
import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo; import me.chanjar.weixin.common.bean.subscribemsg.TemplateInfo;
@ -85,7 +86,7 @@ public class WxMaSubscribeServiceImpl implements WxMaSubscribeService {
public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException { public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException {
String responseContent = this.service.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson()); String responseContent = this.service.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent); JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
} }
} }

View File

@ -1,5 +1,7 @@
package cn.binarywang.wx.miniapp.constant; package cn.binarywang.wx.miniapp.constant;
import lombok.experimental.UtilityClass;
/** /**
* <pre> * <pre>
* 小程序常量. * 小程序常量.
@ -7,24 +9,19 @@ package cn.binarywang.wx.miniapp.constant;
* *
* @author <a href="https://github.com/binarywang">Binary Wang</a> * @author <a href="https://github.com/binarywang">Binary Wang</a>
*/ */
public abstract class WxMaConstants { @UtilityClass
private WxMaConstants() { public class WxMaConstants {
}
/** /**
* 默认的env_version值 * 默认的env_version值
*/ */
public static final String DEFAULT_ENV_VERSION = "release"; public static final String DEFAULT_ENV_VERSION = "release";
/**
* 微信接口返回的参数errcode.
*/
public static final String ERRCODE = "errcode";
/** /**
* 素材类型. * 素材类型.
*/ */
public abstract static class MediaType { @UtilityClass
public static class MediaType {
/** /**
* 图片. * 图片.
*/ */
@ -34,7 +31,8 @@ public abstract class WxMaConstants {
/** /**
* 消息格式. * 消息格式.
*/ */
public abstract static class MsgDataFormat { @UtilityClass
public static class MsgDataFormat {
public static final String XML = "XML"; public static final String XML = "XML";
public static final String JSON = "JSON"; public static final String JSON = "JSON";
} }
@ -42,6 +40,7 @@ public abstract class WxMaConstants {
/** /**
* 客服消息的消息类型. * 客服消息的消息类型.
*/ */
@UtilityClass
public static class KefuMsgType { public static class KefuMsgType {
/** /**
* 文本消息. * 文本消息.
@ -64,8 +63,8 @@ public abstract class WxMaConstants {
/** /**
* 内容安全检测的媒体类型 * 内容安全检测的媒体类型
*/ */
@UtilityClass
public static final class SecCheckMediaType { public static final class SecCheckMediaType {
/** /**
* 音频 * 音频
*/ */
@ -80,6 +79,7 @@ public abstract class WxMaConstants {
/** /**
* 快递账号绑定类型 * 快递账号绑定类型
*/ */
@UtilityClass
public static final class BindAccountType { public static final class BindAccountType {
/** /**
@ -96,6 +96,7 @@ public abstract class WxMaConstants {
/** /**
* 快递下单订单来源 * 快递下单订单来源
*/ */
@UtilityClass
public static final class OrderAddSource { public static final class OrderAddSource {
/** /**
@ -112,11 +113,8 @@ public abstract class WxMaConstants {
/** /**
* 快递下单保价 * 快递下单保价
*/ */
@UtilityClass
public static final class OrderAddInsured { public static final class OrderAddInsured {
private OrderAddInsured() {
}
/** /**
* 不保价 * 不保价
*/ */
@ -138,10 +136,8 @@ public abstract class WxMaConstants {
* <p> * <p>
* developer为开发版trial为体验版formal为正式版默认为正式版 * developer为开发版trial为体验版formal为正式版默认为正式版
*/ */
@UtilityClass
public static final class MiniProgramState { public static final class MiniProgramState {
private MiniProgramState() {
}
/** /**
* 开发版 * 开发版
*/ */
@ -163,10 +159,8 @@ public abstract class WxMaConstants {
* 进入小程序查看的语言类型 * 进入小程序查看的语言类型
* 支持zh_CN(简体中文)en_US(英文)zh_HK(繁体中文)zh_TW(繁体中文)默认为zh_CN * 支持zh_CN(简体中文)en_US(英文)zh_HK(繁体中文)zh_TW(繁体中文)默认为zh_CN
*/ */
@UtilityClass
public static final class MiniProgramLang { public static final class MiniProgramLang {
private MiniProgramLang() {
}
/** /**
* 简体中文 * 简体中文
*/ */

View File

@ -161,7 +161,7 @@ public class WxMpCardServiceImpl implements WxMpCardService {
// 判断返回值 // 判断返回值
JsonObject json = GsonParser.parse(responseContent); JsonObject json = GsonParser.parse(responseContent);
String errcode = json.get("errcode").getAsString(); String errcode = json.get(WxConsts.ERR_CODE).getAsString();
if (!"0".equals(errcode)) { if (!"0".equals(errcode)) {
String errmsg = json.get("errmsg").getAsString(); String errmsg = json.get("errmsg").getAsString();
throw new WxErrorException(WxError.builder() throw new WxErrorException(WxError.builder()

View File

@ -1,6 +1,7 @@
package me.chanjar.weixin.mp.api.impl; package me.chanjar.weixin.mp.api.impl;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
@ -27,7 +28,6 @@ public class WxMpDraftServiceImpl implements WxMpDraftService {
private static final String MEDIA_ID = "media_id"; private static final String MEDIA_ID = "media_id";
private static final String ERRCODE_SUCCESS = "0"; private static final String ERRCODE_SUCCESS = "0";
private static final String ERRCODE = "errcode";
private final WxMpService mpService; private final WxMpService mpService;
@Override @Override
@ -49,7 +49,7 @@ public class WxMpDraftServiceImpl implements WxMpDraftService {
@Override @Override
public Boolean updateDraft(WxMpUpdateDraft updateDraftInfo) throws WxErrorException { public Boolean updateDraft(WxMpUpdateDraft updateDraftInfo) throws WxErrorException {
String json = this.mpService.post(WxMpApiUrl.Draft.UPDATE_DRAFT, updateDraftInfo); String json = this.mpService.post(WxMpApiUrl.Draft.UPDATE_DRAFT, updateDraftInfo);
return GsonParser.parse(json).get(ERRCODE).getAsString().equals(ERRCODE_SUCCESS); return GsonParser.parse(json).get(WxConsts.ERR_CODE).getAsString().equals(ERRCODE_SUCCESS);
} }
@Override @Override
@ -62,7 +62,7 @@ public class WxMpDraftServiceImpl implements WxMpDraftService {
public Boolean delDraft(String mediaId) throws WxErrorException { public Boolean delDraft(String mediaId) throws WxErrorException {
String json = this.mpService.post(WxMpApiUrl.Draft.DEL_DRAFT, String json = this.mpService.post(WxMpApiUrl.Draft.DEL_DRAFT,
GsonHelper.buildJsonObject(MEDIA_ID, mediaId)); GsonHelper.buildJsonObject(MEDIA_ID, mediaId));
return GsonParser.parse(json).get(ERRCODE).getAsString().equals(ERRCODE_SUCCESS); return GsonParser.parse(json).get(WxConsts.ERR_CODE).getAsString().equals(ERRCODE_SUCCESS);
} }
@Override @Override

View File

@ -1,6 +1,7 @@
package me.chanjar.weixin.mp.api.impl; package me.chanjar.weixin.mp.api.impl;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.common.util.json.GsonParser;
@ -24,7 +25,6 @@ public class WxMpFreePublishServiceImpl implements WxMpFreePublishService {
private static final String PUBLISH_ID = "publish_id"; private static final String PUBLISH_ID = "publish_id";
private static final String ARTICLE_ID = "article_id"; private static final String ARTICLE_ID = "article_id";
private static final String ERRCODE_SUCCESS = "0"; private static final String ERRCODE_SUCCESS = "0";
private static final String ERRCODE = "errcode";
private final WxMpService mpService; private final WxMpService mpService;
@Override @Override
@ -44,7 +44,7 @@ public class WxMpFreePublishServiceImpl implements WxMpFreePublishService {
public Boolean deletePush(String articleId, Integer index) throws WxErrorException { public Boolean deletePush(String articleId, Integer index) throws WxErrorException {
String json = this.mpService.post(WxMpApiUrl.FreePublish.DEL_PUSH, String json = this.mpService.post(WxMpApiUrl.FreePublish.DEL_PUSH,
GsonHelper.buildJsonObject(ARTICLE_ID, articleId, "index", index)); GsonHelper.buildJsonObject(ARTICLE_ID, articleId, "index", index));
return GsonParser.parse(json).get(ERRCODE).toString().equals(ERRCODE_SUCCESS); return GsonParser.parse(json).get(WxConsts.ERR_CODE).toString().equals(ERRCODE_SUCCESS);
} }
@Override @Override

View File

@ -34,7 +34,6 @@ import static me.chanjar.weixin.mp.enums.WxMpApiUrl.SubscribeMsg.*;
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxMpSubscribeMsgServiceImpl implements WxMpSubscribeMsgService { public class WxMpSubscribeMsgServiceImpl implements WxMpSubscribeMsgService {
private static final String ERR_CODE = "errcode";
private final WxMpService service; private final WxMpService service;
@Override @Override

View File

@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.enums.WxType; import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@ -25,15 +26,13 @@ import static me.chanjar.weixin.mp.enums.WxMpApiUrl.TemplateMsg.*;
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService { public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
private final WxMpService wxMpService; private final WxMpService wxMpService;
@Override @Override
public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException { public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException {
String responseContent = this.wxMpService.post(MESSAGE_TEMPLATE_SEND, templateMessage.toJson()); String responseContent = this.wxMpService.post(MESSAGE_TEMPLATE_SEND, templateMessage.toJson());
final JsonObject jsonObject = GsonParser.parse(responseContent); final JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get("errcode").getAsInt() == 0) { if (jsonObject.get(WxConsts.ERR_CODE).getAsInt() == 0) {
return jsonObject.get("msgid").getAsString(); return jsonObject.get("msgid").getAsString();
} }
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP)); throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
@ -62,7 +61,7 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
jsonObject.addProperty("template_id_short", shortTemplateId); jsonObject.addProperty("template_id_short", shortTemplateId);
String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString()); String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString());
final JsonObject result = GsonParser.parse(responseContent); final JsonObject result = GsonParser.parse(responseContent);
if (result.get("errcode").getAsInt() == 0) { if (result.get(WxConsts.ERR_CODE).getAsInt() == 0) {
return result.get("template_id").getAsString(); return result.get("template_id").getAsString();
} }

View File

@ -1,6 +1,7 @@
package me.chanjar.weixin.mp.util.json; package me.chanjar.weixin.mp.util.json;
import com.google.gson.*; import com.google.gson.*;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
@ -16,8 +17,8 @@ public class WxMpMassSendResultAdapter implements JsonDeserializer<WxMpMassSendR
WxMpMassSendResult sendResult = new WxMpMassSendResult(); WxMpMassSendResult sendResult = new WxMpMassSendResult();
JsonObject sendResultJsonObject = json.getAsJsonObject(); JsonObject sendResultJsonObject = json.getAsJsonObject();
if (sendResultJsonObject.get("errcode") != null && !sendResultJsonObject.get("errcode").isJsonNull()) { if (sendResultJsonObject.get(WxConsts.ERR_CODE) != null && !sendResultJsonObject.get(WxConsts.ERR_CODE).isJsonNull()) {
sendResult.setErrorCode(GsonHelper.getAsString(sendResultJsonObject.get("errcode"))); sendResult.setErrorCode(GsonHelper.getAsString(sendResultJsonObject.get(WxConsts.ERR_CODE)));
} }
if (sendResultJsonObject.get("errmsg") != null && !sendResultJsonObject.get("errmsg").isJsonNull()) { if (sendResultJsonObject.get("errmsg") != null && !sendResultJsonObject.get("errmsg").isJsonNull()) {
sendResult.setErrorMsg(GsonHelper.getAsString(sendResultJsonObject.get("errmsg"))); sendResult.setErrorMsg(GsonHelper.getAsString(sendResultJsonObject.get("errmsg")));

View File

@ -22,7 +22,7 @@ public class WxMpMemberCardActivateTempInfoResultGsonAdapter implements JsonDese
JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonObject jsonObject = jsonElement.getAsJsonObject();
result.setErrorCode(GsonHelper.getString(jsonObject, "errcode")); result.setErrorCode(GsonHelper.getString(jsonObject, WxConsts.ERR_CODE));
result.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg")); result.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg"));
JsonObject userInfoJsonObject = jsonObject.getAsJsonObject("info"); JsonObject userInfoJsonObject = jsonObject.getAsJsonObject("info");

View File

@ -27,7 +27,7 @@ public class WxMpMemberCardUpdateResultGsonAdapter implements JsonDeserializer<W
JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonObject jsonObject = jsonElement.getAsJsonObject();
result.setOpenId(GsonHelper.getString(jsonObject, "openid")); result.setOpenId(GsonHelper.getString(jsonObject, "openid"));
result.setErrorCode(GsonHelper.getString(jsonObject, "errcode")); result.setErrorCode(GsonHelper.getString(jsonObject, WxConsts.ERR_CODE));
result.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg")); result.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg"));
result.setResultBalance(GsonHelper.getDouble(jsonObject, "result_balance")); result.setResultBalance(GsonHelper.getDouble(jsonObject, "result_balance"));
result.setResultBonus(GsonHelper.getInteger(jsonObject, "result_bonus")); result.setResultBonus(GsonHelper.getInteger(jsonObject, "result_bonus"));

View File

@ -31,7 +31,7 @@ public class WxMpMemberCardUserInfoResultGsonAdapter implements JsonDeserializer
JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonObject jsonObject = jsonElement.getAsJsonObject();
result.setOpenId(getString(jsonObject, "openid")); result.setOpenId(getString(jsonObject, "openid"));
result.setErrorCode(getString(jsonObject, "errcode")); result.setErrorCode(getString(jsonObject, WxConsts.ERR_CODE));
result.setErrorMsg(getString(jsonObject, "errmsg")); result.setErrorMsg(getString(jsonObject, "errmsg"));
result.setNickname(getString(jsonObject, "nickname")); result.setNickname(getString(jsonObject, "nickname"));
result.setMembershipNumber(getString(jsonObject, "membership_number")); result.setMembershipNumber(getString(jsonObject, "membership_number"));

View File

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

View File

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

View File

@ -1,14 +1,12 @@
package me.chanjar.weixin.open.api.impl; package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.api.WxOpenMinishopGoodsService; import me.chanjar.weixin.open.api.WxOpenMinishopGoodsService;
import me.chanjar.weixin.open.bean.minishopGoods.AddMinishopGoodsSPU; import me.chanjar.weixin.open.bean.minishopgoods.AddMinishopGoodsSPU;
import me.chanjar.weixin.open.bean.minishopGoods.GoodsCatList; import me.chanjar.weixin.open.bean.minishopgoods.GoodsCatList;
import me.chanjar.weixin.open.bean.minishopGoods.ParentCatId; import me.chanjar.weixin.open.bean.minishopgoods.ParentCatId;
import me.chanjar.weixin.open.bean.result.WxOpenResult; import me.chanjar.weixin.open.bean.result.WxOpenResult;
@Slf4j @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.Gson;
import com.google.gson.JsonObject; 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 com.google.gson.JsonObject;
import lombok.Data; 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 com.google.gson.JsonObject;
import lombok.Data; 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.Gson;
import com.google.gson.JsonObject; 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 com.google.gson.JsonObject;
import lombok.Data; 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 com.google.gson.JsonObject;
import lombok.Data; 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.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import me.chanjar.weixin.common.api.WxConsts;
import java.util.List; import java.util.List;
/**
* @author kelvenlaw
*/
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class GoodsCatList { public class GoodsCatList {
@ -26,7 +30,7 @@ public class GoodsCatList {
public JsonObject toJsonObject() { public JsonObject toJsonObject() {
Gson gson = new Gson(); Gson gson = new Gson();
JsonObject jsonObject = new JsonObject(); JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("errcode", errcode); jsonObject.addProperty(WxConsts.ERR_CODE, errcode);
jsonObject.addProperty("errmsg", errmsg); jsonObject.addProperty("errmsg", errmsg);
jsonObject.addProperty("cat_list", gson.toJson(catList)); jsonObject.addProperty("cat_list", gson.toJson(catList));
return jsonObject; 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 com.google.gson.JsonObject;
import lombok.Data; 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.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.util.Arrays;
import java.util.List; import java.util.List;
@Data @Data