mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🎨 统一抽取errcode常量,同步优化规范部分代码
This commit is contained in:
@@ -161,7 +161,7 @@ public class WxMpCardServiceImpl implements WxMpCardService {
|
||||
|
||||
// 判断返回值
|
||||
JsonObject json = GsonParser.parse(responseContent);
|
||||
String errcode = json.get("errcode").getAsString();
|
||||
String errcode = json.get(WxConsts.ERR_CODE).getAsString();
|
||||
if (!"0".equals(errcode)) {
|
||||
String errmsg = json.get("errmsg").getAsString();
|
||||
throw new WxErrorException(WxError.builder()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
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 ERRCODE_SUCCESS = "0";
|
||||
private static final String ERRCODE = "errcode";
|
||||
private final WxMpService mpService;
|
||||
|
||||
@Override
|
||||
@@ -49,7 +49,7 @@ public class WxMpDraftServiceImpl implements WxMpDraftService {
|
||||
@Override
|
||||
public Boolean updateDraft(WxMpUpdateDraft updateDraftInfo) throws WxErrorException {
|
||||
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
|
||||
@@ -62,7 +62,7 @@ public class WxMpDraftServiceImpl implements WxMpDraftService {
|
||||
public Boolean delDraft(String mediaId) throws WxErrorException {
|
||||
String json = this.mpService.post(WxMpApiUrl.Draft.DEL_DRAFT,
|
||||
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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
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 ARTICLE_ID = "article_id";
|
||||
private static final String ERRCODE_SUCCESS = "0";
|
||||
private static final String ERRCODE = "errcode";
|
||||
private final WxMpService mpService;
|
||||
|
||||
@Override
|
||||
@@ -44,7 +44,7 @@ public class WxMpFreePublishServiceImpl implements WxMpFreePublishService {
|
||||
public Boolean deletePush(String articleId, Integer index) throws WxErrorException {
|
||||
String json = this.mpService.post(WxMpApiUrl.FreePublish.DEL_PUSH,
|
||||
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
|
||||
|
||||
@@ -34,7 +34,6 @@ import static me.chanjar.weixin.mp.enums.WxMpApiUrl.SubscribeMsg.*;
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class WxMpSubscribeMsgServiceImpl implements WxMpSubscribeMsgService {
|
||||
private static final String ERR_CODE = "errcode";
|
||||
private final WxMpService service;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.enums.WxType;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
@@ -25,15 +26,13 @@ import static me.chanjar.weixin.mp.enums.WxMpApiUrl.TemplateMsg.*;
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
|
||||
|
||||
|
||||
private final WxMpService wxMpService;
|
||||
|
||||
@Override
|
||||
public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException {
|
||||
String responseContent = this.wxMpService.post(MESSAGE_TEMPLATE_SEND, templateMessage.toJson());
|
||||
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();
|
||||
}
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
|
||||
@@ -62,7 +61,7 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
|
||||
jsonObject.addProperty("template_id_short", shortTemplateId);
|
||||
String responseContent = this.wxMpService.post(TEMPLATE_API_ADD_TEMPLATE, jsonObject.toString());
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user