me.chanjar.weixin.common.error.WxError.fromJson()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中me.chanjar.weixin.common.error.WxError.fromJson()方法的一些代码示例,展示了WxError.fromJson()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WxError.fromJson()方法的具体详情如下:
包路径:me.chanjar.weixin.common.error.WxError
类名称:WxError
方法名:fromJson

WxError.fromJson介绍

暂无

代码示例

代码示例来源:origin: binarywang/WxJava

@Override
public String addTemplate(String shortTemplateId) throws WxErrorException {
 String url = API_URL_PREFIX + "/api_add_template";
 JsonObject jsonObject = new JsonObject();
 jsonObject.addProperty("template_id_short", shortTemplateId);
 String responseContent = this.wxMpService.post(url, jsonObject.toString());
 final JsonObject result = JSON_PARSER.parse(responseContent).getAsJsonObject();
 if (result.get("errcode").getAsInt() == 0) {
  return result.get("template_id").getAsString();
 }
 throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}

代码示例来源:origin: com.github.binarywang/weixin-java-mp

@Override
public WxMpStoreBaseInfo get(String poiId) throws WxErrorException {
 JsonObject paramObject = new JsonObject();
 paramObject.addProperty("poi_id", poiId);
 String response = this.wxMpService.post(POI_GET_URL, paramObject.toString());
 WxError wxError = WxError.fromJson(response, WxType.MP);
 if (wxError.getErrorCode() != 0) {
  throw new WxErrorException(wxError);
 }
 return WxMpStoreBaseInfo.fromJson(new JsonParser().parse(response).getAsJsonObject()
  .get("business").getAsJsonObject().get("base_info").toString());
}

代码示例来源:origin: binarywang/WxJava

@Override
public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException {
 String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
 String responseContent = this.wxMpService.post(url, templateMessage.toJson());
 final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
 if (jsonObject.get("errcode").getAsInt() == 0) {
  return jsonObject.get("msgid").getAsString();
 }
 throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}

代码示例来源:origin: com.github.binarywang/weixin-java-mp

@Override
public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException {
 final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()),
  content);
 final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
 if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) {
  return jsonObject.get("to_content").getAsString();
 }
 throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}

代码示例来源:origin: binarywang/WxJava

@Override
public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException {
 final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()),
  content);
 final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
 if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) {
  return jsonObject.get("to_content").getAsString();
 }
 throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}

代码示例来源:origin: com.github.binarywang/weixin-java-miniapp

@Override
public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException {
 String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson());
 JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
 if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
  throw new WxErrorException(WxError.fromJson(responseContent));
 }
}

代码示例来源:origin: binarywang/WxJava

@Override
public void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException {
 String responseContent = this.wxMaService.post(UNIFORM_MSG_SEND_URL, uniformMessage.toJson());
 JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
 if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
  throw new WxErrorException(WxError.fromJson(responseContent));
 }
}

代码示例来源:origin: binarywang/WxJava

@Override
public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException {
 String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson());
 JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
 if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
  throw new WxErrorException(WxError.fromJson(responseContent));
 }
}

代码示例来源:origin: com.github.binarywang/weixin-java-mp

@Override
public void delete(String poiId) throws WxErrorException {
 JsonObject paramObject = new JsonObject();
 paramObject.addProperty("poi_id", poiId);
 String response = this.wxMpService.post(POI_DEL_URL, paramObject.toString());
 WxError wxError = WxError.fromJson(response, WxType.MP);
 if (wxError.getErrorCode() != 0) {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: com.github.binarywang/weixin-java-mp

@Override
public WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) throws WxErrorException {
 String url = "https://api.weixin.qq.com/shakearound/device/bindpage";
 String postData = shakeAroundDeviceBindPageQuery.toJsonString();
 String responseContent = this.wxMpService.post(url, postData);
 return WxError.fromJson(responseContent, WxType.MP);
}

代码示例来源:origin: com.github.binarywang/weixin-java-mp

@Override
public List<String> listCategories() throws WxErrorException {
 String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null);
 WxError wxError = WxError.fromJson(response, WxType.MP);
 if (wxError.getErrorCode() != 0) {
  throw new WxErrorException(wxError);
 }
 return WxMpGsonBuilder.create().fromJson(
  new JsonParser().parse(response).getAsJsonObject().get("category_list"),
  new TypeToken<List<String>>() {
  }.getType());
}

代码示例来源:origin: binarywang/WxJava

@Override
public List<String> listCategories() throws WxErrorException {
 String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null);
 WxError wxError = WxError.fromJson(response, WxType.MP);
 if (wxError.getErrorCode() != 0) {
  throw new WxErrorException(wxError);
 }
 return WxMpGsonBuilder.create().fromJson(
  new JsonParser().parse(response).getAsJsonObject().get("category_list"),
  new TypeToken<List<String>>() {
  }.getType());
}

代码示例来源:origin: com.github.binarywang/weixin-java-miniapp

@Override
public WxMaTemplateLibraryGetResult findTemplateLibraryKeywordList(String id) throws WxErrorException {
 Map<String, String> params = new HashMap<>();
 params.put("id", id);
 String responseText = this.wxMaService.post(TEMPLATE_LIBRARY_KEYWORD_URL, WxGsonBuilder.create().toJson(params));
 WxError wxError = WxError.fromJson(responseText);
 if (wxError.getErrorCode() == 0) {
  return WxMaTemplateLibraryGetResult.fromJson(responseText);
 } else {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: binarywang/WxJava

@Override
public WxMaTemplateLibraryGetResult findTemplateLibraryKeywordList(String id) throws WxErrorException {
 Map<String, String> params = new HashMap<>();
 params.put("id", id);
 String responseText = this.wxMaService.post(TEMPLATE_LIBRARY_KEYWORD_URL, WxGsonBuilder.create().toJson(params));
 WxError wxError = WxError.fromJson(responseText);
 if (wxError.getErrorCode() == 0) {
  return WxMaTemplateLibraryGetResult.fromJson(responseText);
 } else {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: com.github.binarywang/weixin-java-mp

@Override
public WxMpMaterialCountResult materialCount() throws WxErrorException {
 String responseText = this.wxMpService.get(MATERIAL_GET_COUNT_URL, null);
 WxError wxError = WxError.fromJson(responseText, WxType.MP);
 if (wxError.getErrorCode() == 0) {
  return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialCountResult.class);
 } else {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: binarywang/WxJava

@Override
public WxMpMaterialCountResult materialCount() throws WxErrorException {
 String responseText = this.wxMpService.get(MATERIAL_GET_COUNT_URL, null);
 WxError wxError = WxError.fromJson(responseText, WxType.MP);
 if (wxError.getErrorCode() == 0) {
  return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialCountResult.class);
 } else {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: com.github.binarywang/weixin-java-mp

@Override
public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException {
 String responseText = this.wxMpService.post(NEWS_UPDATE_URL, wxMpMaterialArticleUpdate.toJson());
 WxError wxError = WxError.fromJson(responseText, WxType.MP);
 if (wxError.getErrorCode() == 0) {
  return true;
 } else {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: com.github.binarywang/weixin-java-mp

@Override
public void update(WxMpStoreBaseInfo request) throws WxErrorException {
 String response = this.wxMpService.post(POI_UPDATE_URL, request.toJson());
 WxError wxError = WxError.fromJson(response, WxType.MP);
 if (wxError.getErrorCode() != 0) {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: binarywang/WxJava

@Override
public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException {
 String responseText = this.wxMpService.post(NEWS_UPDATE_URL, wxMpMaterialArticleUpdate.toJson());
 WxError wxError = WxError.fromJson(responseText, WxType.MP);
 if (wxError.getErrorCode() == 0) {
  return true;
 } else {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: com.github.binarywang/weixin-java-mp

@Override
public void add(WxMpStoreBaseInfo request) throws WxErrorException {
 BeanUtils.checkRequiredFields(request);
 String response = this.wxMpService.post(POI_ADD_URL, request.toJson());
 WxError wxError = WxError.fromJson(response, WxType.MP);
 if (wxError.getErrorCode() != 0) {
  throw new WxErrorException(wxError);
 }
}

相关文章