gpt4 book ai didi

me.chanjar.weixin.common.exception.WxErrorException类的使用及代码示例

转载 作者:知者 更新时间:2024-03-21 07:03:05 29 4
gpt4 key购买 nike

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

WxErrorException介绍

暂无

代码示例

代码示例来源:origin: chanjarster/weixin-java-tools

return executeInternal(executor, uri, data);
} catch (WxErrorException e) {
 WxError error = e.getError();

代码示例来源:origin: chanjarster/weixin-java-tools

public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
 String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
 String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
 JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
 final JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
 if (jsonObject.get("errcode").getAsInt() == 0)
  return jsonObject.get("msgid").getAsString();
 throw new WxErrorException(WxError.fromJson(responseContent));
}

代码示例来源:origin: chanjarster/weixin-java-tools

return executor.execute(getHttpclient(), httpProxy, uriWithAccessToken, data);
} catch (WxErrorException e) {
 WxError error = e.getError();
  throw new WxErrorException(error);

代码示例来源:origin: aillamsun/genesis

/**
 * @param @param  longUrl
 * @param @return
 * @param @throws WxErrorException    参数
 * @return String    返回类型
 * @throws
 * @Title: getShortUrl
 * @Description: TODO 获取短链接
 */
public static String getShortUrl(String longUrl) {
  try {
    return WxMpServiceFactory.getWxMpService().shortUrl(longUrl);
  } catch (WxErrorException e) {
    e.printStackTrace();
    return "";
  }
}

代码示例来源:origin: yjjdick/sdb-mall

this.logger.error(e.getMessage(), e);
return R.error(e.toString());

代码示例来源:origin: chanjarster/weixin-java-tools

return executor.execute(getHttpclient(), httpProxy, uriWithAccessToken, data);
} catch (WxErrorException e) {
 WxError error = e.getError();
  throw new WxErrorException(error);

代码示例来源:origin: yjjdick/sdb-mall

@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                Map<String, Object> context, WxMpService weixinService,
                WxSessionManager sessionManager) {
  if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
    //TODO 可以选择将消息保存到本地
  }
  //当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
  try {
    if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
      && weixinService.getKefuService().kfOnlineList()
      .getKfOnlineList().size() > 0) {
      return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE()
        .fromUser(wxMessage.getToUser())
        .toUser(wxMessage.getFromUser()).build();
    }
  } catch (WxErrorException e) {
    e.printStackTrace();
  }
  //TODO 组装回复消息
  String content = "收到信息内容:" + JsonUtils.toJson(wxMessage);
  return new TextBuilder().build(content, wxMessage, weixinService);
}

代码示例来源:origin: chanjarster/weixin-java-tools

public WxMpMaterialFileBatchGetResult materialFileBatchGet(String type, int offset, int count) throws WxErrorException {
 String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material";
 Map<String, Object> params = new HashMap<>();
 params.put("type", type);
 params.put("offset", offset);
 params.put("count", count);
 String responseText = post(url, WxGsonBuilder.create().toJson(params));
 WxError wxError = WxError.fromJson(responseText);
 if (wxError.getErrorCode() == 0) {
  return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialFileBatchGetResult.class);
 } else {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: chanjarster/weixin-java-tools

return executeInternal(executor, uri, data);
} catch (WxErrorException e) {
 WxError error = e.getError();

代码示例来源:origin: me.chanjar/weixin-java-mp

return executor.execute(getHttpclient(), httpProxy, uriWithAccessToken, data);
} catch (WxErrorException e) {
 WxError error = e.getError();
  throw new WxErrorException(error);

代码示例来源:origin: chanjarster/weixin-java-tools

public WxMpMaterialNewsBatchGetResult materialNewsBatchGet(int offset, int count) throws WxErrorException {
 String url = "https://api.weixin.qq.com/cgi-bin/material/batchget_material";
 Map<String, Object> params = new HashMap<>();
 params.put("type", WxConsts.MATERIAL_NEWS);
 params.put("offset", offset);
 params.put("count", count);
 String responseText = post(url, WxGsonBuilder.create().toJson(params));
 WxError wxError = WxError.fromJson(responseText);
 if (wxError.getErrorCode() == 0) {
  return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialNewsBatchGetResult.class);
 } else {
  throw new WxErrorException(wxError);
 }
}

代码示例来源:origin: chanjarster/weixin-java-tools

public WxMenu menuTryMatch(String userid) throws WxErrorException {
 String url = "https://api.weixin.qq.com/cgi-bin/menu/trymatch";
 try {
  String resultContent = execute(new SimpleGetRequestExecutor(), url, "user_id=" + userid);
  return WxMenu.fromJson(resultContent);
 } catch (WxErrorException e) {
  // 46003 不存在的菜单数据     46002 不存在的菜单版本
  if (e.getError().getErrorCode() == 46003 || e.getError().getErrorCode() == 46002) {
   return null;
  }
  throw e;
 }
}

代码示例来源:origin: chanjarster/weixin-java-tools

public Boolean execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, ClientProtocolException, IOException {
 HttpPost httpPost = new HttpPost(uri);
 if (httpProxy != null) {
  RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
  httpPost.setConfig(config);
 }
 Map<String, String> params = new HashMap<>();
 params.put("media_id", materialId);
 httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
 CloseableHttpResponse response = httpclient.execute(httpPost);
 String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
 WxError error = WxError.fromJson(responseContent);
 if (error.getErrorCode() != 0) {
  throw new WxErrorException(error);
 } else {
  return true;
 }
}

代码示例来源:origin: chanjarster/weixin-java-tools

@Override
public WxMenu menuGet(String agentId) throws WxErrorException {
 String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + agentId;
 try {
  String resultContent = get(url, null);
  return WxMenu.fromJson(resultContent);
 } catch (WxErrorException e) {
  // 46003 不存在的菜单数据
  if (e.getError().getErrorCode() == 46003) {
   return null;
  }
  throw e;
 }
}

代码示例来源:origin: chanjarster/weixin-java-tools

public InputStream execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, ClientProtocolException, IOException {
 HttpPost httpPost = new HttpPost(uri);
 if (httpProxy != null) {
  RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
  httpPost.setConfig(config);
 }
 Map<String, String> params = new HashMap<>();
 params.put("media_id", materialId);
 httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
 CloseableHttpResponse response = httpclient.execute(httpPost);
 // 下载媒体文件出错
 InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
 byte[] responseContent = IOUtils.toByteArray(inputStream);
 String responseContentString = new String(responseContent, "UTF-8");
 if (responseContentString.length() < 100) {
  try {
   WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
   if (wxError.getErrorCode() != 0) {
    throw new WxErrorException(wxError);
   }
  } catch (com.google.gson.JsonSyntaxException ex) {
   return new ByteArrayInputStream(responseContent);
  }
 }
 return new ByteArrayInputStream(responseContent);
}

代码示例来源:origin: chanjarster/weixin-java-tools

public WxMenu menuGet() throws WxErrorException {
 String url = "https://api.weixin.qq.com/cgi-bin/menu/get";
 try {
  String resultContent = execute(new SimpleGetRequestExecutor(), url, null);
  return WxMenu.fromJson(resultContent);
 } catch (WxErrorException e) {
  // 46003 不存在的菜单数据
  if (e.getError().getErrorCode() == 46003) {
   return null;
  }
  throw e;
 }
}

代码示例来源:origin: chanjarster/weixin-java-tools

public WxMpMaterialNews execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, ClientProtocolException, IOException {
 HttpPost httpPost = new HttpPost(uri);
 if (httpProxy != null) {
  RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
  httpPost.setConfig(config);
 }
 Map<String, String> params = new HashMap<>();
 params.put("media_id", materialId);
 httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
 CloseableHttpResponse response = httpclient.execute(httpPost);
 String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
 WxError error = WxError.fromJson(responseContent);
 if (error.getErrorCode() != 0) {
  throw new WxErrorException(error);
 } else {
  return WxMpGsonBuilder.create().fromJson(responseContent, WxMpMaterialNews.class);
 }
}

代码示例来源:origin: me.chanjar/weixin-java-mp

return executeInternal(executor, uri, data);
} catch (WxErrorException e) {
 WxError error = e.getError();

代码示例来源:origin: chanjarster/weixin-java-tools

public WxMpMaterialVideoInfoResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, ClientProtocolException, IOException {
 HttpPost httpPost = new HttpPost(uri);
 if (httpProxy != null) {
  RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
  httpPost.setConfig(config);
 }
 Map<String, String> params = new HashMap<>();
 params.put("media_id", materialId);
 httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
 CloseableHttpResponse response = httpclient.execute(httpPost);
 String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
 WxError error = WxError.fromJson(responseContent);
 if (error.getErrorCode() != 0) {
  throw new WxErrorException(error);
 } else {
  return WxMpMaterialVideoInfoResult.fromJson(responseContent);
 }
}

代码示例来源:origin: me.chanjar/weixin-java-mp

public WxMenu menuTryMatch(String userid) throws WxErrorException {
 String url = "https://api.weixin.qq.com/cgi-bin/menu/trymatch";
 try {
  String resultContent = execute(new SimpleGetRequestExecutor(), url, "user_id=" + userid);
  return WxMenu.fromJson(resultContent);
 } catch (WxErrorException e) {
  // 46003 不存在的菜单数据     46002 不存在的菜单版本
  if (e.getError().getErrorCode() == 46003 || e.getError().getErrorCode() == 46002) {
   return null;
  }
  throw e;
 }
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com