收藏
回答

微信公众号群发图文消息报268488001错误?

AppID
wx34e79b0dfba87f55

{"errcode":268488001,"errmsg":"system busy, please try later rid: 674eae0e-307a253b-280f84ed"}

使用群发微信公众号图文消息的时候老是报这个错误

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

2 个回答

  • 社区技术运营专员--许涛
    社区技术运营专员--许涛
    12-03

    你好,麻烦现在重新试试呢?

    12-03
    有用
    回复 7
    • Lan1ce
      Lan1ce
      12-03
      现在变成{"errcode":-1,"errmsg":"system error rid: 674ed30e-33ebe364-11f06acd"}
      12-03
      回复
    • 社区技术运营专员--许涛
      社区技术运营专员--许涛
      12-03回复Lan1ce
      现在重新试试呢?日志查看调用时间点是2024-12-03 17:44:46
      12-03
      回复
    • Lan1ce
      Lan1ce
      12-03
      {"errcode":-1,"errmsg":"system error rid: 674ee815-669f25e4-7af00a17"}还是一样的errcode
      12-03
      回复
    • 社区技术运营专员--许涛
      社区技术运营专员--许涛
      12-04回复Lan1ce
      素材ID怎么拿到的呢?
      12-04
      回复
    • 社区技术运营专员--许涛
      社区技术运营专员--许涛
      12-04回复Lan1ce
      是什么时候创建的 media_id
      12-04
      回复
    查看更多(2)
  • Lan1ce
    Lan1ce
    12-04
    public static String uploadMaterial(String accessToken, String type, File mediaFile) throws IOException {
        String UPLOAD_URL = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=%s&type=%s";
        // 构建请求URL
        String urlStr = String.format(UPLOAD_URL, accessToken, type);
    
        URL url = new URL(urlStr);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
    
        // 设置输出流
        try (OutputStream os = conn.getOutputStream()) {
            // 构建请求体
            String boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW";
            StringBuilder sb = new StringBuilder();
            sb.append("--").append(boundary).append("\r\n");
            sb.append("Content-Disposition: form-data; name=\"media\"; filename=\"")
                    .append(mediaFile.getName()).append("\"\r\n");
            sb.append("Content-Type: application/octet-stream\r\n\r\n");
    
            byte[] entityHeaderBytes = sb.toString().getBytes("UTF-8");
            os.write(entityHeaderBytes);
    
            // 写入文件内容
            try (FileInputStream fis = new FileInputStream(mediaFile)) {
                byte[] buffer = new byte[4096];
                int bytesRead;
                while ((bytesRead = fis.read(buffer)) != -1) {
                    os.write(buffer, 0, bytesRead);
                }
            }
    
            // 结束边界
            byte[] endBoundary = ("\r\n--" + boundary + "--\r\n").getBytes("UTF-8");
            os.write(endBoundary);
        }
    
        int responseCode = conn.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
                String inputLine;
                StringBuilder content = new StringBuilder();
                while ((inputLine = in.readLine()) != null) {
                    content.append(inputLine);
                }
    
                // 使用Jackson解析JSON响应并提取media_id
                ObjectMapper objectMapper = new ObjectMapper();
                JsonNode rootNode = objectMapper.readTree(content.toString());
                return rootNode.path("media_id").asText();
            }
        } else {
            System.out.println("Upload failed with response code: " + responseCode);
            throw new IOException("Failed to upload material. Response code: " + responseCode);
        }
    }
    
    
    public static String addDraft(String accessToken, List<Article> articles) throws IOException {
        String ADD_DRAFT_URL = "https://api.weixin.qq.com/cgi-bin/draft/add?access_token=%s";
        ;
        String urlStr = String.format(ADD_DRAFT_URL, accessToken);
    
        URL url = new URL(urlStr);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
    
        // 构建JSON请求体
        JSONObject json = new JSONObject();
        JSONArray articlesArray = new JSONArray();
        for (Article article : articles) {
            articlesArray.add(article.toJSON());
        }
        json.put("articles", articlesArray);
    
        // 使用 try-with-resources 确保 OutputStream 被正确关闭
        try (OutputStream os = conn.getOutputStream()) {
            byte[] input = json.toJSONString().getBytes("UTF-8");
            os.write(input, 0, input.length);
        }
    
        // 获取响应
        int responseCode = conn.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            // 使用 try-with-resources 确保 BufferedReader 被正确关闭
            try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
                String inputLine;
                StringBuilder content = new StringBuilder();
                while ((inputLine = in.readLine()) != null) {
                    content.append(inputLine);
                }
    
                // 解析JSON响应并提取media_id
                JSONObject jsonResponse = JSONObject.parseObject(content.toString());
                return jsonResponse.getString("media_id"); // 可能为null,如果没有media_id字段
            }
        } else {
            // 尝试读取错误信息
            try (BufferedReader errReader = new BufferedReader(new InputStreamReader(conn.getErrorStream()))) {
                String errorLine;
                StringBuilder errorMessage = new StringBuilder();
                while ((errorLine = errReader.readLine()) != null) {
                    errorMessage.append(errorLine);
                }
                System.err.println("Error response from server: " + errorMessage.toString());
    
                // 抛出包含详细错误信息的异常
                throw new IOException("Failed to add draft. Response code: " + responseCode + ". Error message: " + errorMessage.toString());
            }
        }
    }
    
    
    public static String sendPreview(String accessToken, String toUser, String mediaId) throws IOException {
        String PREVIEW_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=%s";
        // 构建请求URL
        String urlStr = String.format(PREVIEW_URL, accessToken);
        URL url = new URL(urlStr);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
    
        // 构建JSON请求体
        JSONObject json = new JSONObject();
        json.put("touser", toUser);
        json.put("mpnews", new JSONObject().put("media_id", mediaId));
        json.put("msgtype", "mpnews");
    
        try (OutputStream os = conn.getOutputStream()) {
            byte[] input = json.toJSONString().getBytes("utf-8");
            os.write(input, 0, input.length);
        }
    
        // 获取响应
        int responseCode = conn.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
                String inputLine;
                StringBuilder content = new StringBuilder();
                while ((inputLine = in.readLine()) != null) {
                    content.append(inputLine);
                }
    
                // 解析JSON响应并提取msg_id
                JSONObject jsonResponse = JSONObject.parseObject(content.toString());
                return jsonResponse.toString(); // 可能为null,如果没有msg_id字段
            }
        } else {
            System.out.println("Preview failed with response code: " + responseCode);
            throw new IOException("Failed to send preview message. Response code: " + responseCode);
        }
    }
    
    public static void main(String[] args) throws IOException {
        String accessToken = WeChatUtils.getAccessToken();
        try {
            File mediaFile = new File("C:\\Users\\11795\\Desktop\\首2页 – 1.png"); // 替换为你的文件路径
            String mediaId = uploadMaterial(accessToken, "image", mediaFile);
            // 创建文章实例并填充数据
            Article article = new Article();
            article.setTitle("测试标题");
            article.setThumb_media_id(mediaId); // 替换为实际的封面图片media_id
            article.setAuthor("作者名字");
            article.setDigest("这是文章的摘要");
            article.setShow_cover_pic("1"); // 是否显示封面,1表示显示,0表示不显示
            article.setContent("<p>这是文章的具体内容</p>");
            article.setContent_source_url("http://example.com");
    
            // 使用 Arrays.asList 创建列表
            List<Article> articles = Arrays.asList(article);
            // 替换为实际的openid和media_id
            String toUser = "oAgH06lJSLojkg3D-ug2rXS--HJo";
            String s = addDraft(accessToken, articles);
            String message = sendPreview(accessToken, toUser, s);
            // 调用sendPreview方法发送预览消息并获取msg_id
            if (ObjectUtil.isNotEmpty(message)) {
                System.out.println("Message: " + message);
            } else {
                System.out.println("No message returned.");
            }
    
        } catch (IOException e) {
            e.printStackTrace();
        }
    
    }
    
    现在有新的错误Message: {"errcode":45009,"errmsg":"reach max api daily quota limit rid: 674fdbda-1ac9d8dd-5ddbb5e6"},说我接口调用上限,但我一次都没有成功发送图文消息
    
    12-04
    有用
    回复
登录 后发表内容
问题标签