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

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

本文整理了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

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

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

  1. @Override
  2. public WxMpStoreBaseInfo get(String poiId) throws WxErrorException {
  3. JsonObject paramObject = new JsonObject();
  4. paramObject.addProperty("poi_id", poiId);
  5. String response = this.wxMpService.post(POI_GET_URL, paramObject.toString());
  6. WxError wxError = WxError.fromJson(response, WxType.MP);
  7. if (wxError.getErrorCode() != 0) {
  8. throw new WxErrorException(wxError);
  9. }
  10. return WxMpStoreBaseInfo.fromJson(new JsonParser().parse(response).getAsJsonObject()
  11. .get("business").getAsJsonObject().get("base_info").toString());
  12. }

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. @Override
  2. public void delete(String poiId) throws WxErrorException {
  3. JsonObject paramObject = new JsonObject();
  4. paramObject.addProperty("poi_id", poiId);
  5. String response = this.wxMpService.post(POI_DEL_URL, paramObject.toString());
  6. WxError wxError = WxError.fromJson(response, WxType.MP);
  7. if (wxError.getErrorCode() != 0) {
  8. throw new WxErrorException(wxError);
  9. }
  10. }

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

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

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

  1. @Override
  2. public List<String> listCategories() throws WxErrorException {
  3. String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null);
  4. WxError wxError = WxError.fromJson(response, WxType.MP);
  5. if (wxError.getErrorCode() != 0) {
  6. throw new WxErrorException(wxError);
  7. }
  8. return WxMpGsonBuilder.create().fromJson(
  9. new JsonParser().parse(response).getAsJsonObject().get("category_list"),
  10. new TypeToken<List<String>>() {
  11. }.getType());
  12. }

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

  1. @Override
  2. public List<String> listCategories() throws WxErrorException {
  3. String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null);
  4. WxError wxError = WxError.fromJson(response, WxType.MP);
  5. if (wxError.getErrorCode() != 0) {
  6. throw new WxErrorException(wxError);
  7. }
  8. return WxMpGsonBuilder.create().fromJson(
  9. new JsonParser().parse(response).getAsJsonObject().get("category_list"),
  10. new TypeToken<List<String>>() {
  11. }.getType());
  12. }

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

  1. @Override
  2. public WxMaTemplateLibraryGetResult findTemplateLibraryKeywordList(String id) throws WxErrorException {
  3. Map<String, String> params = new HashMap<>();
  4. params.put("id", id);
  5. String responseText = this.wxMaService.post(TEMPLATE_LIBRARY_KEYWORD_URL, WxGsonBuilder.create().toJson(params));
  6. WxError wxError = WxError.fromJson(responseText);
  7. if (wxError.getErrorCode() == 0) {
  8. return WxMaTemplateLibraryGetResult.fromJson(responseText);
  9. } else {
  10. throw new WxErrorException(wxError);
  11. }
  12. }

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

  1. @Override
  2. public WxMaTemplateLibraryGetResult findTemplateLibraryKeywordList(String id) throws WxErrorException {
  3. Map<String, String> params = new HashMap<>();
  4. params.put("id", id);
  5. String responseText = this.wxMaService.post(TEMPLATE_LIBRARY_KEYWORD_URL, WxGsonBuilder.create().toJson(params));
  6. WxError wxError = WxError.fromJson(responseText);
  7. if (wxError.getErrorCode() == 0) {
  8. return WxMaTemplateLibraryGetResult.fromJson(responseText);
  9. } else {
  10. throw new WxErrorException(wxError);
  11. }
  12. }

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

  1. @Override
  2. public WxMpMaterialCountResult materialCount() throws WxErrorException {
  3. String responseText = this.wxMpService.get(MATERIAL_GET_COUNT_URL, null);
  4. WxError wxError = WxError.fromJson(responseText, WxType.MP);
  5. if (wxError.getErrorCode() == 0) {
  6. return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialCountResult.class);
  7. } else {
  8. throw new WxErrorException(wxError);
  9. }
  10. }

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

  1. @Override
  2. public WxMpMaterialCountResult materialCount() throws WxErrorException {
  3. String responseText = this.wxMpService.get(MATERIAL_GET_COUNT_URL, null);
  4. WxError wxError = WxError.fromJson(responseText, WxType.MP);
  5. if (wxError.getErrorCode() == 0) {
  6. return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialCountResult.class);
  7. } else {
  8. throw new WxErrorException(wxError);
  9. }
  10. }

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

  1. @Override
  2. public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException {
  3. String responseText = this.wxMpService.post(NEWS_UPDATE_URL, wxMpMaterialArticleUpdate.toJson());
  4. WxError wxError = WxError.fromJson(responseText, WxType.MP);
  5. if (wxError.getErrorCode() == 0) {
  6. return true;
  7. } else {
  8. throw new WxErrorException(wxError);
  9. }
  10. }

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

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

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

  1. @Override
  2. public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException {
  3. String responseText = this.wxMpService.post(NEWS_UPDATE_URL, wxMpMaterialArticleUpdate.toJson());
  4. WxError wxError = WxError.fromJson(responseText, WxType.MP);
  5. if (wxError.getErrorCode() == 0) {
  6. return true;
  7. } else {
  8. throw new WxErrorException(wxError);
  9. }
  10. }

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

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

相关文章