收藏
回答

公众号文章拉取功能?

公众号ID
gh_a546a6f830b7

我需要获取公众号里面所有发表记录里面的文章,我已经掉用了这几个你们接口还是获取不了全部的,我改怎么解决这个问题

private static final String PUBLISH_BATCH_GET_URL = "https://api.weixin.qq.com/cgi-bin/freepublish/batchget";
private static final String DRAFT_BATCH_GET_URL = "https://api.weixin.qq.com/cgi-bin/draft/batchget";
private static final String MATERIAL_BATCH_GET_URL = "https://api.weixin.qq.com/cgi-bin/material/batchget_material";


回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员--许涛
    社区技术运营专员--许涛
    01-05

    你好,只能获取5篇文章。没有接口获取发表记录-全部的文章

    01-05
    有用
    回复 3
    • 胡家伟
      胡家伟
      01-21
      有计划提供 发表记录-全部的文章 的接口吗?
      01-21
      回复
    • 社区技术运营专员--许涛
      社区技术运营专员--许涛
      01-27回复胡家伟
      没有
      01-27
      回复
    • Jerry
      Jerry
      05-11
      请问那“已通知”的26条内容有接口可以单独拉取吗?
      05-11
      回复
  • 智能回答 智能回答 本次回答由AI生成
    01-04
    有用
    回复 2
    • .
      .
      01-04
      package cn.iocoder.yudao.module.ses.api.wechat.impl;


      import cn.hutool.http.HttpUtil;
      import cn.hutool.json.JSONUtil;
      import cn.iocoder.yudao.module.ses.api.wechat.WeChatPublishApi;
      import cn.iocoder.yudao.module.ses.api.wechat.dto.WeChatDraftBatchGetRespDTO;
      import cn.iocoder.yudao.module.ses.api.wechat.dto.WeChatFreePublishBatchGetReqDTO;
      import cn.iocoder.yudao.module.ses.api.wechat.dto.WeChatFreePublishBatchGetRespDTO;
      import cn.iocoder.yudao.module.ses.api.wechat.dto.WeChatMaterialBatchGetReqDTO;
      import cn.iocoder.yudao.module.ses.api.wechat.dto.WeChatMaterialBatchGetRespDTO;
      import lombok.extern.slf4j.Slf4j;
      import org.springframework.stereotype.Service;


      /**
       * 微信发布 API 实现类
       */
      @Service
      @Slf4j
      public class WeChatPublishApiImpl implements WeChatPublishApi {


          private static final String PUBLISH_BATCH_GET_URL = "https://api.weixin.qq.com/cgi-bin/freepublish/batchget";
          private static final String DRAFT_BATCH_GET_URL = "https://api.weixin.qq.com/cgi-bin/draft/batchget";
          private static final String MATERIAL_BATCH_GET_URL = "https://api.weixin.qq.com/cgi-bin/material/batchget_material";


          @Override
          public WeChatFreePublishBatchGetRespDTO getPublishedArticles(String accessToken, WeChatFreePublishBatchGetReqDTO reqDTO) {
              String url = PUBLISH_BATCH_GET_URL + "?access_token=" + accessToken;
              String safeUrl = PUBLISH_BATCH_GET_URL + "?access_token=" + maskToken(accessToken);
              
              log.info("开始调用微信接口获取已发布消息列表, url: {}, req: {}", safeUrl, reqDTO);
              try {
                  String jsonBody = JSONUtil.toJsonStr(reqDTO);
                  long startMs = System.currentTimeMillis();
                  String result = HttpUtil.post(url, jsonBody);
                  log.info("微信已发布接口返回结果(耗时 {} ms): {}", System.currentTimeMillis() - startMs, result);


                  WeChatFreePublishBatchGetRespDTO respDTO = JSONUtil.toBean(result, WeChatFreePublishBatchGetRespDTO.class);
                  if (respDTO.getErrcode() != null && respDTO.getErrcode() != 0) {
                      log.error("获取已发布消息列表失败, errcode: {}, errmsg: {}", respDTO.getErrcode(), respDTO.getErrmsg());
                  }
                  return respDTO;
              } catch (Exception e) {
                  log.error("调用微信接口异常", e);
                  throw new RuntimeException("调用微信接口异常", e);
              }
          }


          @Override
          public WeChatDraftBatchGetRespDTO getDrafts(String accessToken, WeChatFreePublishBatchGetReqDTO reqDTO) {
              String url = DRAFT_BATCH_GET_URL + "?access_token=" + accessToken;
              String safeUrl = DRAFT_BATCH_GET_URL + "?access_token=" + maskToken(accessToken);


              log.info("开始调用微信接口获取草稿列表, url: {}, req: {}", safeUrl, reqDTO);
              try {
                  String jsonBody = JSONUtil.toJsonStr(reqDTO);
                  long startMs = System.currentTimeMillis();
                  String result = HttpUtil.post(url, jsonBody);
                  log.info("微信草稿接口返回结果(耗时 {} ms): {}", System.currentTimeMillis() - startMs, result);


                  WeChatDraftBatchGetRespDTO respDTO = JSONUtil.toBean(result, WeChatDraftBatchGetRespDTO.class);
                  if (respDTO.getErrcode() != null && respDTO.getErrcode() != 0) {
                      log.error("获取草稿列表失败, errcode: {}, errmsg: {}", respDTO.getErrcode(), respDTO.getErrmsg());
                  }
                  return respDTO;
              } catch (Exception e) {
                  log.error("调用微信接口异常", e);
                  throw new RuntimeException("调用微信接口异常", e);
              }
          }


          @Override
          public WeChatMaterialBatchGetRespDTO getMaterials(String accessToken, WeChatMaterialBatchGetReqDTO reqDTO) {
              String url = MATERIAL_BATCH_GET_URL + "?access_token=" + accessToken;
              String safeUrl = MATERIAL_BATCH_GET_URL + "?access_token=" + maskToken(accessToken);


              log.info("开始调用微信接口获取素材列表, url: {}, req: {}", safeUrl, reqDTO);
              try {
                  String jsonBody = JSONUtil.toJsonStr(reqDTO);
                  long startMs = System.currentTimeMillis();
                  String result = HttpUtil.post(url, jsonBody);
                  log.info("微信素材接口返回结果(耗时 {} ms): {}", System.currentTimeMillis() - startMs, result);


                  WeChatMaterialBatchGetRespDTO respDTO = JSONUtil.toBean(result, WeChatMaterialBatchGetRespDTO.class);
                  if (respDTO.getErrcode() != null && respDTO.getErrcode() != 0) {
                      log.error("获取素材列表失败, errcode: {}, errmsg: {}", respDTO.getErrcode(), respDTO.getErrmsg());
                  }
                  return respDTO;
              } catch (Exception e) {
                  log.error("调用微信接口异常", e);
                  throw new RuntimeException("调用微信接口异常", e);
              }
          }


          private static String maskToken(String token) {
              if (token == null || token.isBlank()) {
                  return "null";
              }
              if (token.length() <= 12) {
                  return token.charAt(0) + "****" + token.charAt(token.length() - 1);
              }
              return token.substring(0, 6) + "****" + token.substring(token.length() - 4);
          }
      }
      接口返回是正确的,有几条文章,但是拿不到所有文章,最近调用在今天上午10点半左右  公众号id gh_a546a6f830b7
      01-04
      回复
    • 智能回答 智能回答 本次回答由AI生成
      01-04回复.
登录 后发表内容