小程序
小游戏
企业微信
微信支付
扫描小程序码分享
{"errcode":268488001,"errmsg":"system busy, please try later rid: 674eae0e-307a253b-280f84ed"}
使用群发微信公众号图文消息的时候老是报这个错误
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
你好,麻烦现在重新试试呢?
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
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"},说我接口调用上限,但我一次都没有成功发送图文消息
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
你好,麻烦现在重新试试呢?
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"},说我接口调用上限,但我一次都没有成功发送图文消息