me.chanjar.weixin.common.util.json.WxGsonBuilder.create()方法的使用及代码示例

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

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

WxGsonBuilder.create介绍

暂无

代码示例

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

/**
 * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
 * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
 * @param json
 * @return
 */
public static WxMenu fromJson(String json) {
 return WxGsonBuilder.create().fromJson(json, WxMenu.class);
}

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

public static WxError fromJson(String json) {
 WxError error = WxGsonBuilder.create().fromJson(json, WxError.class);
 return error;
}

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

public static WxMediaUploadResult fromJson(String json) {
 return WxGsonBuilder.create().fromJson(json, WxMediaUploadResult.class);
}

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

public static WxAccessToken fromJson(String json) {
 return WxGsonBuilder.create().fromJson(json, WxAccessToken.class);
}

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

public String toJson() {
 return WxGsonBuilder.create().toJson(this);
}

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

/**
 * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
 * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
 * @param is
 * @return
 */
public static WxMenu fromJson(InputStream is) {
 return WxGsonBuilder.create().fromJson(new InputStreamReader(is, Charsets.UTF_8), WxMenu.class);
}

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

Map<String, String> form = material.getForm();
if (material.getForm() != null) {
 multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form));

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

@Override
 public String toString() {
  return WxGsonBuilder.create().toJson(this);
 }
}

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

@Override
 public String toString() {
  return WxGsonBuilder.create().toJson(this);
 }
}

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

@Override
 public String toString() {
  return WxGsonBuilder.create().toJson(this);
 }
}

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

/**
 * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
 * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
 */
public static WxMenu fromJson(String json) {
 return WxGsonBuilder.create().fromJson(json, WxMenu.class);
}

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

/**
 * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
 * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
 * @param json
 * @return
 */
public static WxMenu fromJson(String json) {
 return WxGsonBuilder.create().fromJson(json, WxMenu.class);
}

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

/**
 * 要用 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html 格式来反序列化
 * 相比 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html 的格式,外层多套了一个menu
 * @param is
 * @return
 */
public static WxMenu fromJson(InputStream is) {
 return WxGsonBuilder.create().fromJson(new InputStreamReader(is, Charsets.UTF_8), WxMenu.class);
}

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

相关文章

微信公众号

最新文章

更多

WxGsonBuilder类方法