{"id":2880,"date":"2026-06-11T16:54:07","date_gmt":"2026-06-11T08:54:07","guid":{"rendered":"https:\/\/thereisno.top\/?p=2880"},"modified":"2026-06-11T16:54:07","modified_gmt":"2026-06-11T08:54:07","slug":"%e9%a3%9e%e4%b9%a6%e8%87%aa%e5%8a%a8%e5%8c%96pdf%e5%8a%a0%e5%af%86%e6%95%b0%e5%ad%97%e8%af%81%e4%b9%a6%e7%ad%be%e5%90%8d","status":"publish","type":"post","link":"https:\/\/thereisno.top\/?p=2880","title":{"rendered":"\u98de\u4e66\u81ea\u52a8\u5316PDF\u52a0\u5bc6\u6570\u5b57\u8bc1\u4e66\u7b7e\u540d"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u80cc\u666f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u9762\u5df2\u7ecf\u5b8c\u6210\u4e86<a href=\"https:\/\/thereisno.top\/?p=2876\">\u9489\u9489\u81ea\u52a8\u5316PDF\u52a0\u5bc6\u6570\u5b57\u8bc1\u4e66\u7b7e\u540d<\/a>\uff0c\u98de\u4e66\u548c\u4f01\u4e1a\u5fae\u4fe1\u4e5f\u5e94\u8be5\u540c\u6b65\u8ddf\u8fdb\u3002\u53ef\u60dc\u7684\u662f\u4f01\u4e1a\u5fae\u4fe1\u673a\u5668\u4eba\u9650\u5236\u666e\u901a\u673a\u5668\u4eba\u548c\u4f7f\u7528<code>URL\u56de\u8c03<\/code>\u63a5\u5165\u7684\u673a\u5668\u4eba\u4e0d\u652f\u6301\u63a5\u6536\u6587\u4ef6\uff0c\u53ea\u80fd\u662f\u957f\u8fde\u63a5\u667a\u80fd\u673a\u5668\u4eba\u652f\u6301\u63a5\u6536\u6587\u4ef6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6548\u679c\u5c55\u793a<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/doc.thereisno.top\/_images\/fssignpdf.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u6838\u5fc3\u4ee3\u7801<\/h2>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"wp-block-preformatted\">import org.apache.http.client.methods.CloseableHttpResponse;\nimport org.apache.http.client.methods.HttpGet;\nimport org.apache.http.impl.client.CloseableHttpClient;\nimport org.apache.http.impl.client.HttpClients;\nimport org.apache.http.util.EntityUtils;\n\nimport com.alibaba.fastjson.JSONObject;\n\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\n\nimport org.apache.http.HttpEntity;\nimport org.apache.http.client.methods.HttpPost;\nimport org.apache.http.entity.ContentType;\nimport org.apache.http.entity.StringEntity;\nimport org.apache.http.entity.mime.MultipartEntityBuilder;\n\npublic class FeishuUpDownUtil {\n\t\n\t\/**\n\t * \u4e0b\u8f7d\u7528\u6237\u4e0a\u4f20\u7684\u6587\u4ef6\n\t * @param msgId \u6d88\u606fID\n\t * @param fileKey \u4e8b\u4ef6\u5185\u7684file_key\n\t * @param saveName \u4fdd\u5b58\u6587\u4ef6\u540d\n\t * @return \u672c\u5730\u7edd\u5bf9\u8def\u5f84\n\t *\/\n\tpublic String downloadFeishuFile(String token,String msgId, String fileKey, String savePath) {\n\t    String url = \"https:\/\/open.feishu.cn\/open-apis\/im\/v1\/messages\/\" + msgId + \"\/resources\/\" + fileKey+\"?type=file\";\n\n\t    try (CloseableHttpClient client = HttpClients.createDefault()) {\n\t        HttpGet httpGet = new HttpGet(url);\n\t        httpGet.setHeader(\"Authorization\", \"Bearer \" + token);\n\t        CloseableHttpResponse resp = client.execute(httpGet);\n\t        InputStream is = resp.getEntity().getContent();\n\n\t        \/\/ \u5199\u5165\u672c\u5730\n\t        File outFile = new File(savePath);\n\t        try (FileOutputStream fos = new FileOutputStream(outFile)) {\n\t            byte[] buf = new byte[4096];\n\t            int len;\n\t            while ((len = is.read(buf)) != -1) {\n\t                fos.write(buf, 0, len);\n\t            }\n\t        }\n\t        resp.close();\n\t    } catch (IOException e) {\n\t    \tSystem.out.println(\"\u4e0b\u8f7d\u6587\u4ef6\u5931\u8d25\");\n\t\t\te.printStackTrace();\n\t\t}\n\t    return savePath;\n\t}\n\t\n\t\/**\n\t * \u4e0a\u4f20\u672c\u5730\u6587\u4ef6\uff0c\u8fd4\u56de\u53ef\u53d1\u6d88\u606f\u7684file_key\n\t *\/\n\tpublic String uploadFeishuFile(String token,String localFilePath) {\n\t    String url = \"https:\/\/open.feishu.cn\/open-apis\/im\/v1\/files\";\n\t    File uploadFile = new File(localFilePath);\n\n\t    try (CloseableHttpClient client = HttpClients.createDefault()) {\n\t        HttpPost httpPost = new HttpPost(url);\n\t        httpPost.setHeader(\"Authorization\", \"Bearer \" + token);\n\n\t        \/\/ \u4e25\u683c\u6309\u7167\u98de\u4e66\u8981\u6c42\u6784\u9020multipart\n\t        MultipartEntityBuilder builder = MultipartEntityBuilder.create();\n\t        \/\/ \u624b\u52a8\u56fa\u5b9aboundary\uff0c\u907f\u514d\u590d\u6742\u7b26\u53f7\u89e3\u6790\u5931\u8d25\n\t        String boundary = \"----feishu-file-upload-boundary-123456\";\n\t        httpPost.setHeader(\"Content-Type\", \"multipart\/form-data; boundary=\" + boundary);\n\t        builder.setBoundary(boundary);\n\t        \n\t        \/\/ 1. \u6587\u4ef6\u7c7b\u578b \u666e\u901a\u6587\u4ef6\u7c7b\u578b \u56fa\u5b9a\u5c0f\u5199file\uff0c\u5f3a\u5236UTF8\n\t        builder.addTextBody(\"file_type\", \"pdf\",ContentType.TEXT_PLAIN.withCharset(java.nio.charset.StandardCharsets.UTF_8));\n\t        \/\/ 2. \u6587\u4ef6\u540d\u79f0\n\t        builder.addTextBody(\"file_name\", uploadFile.getName(),ContentType.TEXT_PLAIN.withCharset(java.nio.charset.StandardCharsets.UTF_8));\n\t        \/\/ 3. \u6587\u4ef6\u4e8c\u8fdb\u5236\n\t        builder.addBinaryBody(\n\t                \"file\",\n\t                new FileInputStream(uploadFile),\n\t                ContentType.APPLICATION_OCTET_STREAM,\n\t                uploadFile.getName()\n\t        );\n\t        \n\t        HttpEntity multipart = builder.build();\n\t        httpPost.setEntity(multipart);\n\n\t        CloseableHttpResponse resp = client.execute(httpPost);\n\t        String respJson = EntityUtils.toString(resp.getEntity(), \"UTF-8\");\n\t        System.out.println(\"upload feishu file: \"+respJson);\n\t        resp.close();\n\n\t        \/\/ \u89e3\u6790\u8fd4\u56defile_key\n\t        JSONObject resObj = JSONObject.parseObject(respJson);\n\t        JSONObject data = resObj.getJSONObject(\"data\");\n\t        return data.getString(\"file_key\");\n\t    } catch (IOException e) {\n\t    \tSystem.out.println(\"\u4e0a\u4f20\u6587\u4ef6\u5931\u8d25\");\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn null;\n\t\t\n\t}\n\t\n\t\/**\n\t * \u4f1a\u8bdd\u5185\u56de\u590d\u6587\u4ef6\u6d88\u606f\uff0c\u66ff\u4ee3\u6587\u672c\u53d1\u9001\n\t * @param chatId \u4f1a\u8bddID\n\t * @param fileKey \u4e0a\u4f20\u63a5\u53e3\u8fd4\u56de\u7684file_key\n\t * @param showFileName \u524d\u7aef\u5c55\u793a\u6587\u4ef6\u540d\n\t *\/\n\tpublic void replyFeishuFile(String token,String chatId, String fileKey, String showFileName) {\n\t    String url = \"https:\/\/open.feishu.cn\/open-apis\/im\/v1\/messages?receive_id_type=chat_id\";\n\n\t    \/\/ \u6784\u9020\u6587\u4ef6\u6d88\u606f\u4f53\n\t    JSONObject fileContent = new JSONObject();\n\t    fileContent.put(\"file_key\", fileKey);\n\t    fileContent.put(\"file_name\", showFileName);\n\n\t    JSONObject body = new JSONObject();\n\t    body.put(\"receive_id_type\", \"chat_id\");\n\t    body.put(\"receive_id\", chatId);\n\t    body.put(\"msg_type\", \"file\");\n\t    body.put(\"content\", fileContent.toString());\n\t    String reqJson=body.toString();\n\t    System.out.println(reqJson);\n\n\t    try (CloseableHttpClient client = HttpClients.createDefault()) {\n\t        HttpPost httpPost = new HttpPost(url);\n\t        httpPost.setHeader(\"Authorization\", \"Bearer \" + token);\n\t        httpPost.setHeader(\"Content-Type\", \"application\/json; charset=utf-8\");\n\t        StringEntity reqEntity=new StringEntity(reqJson, java.nio.charset.StandardCharsets.UTF_8);\n\t        httpPost.setEntity(reqEntity);\n\n\t        CloseableHttpResponse resp = client.execute(httpPost);\n\t        System.out.println(\"\u53d1\u9001\u6587\u4ef6\u8fd4\u56de\uff1a\" + respStr);\n\t        resp.close();\n\t    } catch (IOException e) {\n\t    \tSystem.out.println(\"\u56de\u590d\u6587\u4ef6\u6d88\u606f\u5931\u8d25\");\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n}\n<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f<\/strong>\uff1a \u8c46\u5305\u7ed9\u7684\u53c2\u8003\u4ee3\u7801&nbsp;<code>downloadFeishuFile<\/code>&nbsp;<code>replyFeishuFile<\/code>\uff0c\u53c2\u6570\u662f\u9519\u8bef\u7684\uff0c\u98de\u4e66\u6bd5\u7adf\u662f\u81ea\u5df1\u7684\u4e1c\u897f\uff0c\u8c46\u5305\u90fd\u80fd\u641e\u9519\u3002&nbsp;<code>type=file<\/code>\u548c&nbsp;<code>receive_id_type=chat_id<\/code>&nbsp;\u662fURL\u53c2\u6570\uff0c\u4e0d\u662f<code>header<\/code><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u524d\u9762\u5df2\u7ecf\u5b8c\u6210\u4e86\u9489\u9489\u81ea\u52a8\u5316PDF\u52a0\u5bc6\u6570\u5b57\u8bc1\u4e66\u7b7e\u540d\uff0c\u98de\u4e66\u548c\u4f01\u4e1a\u5fae\u4fe1\u4e5f\u5e94\u8be5\u540c\u6b65\u8ddf\u8fdb\u3002\u53ef\u60dc\u7684\u662f\u4f01\u4e1a\u5fae\u4fe1\u673a\u5668\u4eba\u9650\u5236 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/thereisno.top\/?p=2880\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u98de\u4e66\u81ea\u52a8\u5316PDF\u52a0\u5bc6\u6570\u5b57\u8bc1\u4e66\u7b7e\u540d\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[310,312,311],"class_list":["post-2880","post","type-post","status-publish","format-standard","hentry","category-java","tag-pdf","tag-312","tag-311"],"_links":{"self":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/2880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2880"}],"version-history":[{"count":1,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/2880\/revisions"}],"predecessor-version":[{"id":2881,"href":"https:\/\/thereisno.top\/index.php?rest_route=\/wp\/v2\/posts\/2880\/revisions\/2881"}],"wp:attachment":[{"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thereisno.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}