gpt4 book ai didi

me.chanjar.weixin.common.exception.WxErrorException.()方法的使用及代码示例

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

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

WxErrorException.<init>介绍

暂无

代码示例

代码示例来源: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

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

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 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

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 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: 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: chanjarster/weixin-java-tools

@Override
public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String postEntity) throws WxErrorException, ClientProtocolException, IOException {
 HttpPost httpPost = new HttpPost(uri);
 if (httpProxy != null) {
  RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
  httpPost.setConfig(config);
 }
 if (postEntity != null) {
  StringEntity entity = new StringEntity(postEntity, Consts.UTF_8);
  httpPost.setEntity(entity);
 }
 try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
  String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
  WxError error = WxError.fromJson(responseContent);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  }
  return responseContent;
 }
}

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

@Override
public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String queryParam) throws WxErrorException, ClientProtocolException, IOException {
 if (queryParam != null) {
  if (uri.indexOf('?') == -1) {
   uri += '?';
  }
  uri += uri.endsWith("?") ? queryParam : '&' + queryParam;
 }
 HttpGet httpGet = new HttpGet(uri);
 if (httpProxy != null) {
  RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
  httpGet.setConfig(config);
 }
 try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
  String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
  WxError error = WxError.fromJson(responseContent);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  }
  return responseContent;
 }
}

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

public WxMpMaterialCountResult materialCount() throws WxErrorException {
 String url = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount";
 String responseText = get(url, null);
 WxError wxError = WxError.fromJson(responseText);
 if (wxError.getErrorCode() == 0) {
  return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialCountResult.class);
 } else {
  throw new WxErrorException(wxError);
 }
}

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

WxError error = new WxError();
error.setErrorCode(-1);
throw new WxErrorException(error);

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

throw new WxErrorException(WxError.fromJson(responseContent));

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

@Override
public WxMediaUploadResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, File file) throws WxErrorException, ClientProtocolException, IOException {
 HttpPost httpPost = new HttpPost(uri);
 if (httpProxy != null) {
  RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
  httpPost.setConfig(config);
 }
 if (file != null) {
  HttpEntity entity = MultipartEntityBuilder
     .create()
     .addBinaryBody("media", file)
     .setMode(HttpMultipartMode.RFC6532)
     .build();
  httpPost.setEntity(entity);
  httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
 }
 try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
  String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
  WxError error = WxError.fromJson(responseContent);
  if (error.getErrorCode() != 0) {
   throw new WxErrorException(error);
  }
  return WxMediaUploadResult.fromJson(responseContent);
 }
}

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

public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException {
 String url = "https://api.weixin.qq.com/cgi-bin/material/update_news";
 String responseText = post(url, wxMpMaterialArticleUpdate.toJson());
 WxError wxError = WxError.fromJson(responseText);
 if (wxError.getErrorCode() == 0) {
  return true;
 } else {
  throw new WxErrorException(wxError);
 }
}

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

throw new WxErrorException(WxError.fromJson(responseContent));

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

WxError error = WxError.fromJson(responseContent);
if (error.getErrorCode() != 0) {
 throw new WxErrorException(error);
} else {
 return WxMpMaterialUploadResult.fromJson(responseContent);

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

throw new WxErrorException(error);

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

throw new WxErrorException(error);

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

WxError error = WxError.fromJson(resultContent);
if (error.getErrorCode() != 0) {
 throw new WxErrorException(error);

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

throw new WxErrorException(error);

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