當前位置: 首頁>>代碼示例>>Java>>正文


Java Utf8ResponseHandler類代碼示例

本文整理匯總了Java中me.chanjar.weixin.common.util.http.Utf8ResponseHandler的典型用法代碼示例。如果您正苦於以下問題:Java Utf8ResponseHandler類的具體用法?Java Utf8ResponseHandler怎麽用?Java Utf8ResponseHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Utf8ResponseHandler類屬於me.chanjar.weixin.common.util.http包,在下文中一共展示了Utf8ResponseHandler類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public WxMpMaterialNews execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, 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)));
  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);
    } else {
      return WxMpGsonBuilder.create().fromJson(responseContent, WxMpMaterialNews.class);
    }
  }finally {
    httpPost.releaseConnection();
  }

}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:25,代碼來源:MaterialNewsInfoRequestExecutor.java

示例2: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public Boolean execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, 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)));
  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);
    } else {
      return true;
    }
  }finally {
    httpPost.releaseConnection();
  }
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:24,代碼來源:MaterialDeleteRequestExecutor.java

示例3: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public WxMpMaterialVideoInfoResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, 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)));
  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);
    } else {
      return WxMpMaterialVideoInfoResult.fromJson(responseContent);
    }
  }finally {
    httpPost.releaseConnection();
  }
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:24,代碼來源:MaterialVideoInfoRequestExecutor.java

示例4: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, 
    WxMpQrCodeTicket ticket) throws WxErrorException, IOException {
  if (ticket != null) {
    if (uri.indexOf('?') == -1) {
      uri += '?';
    }
    uri += uri.endsWith("?") 
        ? "ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8") 
        : "&ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8");
  }
  
  HttpGet httpGet = new HttpGet(uri);
  if (httpProxy != null) {
    RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
    httpGet.setConfig(config);
  }

  try (CloseableHttpResponse response = httpclient.execute(httpGet);
      InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) {
    Header[] contentTypeHeader = response.getHeaders("Content-Type");
    if (contentTypeHeader != null && contentTypeHeader.length > 0) {
      // 出錯
      if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
        String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
        throw new WxErrorException(WxError.fromJson(responseContent));
      }
    }
    return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
  } finally {
    httpGet.releaseConnection();
  }

}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:35,代碼來源:QrCodeRequestExecutor.java

示例5: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public WxMpMaterialNews execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, 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<String, String>();
  params.put("media_id", materialId);
  httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
  CloseableHttpResponse response = httpclient.execute(httpPost);
  try {
    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);
    }
  }finally {
    IOUtils.closeQuietly(response);
    httpPost.releaseConnection();
  }

}
 
開發者ID:binarywang,項目名稱:weixin-java-tools-for-JDK6,代碼行數:27,代碼來源:MaterialNewsInfoRequestExecutor.java

示例6: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public Boolean execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, 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<String, String>();
  params.put("media_id", materialId);
  httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
  CloseableHttpResponse response = httpclient.execute(httpPost);
  try {
    String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
    WxError error = WxError.fromJson(responseContent);
    if (error.getErrorCode() != 0) {
      throw new WxErrorException(error);
    } else {
      return true;
    }
  }finally {
    IOUtils.closeQuietly(response);
    httpPost.releaseConnection();
  }
}
 
開發者ID:binarywang,項目名稱:weixin-java-tools-for-JDK6,代碼行數:26,代碼來源:MaterialDeleteRequestExecutor.java

示例7: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public WxMpMaterialVideoInfoResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, 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<String, String>();
  params.put("media_id", materialId);
  httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
  CloseableHttpResponse response = httpclient.execute(httpPost);
  try {
    String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
    WxError error = WxError.fromJson(responseContent);
    if (error.getErrorCode() != 0) {
      throw new WxErrorException(error);
    } else {
      return WxMpMaterialVideoInfoResult.fromJson(responseContent);
    }
  }finally {
    IOUtils.closeQuietly(response);
    httpPost.releaseConnection();
  }
}
 
開發者ID:binarywang,項目名稱:weixin-java-tools-for-JDK6,代碼行數:26,代碼來源:MaterialVideoInfoRequestExecutor.java

示例8: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public WxMediaImgUploadResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, File data) throws WxErrorException, IOException {
  if (data == null) {
    throw new WxErrorException(WxError.newBuilder().setErrorMsg("文件對象為空").build());
  }

  HttpPost httpPost = new HttpPost(uri);
  if (httpProxy != null) {
    RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
    httpPost.setConfig(config);
  }

  HttpEntity entity = MultipartEntityBuilder
    .create()
    .addBinaryBody("media", data)
    .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 WxMediaImgUploadResult.fromJson(responseContent);
  }
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:31,代碼來源:MediaImgUploadRequestExecutor.java

示例9: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, 
    WxMpQrCodeTicket ticket) throws WxErrorException, IOException {
  if (ticket != null) {
    if (uri.indexOf('?') == -1) {
      uri += '?';
    }
    uri += uri.endsWith("?") 
        ? "ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8") 
        : "&ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8");
  }
  
  HttpGet httpGet = new HttpGet(uri);
  if (httpProxy != null) {
    RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
    httpGet.setConfig(config);
  }

  CloseableHttpResponse response = httpclient.execute(httpGet);
  InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
  try {
    Header[] contentTypeHeader = response.getHeaders("Content-Type");
    if (contentTypeHeader != null && contentTypeHeader.length > 0) {
      // 出錯
      if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
        String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
        throw new WxErrorException(WxError.fromJson(responseContent));
      }
    }
    return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
  } finally {
    IOUtils.closeQuietly(inputStream);
    IOUtils.closeQuietly(response);
    httpGet.releaseConnection();
  }

}
 
開發者ID:binarywang,項目名稱:weixin-java-tools-for-JDK6,代碼行數:38,代碼來源:QrCodeRequestExecutor.java

示例10: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public WxMediaImgUploadResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, File data) throws WxErrorException, IOException {
  if (data == null) {
    throw new WxErrorException(WxError.newBuilder().setErrorMsg("文件對象為空").build());
  }

  HttpPost httpPost = new HttpPost(uri);
  if (httpProxy != null) {
    RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
    httpPost.setConfig(config);
  }

  HttpEntity entity = MultipartEntityBuilder
    .create()
    .addBinaryBody("media", data)
    .setMode(HttpMultipartMode.RFC6532)
    .build();
  httpPost.setEntity(entity);
  httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
  CloseableHttpResponse response = httpclient.execute(httpPost);
  try {
    String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
    WxError error = WxError.fromJson(responseContent);
    if (error.getErrorCode() != 0) {
      throw new WxErrorException(error);
    }

    return WxMediaImgUploadResult.fromJson(responseContent);
  } finally {
    IOUtils.closeQuietly(response);
  }
}
 
開發者ID:binarywang,項目名稱:weixin-java-tools-for-JDK6,代碼行數:33,代碼來源:MediaImgUploadRequestExecutor.java

示例11: execute

import me.chanjar.weixin.common.util.http.Utf8ResponseHandler; //導入依賴的package包/類
@Override
public WxMpMaterialUploadResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, WxMpMaterial material) throws WxErrorException, IOException {
  HttpPost httpPost = new HttpPost(uri);
  if (httpProxy != null) {
    RequestConfig response = RequestConfig.custom().setProxy(httpProxy).build();
    httpPost.setConfig(response);
  }

  if (material == null) {
    throw new WxErrorException(WxError.newBuilder().setErrorMsg("非法請求,material參數為空").build());
  }

  File file = material.getFile();
  if (file == null || !file.exists()) {
    throw new FileNotFoundException();
  }

  MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
  multipartEntityBuilder
      .addBinaryBody("media", file)
      .setMode(HttpMultipartMode.RFC6532);
  Map<String, String> form = material.getForm();
  if (material.getForm() != null) {
    multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form));
  }

  httpPost.setEntity(multipartEntityBuilder.build());
  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);
    } else {
      return WxMpMaterialUploadResult.fromJson(responseContent);
    }
  } finally {
    httpPost.releaseConnection();
  }
}
 
開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:42,代碼來源:MaterialUploadRequestExecutor.java


注:本文中的me.chanjar.weixin.common.util.http.Utf8ResponseHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。