me.chanjar.weixin.common.exception.WxErrorException Java Examples

The following examples show how to use me.chanjar.weixin.common.exception.WxErrorException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WxMpServiceImpl.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException {
  long timestamp = System.currentTimeMillis() / 1000;
  String noncestr = RandomUtils.getRandomStr();
  String jsapiTicket = getJsapiTicket(false);
  try {
    String signature = SHA1.genWithAmple(
        "jsapi_ticket=" + jsapiTicket,
        "noncestr=" + noncestr,
        "timestamp=" + timestamp,
        "url=" + url
    );
    WxJsapiSignature jsapiSignature = new WxJsapiSignature();
    jsapiSignature.setAppid(wxMpConfigStorage.getAppId());
    jsapiSignature.setTimestamp(timestamp);
    jsapiSignature.setNoncestr(noncestr);
    jsapiSignature.setUrl(url);
    jsapiSignature.setSignature(signature);
    return jsapiSignature;
  } catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
  }
}
 
Example #2
Source File: WxCpServiceImpl.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@Override
public List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
  String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=" + departId;
  String params = "";
  if (fetchChild != null) {
    params += "&fetch_child=" + (fetchChild ? "1" : "0");
  }
  if (status != null) {
    params += "&status=" + status;
  } else {
    params += "&status=0";
  }

  String responseContent = get(url, params);
  JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
  return WxCpGsonBuilder.INSTANCE.create()
      .fromJson(
          tmpJsonElement.getAsJsonObject().get("userlist"),
          new TypeToken<List<WxCpUser>>() { }.getType()
      );
}
 
Example #3
Source File: CustomMenuController.java    From mywx with Apache License 2.0 6 votes vote down vote up
/**
 * 创建微信菜单
 *
 * @return
 */
@RequestMapping(
        value = "create",
        method = {RequestMethod.POST, RequestMethod.GET}
)
public DataModelResult<List<WxMenu.WxMenuButton>> createMenu() {
    DataModelResult<List<WxMenu.WxMenuButton>> result = new DataModelResult<>();
    WxMenu wxMenu = new WxMenu();
    try {
        WxMenu.WxMenuButton button = new WxMenu.WxMenuButton();
        button.setName("test");
        button.setUrl("http://www.baidu.com");
        button.setType("view");
        wxMenu.getButtons().add(button);
        wxMpService.menuCreate(wxMenu);

    } catch (WxErrorException e) {
        WxError wxError = e.getError();
        log.error("create CustomMenu failure e={}", wxError.toString());
        result.setMessage(wxError.getErrorMsg());
        result.setStateCode(wxError.getErrorCode());
    }
    return result;
}
 
Example #4
Source File: MaterialVideoInfoRequestExecutor.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #5
Source File: WxCpBusyRetryTest.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@DataProvider(name="getService")
public Object[][] getService() {
  WxCpService service = new WxCpServiceImpl() {

    @Override
    protected <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
      WxError error = new WxError();
      error.setErrorCode(-1);
      throw new WxErrorException(error);
    }
  };

  service.setMaxRetryTimes(3);
  service.setRetrySleepMillis(500);
  return new Object[][] {
      new Object[] { service }
  };
}
 
Example #6
Source File: WxMpServiceImpl.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
  if (forceRefresh) {
    wxMpConfigStorage.expireJsapiTicket();
  }
  if (wxMpConfigStorage.isJsapiTicketExpired()) {
    synchronized (globalJsapiTicketRefreshLock) {
      if (wxMpConfigStorage.isJsapiTicketExpired()) {
        String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
        String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
        JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
        JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
        String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
        int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
        wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
      }
    }
  }
  return wxMpConfigStorage.getJsapiTicket();
}
 
Example #7
Source File: MediaUploadRequestExecutor.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example #8
Source File: WxCpServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public String tagCreate(String tagName) throws WxErrorException {
  String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/create";
  JsonObject o = new JsonObject();
  o.addProperty("tagname", tagName);
  String responseContent = post(url, o.toString());
  JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
  return tmpJsonElement.getAsJsonObject().get("tagid").getAsString();
}
 
Example #9
Source File: WxMpServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example #10
Source File: WxMpMiscAPITest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCallbackIP() throws WxErrorException {
  String[] ipArray = wxService.getCallbackIP();
  System.out.println(Arrays.toString(ipArray));
  Assert.assertNotNull(ipArray);
  Assert.assertNotEquals(ipArray.length, 0);
}
 
Example #11
Source File: WxCpMessageRouterRule.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
/**
 * 处理微信推送过来的消息
 *
 * @param wxMessage
 * @return true 代表继续执行别的router,false 代表停止执行别的router
 */
protected WxCpXmlOutMessage service(WxCpXmlMessage wxMessage,
    WxCpService wxCpService,
    WxSessionManager sessionManager,
    WxErrorExceptionHandler exceptionHandler) {

  try {

    Map<String, Object> context = new HashMap<String, Object>();
    // 如果拦截器不通过
    for (WxCpMessageInterceptor interceptor : this.interceptors) {
      if (!interceptor.intercept(wxMessage, context, wxCpService, sessionManager)) {
        return null;
      }
    }

    // 交给handler处理
    WxCpXmlOutMessage res = null;
    for (WxCpMessageHandler handler : this.handlers) {
      // 返回最后handler的结果
      res = handler.handle(wxMessage, context, wxCpService, sessionManager);
    }
    return res;

  } catch (WxErrorException e) {
    exceptionHandler.handle(e);
  }

  return null;

}
 
Example #12
Source File: WxMpServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException {
  String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
  JsonObject json = new JsonObject();
  json.addProperty("action_name", "QR_LIMIT_STR_SCENE");
  JsonObject actionInfo = new JsonObject();
  JsonObject scene = new JsonObject();
  scene.addProperty("scene_str", scene_str);
  actionInfo.add("scene", scene);
  json.add("action_info", actionInfo);
  String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
  return WxMpQrCodeTicket.fromJson(responseContent);
}
 
Example #13
Source File: WxMpMassMessageAPITest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider="massMessages")
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException {
  WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage();
  massMessage.setMsgtype(massMsgType);
  massMessage.setMediaId(mediaId);
  massMessage.setGroupId(wxService.groupGet().get(0).getId());

  WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
  Assert.assertNotNull(massResult);
  Assert.assertNotNull(massResult.getMsgId());
}
 
Example #14
Source File: WxMpMassMessageAPITest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
  // 发送群发消息
  ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
  WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
  massMessage.setMsgType(WxConsts.MASS_MSG_TEXT);
  massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
  massMessage.getToUsers().add(configProvider.getOpenId());

  WxMpMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage);
  Assert.assertNotNull(massResult);
  Assert.assertNotNull(massResult.getMsgId());
}
 
Example #15
Source File: WxCpServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public WxMenu menuGet(String agentId) throws WxErrorException {
  String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?agentid=" + agentId;
  try {
    String resultContent = get(url, null);
    return WxMenu.fromJson(resultContent);
  } catch (WxErrorException e) {
    // 46003 不存在的菜单数据
    if (e.getError().getErrorCode() == 46003) {
      return null;
    }
    throw e;
  }
}
 
Example #16
Source File: WxCpServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
public Integer departCreate(WxCpDepart depart) throws WxErrorException {
  String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
  String responseContent = execute(
      new SimplePostRequestExecutor(),
      url,
      depart.toJson());
  JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
  return GsonHelper.getAsInteger(tmpJsonElement.getAsJsonObject().get("id"));
}
 
Example #17
Source File: WxCpServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
public List<WxCpDepart> departGet() throws WxErrorException {
  String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
  String responseContent = get(url, null);
  /*
   * 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} }
   * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
   */
  JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
  return WxCpGsonBuilder.INSTANCE.create()
      .fromJson(
          tmpJsonElement.getAsJsonObject().get("department"),
          new TypeToken<List<WxCpDepart>>() {
          }.getType()
      );
}
 
Example #18
Source File: WxMpOAuth2Servlet.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override protected void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

  response.setContentType("text/html;charset=utf-8");
  response.setStatus(HttpServletResponse.SC_OK);

  String code = request.getParameter("code");
  try {
    response.getWriter().println("<h1>code</h1>");
    response.getWriter().println(code);

    WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
    response.getWriter().println("<h1>access token</h1>");
    response.getWriter().println(wxMpOAuth2AccessToken.toString());

    WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
    response.getWriter().println("<h1>user info</h1>");
    response.getWriter().println(wxMpUser.toString());

    wxMpOAuth2AccessToken = wxMpService.oauth2refreshAccessToken(wxMpOAuth2AccessToken.getRefreshToken());
    response.getWriter().println("<h1>after refresh</h1>");
    response.getWriter().println(wxMpOAuth2AccessToken.toString());

  } catch (WxErrorException e) {
    e.printStackTrace();
  }

  response.getWriter().flush();
  response.getWriter().close();

}
 
Example #19
Source File: WxCpDepartAPITest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
public void testDepartCreate() throws WxErrorException {
  WxCpDepart depart = new WxCpDepart();
  depart.setName("子部门" + System.currentTimeMillis());
  depart.setParentId(1);
  depart.setOrder(1);
  Integer departId = wxCpService.departCreate(depart);
}
 
Example #20
Source File: WxMpMaterialAPITest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testMaterialNewsList"})
public void testMaterialFileList() throws WxErrorException {
  WxMpMaterialFileBatchGetResult wxMpMaterialVoiceBatchGetResult = wxService.materialFileBatchGet(WxConsts.MATERIAL_VOICE, 0, 20);
  WxMpMaterialFileBatchGetResult wxMpMaterialVideoBatchGetResult = wxService.materialFileBatchGet(WxConsts.MATERIAL_VIDEO, 0, 20);
  WxMpMaterialFileBatchGetResult wxMpMaterialImageBatchGetResult = wxService.materialFileBatchGet(WxConsts.MATERIAL_IMAGE, 0, 20);
  return;
}
 
Example #21
Source File: WxCpServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
/**
 * 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
 *
 * @param executor
 * @param uri
 * @param data
 * @return
 * @throws WxErrorException
 */
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
  int retryTimes = 0;
  do {
    try {
      return executeInternal(executor, uri, data);
    } catch (WxErrorException e) {
      WxError error = e.getError();
      /**
       * -1 系统繁忙, 1000ms后重试
       */
      if (error.getErrorCode() == -1) {
        int sleepMillis = retrySleepMillis * (1 << retryTimes);
        try {
          log.debug("微信系统繁忙,{}ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
          Thread.sleep(sleepMillis);
        } catch (InterruptedException e1) {
          throw new RuntimeException(e1);
        }
      } else {
        throw e;
      }
    }
  } while(++retryTimes < maxRetryTimes);

  throw new RuntimeException("微信服务端异常,超出重试次数");
}
 
Example #22
Source File: WxMpMaterialAPITest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "uploadMaterial")
public void testUploadMaterial(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
  if (wxMaterialCountResultBeforeTest == null) {
    wxMaterialCountResultBeforeTest = wxService.materialCount();
  }
  InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
  File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), fileType);
  WxMpMaterial wxMaterial = new WxMpMaterial();
  wxMaterial.setFile(tempFile);
  wxMaterial.setName(fileName);
  if (WxConsts.MEDIA_VIDEO.equals(mediaType)) {
    wxMaterial.setVideoTitle("title");
    wxMaterial.setVideoIntroduction("test video description");
  }
  WxMpMaterialUploadResult res = wxService.materialFileUpload(mediaType, wxMaterial);
  Assert.assertNotNull(res.getMediaId());
  if (WxConsts.MEDIA_IMAGE.equals(mediaType) || WxConsts.MEDIA_THUMB.equals(mediaType)) {
    Assert.assertNotNull(res.getUrl());
  }
  if (WxConsts.MEDIA_THUMB.equals(mediaType)) {
    thumbMediaId = res.getMediaId();
  }

  Map<String, Object> materialInfo = new HashMap<>();
  materialInfo.put("media_id", res.getMediaId());
  materialInfo.put("length", tempFile.length());
  materialInfo.put("filename", tempFile.getName());
  media_ids.put(res.getMediaId(), materialInfo);
}
 
Example #23
Source File: WxCpDepartAPITest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testDepartCreate")
public void testDepartGet() throws WxErrorException {
  System.out.println("=================获取部门");
  List<WxCpDepart> departList = wxCpService.departGet();
  Assert.assertNotNull(departList);
  Assert.assertTrue(departList.size() > 0);
  for (WxCpDepart g : departList) {
    depart = g;
    System.out.println(depart.getId() + ":" + depart.getName());
    Assert.assertNotNull(g.getName());
  }
}
 
Example #24
Source File: MaterialVoiceAndImageDownloadRequestExecutor.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #25
Source File: WxMpMenuAPITest.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = { "testGetMenu"})
public void testDeleteMenu() throws WxErrorException {
  wxService.menuDelete();
}
 
Example #26
Source File: WxMpMaterialAPITest.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"testUploadMaterial"})
public void testAddNews() throws WxErrorException {

  // 单图文消息
  WxMpMaterialNews wxMpMaterialNewsSingle = new WxMpMaterialNews();
  WxMpMaterialNews.WxMpMaterialNewsArticle mpMaterialNewsArticleSingle = new WxMpMaterialNews.WxMpMaterialNewsArticle();
  mpMaterialNewsArticleSingle.setAuthor("author");
  mpMaterialNewsArticleSingle.setThumbMediaId(thumbMediaId);
  mpMaterialNewsArticleSingle.setTitle("single title");
  mpMaterialNewsArticleSingle.setContent("single content");
  mpMaterialNewsArticleSingle.setContentSourceUrl("content url");
  mpMaterialNewsArticleSingle.setShowCoverPic(true);
  mpMaterialNewsArticleSingle.setDigest("single news");
  wxMpMaterialNewsSingle.addArticle(mpMaterialNewsArticleSingle);

  // 多图文消息
  WxMpMaterialNews wxMpMaterialNewsMultiple = new WxMpMaterialNews();
  WxMpMaterialNews.WxMpMaterialNewsArticle wxMpMaterialNewsArticleMutiple1 = new WxMpMaterialNews.WxMpMaterialNewsArticle();
  wxMpMaterialNewsArticleMutiple1.setAuthor("author1");
  wxMpMaterialNewsArticleMutiple1.setThumbMediaId(thumbMediaId);
  wxMpMaterialNewsArticleMutiple1.setTitle("multi title1");
  wxMpMaterialNewsArticleMutiple1.setContent("content 1");
  wxMpMaterialNewsArticleMutiple1.setContentSourceUrl("content url");
  wxMpMaterialNewsArticleMutiple1.setShowCoverPic(true);
  wxMpMaterialNewsArticleMutiple1.setDigest("");

  WxMpMaterialNews.WxMpMaterialNewsArticle wxMpMaterialNewsArticleMultiple2 = new WxMpMaterialNews.WxMpMaterialNewsArticle();
  wxMpMaterialNewsArticleMultiple2.setAuthor("author2");
  wxMpMaterialNewsArticleMultiple2.setThumbMediaId(thumbMediaId);
  wxMpMaterialNewsArticleMultiple2.setTitle("multi title2");
  wxMpMaterialNewsArticleMultiple2.setContent("content 2");
  wxMpMaterialNewsArticleMultiple2.setContentSourceUrl("content url");
  wxMpMaterialNewsArticleMultiple2.setShowCoverPic(true);
  wxMpMaterialNewsArticleMultiple2.setDigest("");

  wxMpMaterialNewsMultiple.addArticle(wxMpMaterialNewsArticleMutiple1);
  wxMpMaterialNewsMultiple.addArticle(wxMpMaterialNewsArticleMultiple2);

  WxMpMaterialUploadResult resSingle = wxService.materialNewsUpload(wxMpMaterialNewsSingle);
  singleNewsMediaId = resSingle.getMediaId();
  WxMpMaterialUploadResult resMulti = wxService.materialNewsUpload(wxMpMaterialNewsMultiple);
  multiNewsMediaId = resMulti.getMediaId();
}
 
Example #27
Source File: WxMpMenuAPITest.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
@Test(dataProvider = "menu")
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
  System.out.println(wxMenu.toJson());
  wxService.menuCreate(wxMenu);
}
 
Example #28
Source File: WxMpUserAPITest.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public void testUserInfo() throws WxErrorException  {
  ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
  WxMpUser user = wxService.userInfo(configProvider.getOpenId(), null);
  Assert.assertNotNull(user);
}
 
Example #29
Source File: WxCpServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
@Override
public void userDelete(String userid) throws WxErrorException {
  String url = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?userid=" + userid;
  get(url, null);
}
 
Example #30
Source File: WxCpServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public String get(String url, String queryParam) throws WxErrorException {
  return execute(new SimpleGetRequestExecutor(), url, queryParam);
}