List of usage examples for org.apache.http.util Args notNegative
public static long notNegative(long j, String str)
From source file:com.wudaosoft.net.httpclient.WorkerBuilder.java
/** * ????????/*from www.j a v a 2 s . c o m*/ * 0? * * @param readTimeout the readTimeout to set */ public WorkerBuilder withReadTimeout(int readTimeout) { this.readTimeout = Args.notNegative(readTimeout, "readTimeout"); return this; }
From source file:me.ixfan.wechatkit.user.UserManager.java
/** * /*from w w w . ja v a 2 s . co m*/ * * @param tagId ID * @param tagName ?? * @throws WeChatApiErrorException API?? */ public void updateTag(int tagId, String tagName) throws WeChatApiErrorException { Args.notNegative(tagId, "Tag ID"); Args.notEmpty(tagName, "Tag name"); final String url = WeChatConstants.WECHAT_POST_UPDATE_TAG.replace("${ACCESS_TOKEN}", super.tokenManager.getAccessToken()); final String jsonData = "{\"tag\":{\"id\":" + String.valueOf(tagId) + ",\"name\":\"" + tagName + "\"}}"; JsonObject jsonResp; try { jsonResp = HttpClientUtil.sendPostRequestWithJsonBody(url, jsonData); } catch (IOException e) { throw new RuntimeException(e); } if (0 != jsonResp.get("errcode").getAsInt()) { throw new WeChatApiErrorException(jsonResp.get("errcode").getAsInt(), jsonResp.get("errmsg").getAsString()); } }
From source file:me.ixfan.wechatkit.user.UserManager.java
/** * //w ww . j a v a 2s .c o m * * @param tagId ID * @throws WeChatApiErrorException API?? */ public void deleteTag(int tagId) throws WeChatApiErrorException { Args.notNegative(tagId, "Tag ID"); final String url = WeChatConstants.WECHAT_POST_DELETE_TAG.replace("${ACCESS_TOKEN}", super.tokenManager.getAccessToken()); final String jsonData = "{\"tag\":{\"id\":" + String.valueOf(tagId) + "}}"; JsonObject jsonResp; try { jsonResp = HttpClientUtil.sendPostRequestWithJsonBody(url, jsonData); } catch (IOException e) { throw new RuntimeException(e); } if (0 != jsonResp.get("errcode").getAsInt()) { throw new WeChatApiErrorException(jsonResp.get("errcode").getAsInt(), jsonResp.get("errmsg").getAsString()); } }
From source file:me.ixfan.wechatkit.user.UserManager.java
/** * ??/*from w w w .ja v a2 s . co m*/ * * @param tagId ID * @param nextOpenId ?OPENID?? * @return OpenId ? <code>next_openid</code> * @throws WeChatApiErrorException API?? */ public String[] getUsersWithTag(int tagId, String nextOpenId) throws WeChatApiErrorException { Args.notNegative(tagId, "Tag ID"); final String url = WeChatConstants.WECHAT_GET_USER_WITH_TAG.replace("${ACCESS_TOKEN}", super.tokenManager.getAccessToken()); final String jsonData = "{\"tagid\":${TAG_ID},\"next_openid\":\"${NEXT_OPENID}\"}"; JsonObject jsonResp; try { jsonResp = HttpClientUtil.sendPostRequestWithJsonBody(url, jsonData.replace("${TAG_ID}", String.valueOf(tagId)).replace("${NEXT_OPENID}", null != nextOpenId ? nextOpenId : "")); } catch (IOException e) { throw new RuntimeException(e); } if (jsonResp.has("count")) { final ArrayList<String> openids = new ArrayList<>(); if (jsonResp.get("count").getAsInt() > 0) { jsonResp.get("data").getAsJsonObject().get("openid").getAsJsonArray() .forEach(e -> openids.add(e.getAsString())); if (jsonResp.has("next_openid")) { openids.add(jsonResp.get("next_openid").getAsString()); } } return openids.toArray(new String[0]); } else { throw new WeChatApiErrorException(jsonResp.get("errcode").getAsInt(), jsonResp.get("errmsg").getAsString()); } }
From source file:me.ixfan.wechatkit.user.UserManager.java
/** * ????/*from www .j a v a2s . c o m*/ * * @param tagId ID * @param openIds ?OpenID?openid?50 * @throws WeChatApiErrorException API?? */ public void batchTaggingUsersWithTag(int tagId, List<String> openIds) throws WeChatApiErrorException { Args.notNegative(tagId, "Tag ID"); Args.notEmpty(openIds, "OpenIds"); final String url = WeChatConstants.WECHAT_POST_BATCH_TAGGING.replace("${ACCESS_TOKEN}", super.tokenManager.getAccessToken()); final String jsonData = "{\"openid_list\":[${OPENIDS}],\"tagid\":${TAG_ID}}"; JsonObject jsonResp; try { jsonResp = HttpClientUtil.sendPostRequestWithJsonBody(url, jsonData.replace("${OPENIDS}", openIds.stream().collect(Collectors.joining(","))) .replace("${TAG_ID}", String.valueOf(tagId))); } catch (IOException e) { throw new RuntimeException(e); } if (jsonResp.get("errcode").getAsInt() != 0) { throw new WeChatApiErrorException(jsonResp.get("errcode").getAsInt(), jsonResp.get("errmsg").getAsString()); } }
From source file:me.ixfan.wechatkit.user.UserManager.java
/** * ??//from w ww. ja va2 s . co m * * @param tagId ID * @param openIds ?OpenID?openid?50 * @throws WeChatApiErrorException API?? */ public void batchUntaggingUsers(int tagId, List<String> openIds) throws WeChatApiErrorException { Args.notNegative(tagId, "Tag ID"); Args.notEmpty(openIds, "OpenIds"); final String url = WeChatConstants.WECHAT_POST_BATCH_UNTAGGING.replace("${ACCESS_TOKEN}", super.tokenManager.getAccessToken()); final String jsonData = "{\"openid_list\":[${OPENIDS}],\"tagid\":${TAG_ID}}"; JsonObject jsonResp; try { jsonResp = HttpClientUtil.sendPostRequestWithJsonBody(url, jsonData.replace("${OPENIDS}", openIds.stream().collect(Collectors.joining(","))) .replace("${TAG_ID}", String.valueOf(tagId))); } catch (IOException e) { throw new RuntimeException(e); } if (jsonResp.get("errcode").getAsInt() != 0) { throw new WeChatApiErrorException(jsonResp.get("errcode").getAsInt(), jsonResp.get("errmsg").getAsString()); } }