use of me.chanjar.weixin.common.exception.WxErrorException in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method materialNewsBatchGet.
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);
}
}
use of me.chanjar.weixin.common.exception.WxErrorException in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method materialCount.
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);
}
}
use of me.chanjar.weixin.common.exception.WxErrorException in project weixin-java-tools by chanjarster.
the class WxCpBusyRetryTest method testRetryInThreadPool.
@Test(dataProvider = "getService")
public void testRetryInThreadPool(final WxCpService service) throws InterruptedException, ExecutionException {
// 当线程池中的线程复用的时候,还是能保证相同的重试次数
ExecutorService executorService = Executors.newFixedThreadPool(1);
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
System.out.println("=====================");
System.out.println(Thread.currentThread().getName() + ": testRetry");
service.execute(null, null, null);
} catch (WxErrorException e) {
throw new RuntimeException(e);
} catch (RuntimeException e) {
// OK
}
}
};
Future<?> submit1 = executorService.submit(runnable);
Future<?> submit2 = executorService.submit(runnable);
submit1.get();
submit2.get();
}
use of me.chanjar.weixin.common.exception.WxErrorException in project weixin-java-tools by chanjarster.
the class MaterialDeleteRequestExecutor method execute.
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;
}
}
use of me.chanjar.weixin.common.exception.WxErrorException in project weixin-java-tools by chanjarster.
the class MaterialNewsInfoRequestExecutor method execute.
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);
}
}
Aggregations