{"id":647,"date":"2026-12-02T20:52:26","date_gmt":"2026-12-02T12:52:26","guid":{"rendered":"https:\/\/wp.chih-hao.synology.me\/?p=647"},"modified":"2026-12-03T02:08:27","modified_gmt":"2026-12-02T18:08:27","slug":"line-bot-%e6%94%b6%e4%b8%8d%e5%88%b0%e8%a8%8a%e6%81%af%ef%bc%9f%e5%be%9e-webhook-%e9%a9%97%e8%ad%89%e5%88%b0%e5%9b%9e%e8%a6%86%e7%9a%84%e6%8e%92%e9%8c%af%e9%a0%86%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/wp.chih-hao.synology.me\/?p=647","title":{"rendered":"LINE Bot \u6536\u4e0d\u5230\u8a0a\u606f\uff1f\u5f9e Webhook \u9a57\u8b49\u5230\u56de\u8986\u7684\u6392\u932f\u9806\u5e8f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">LINE Bot \u6536\u4e0d\u5230\u8a0a\u606f\u6642\uff0c\u5148\u5230 LINE Developers Console \u6309\u4e00\u6b21 <strong>Verify<\/strong>\uff0c\u518d\u7528\u624b\u6a5f\u5c0d\u540c\u4e00\u500b LINE \u5b98\u65b9\u5e33\u865f\u50b3\u4e00\u5247\u6587\u5b57\u3002\u6bd4\u5c0d\u9019\u5169\u6b21\u64cd\u4f5c\u7684\u4f3a\u670d\u5668\u65e5\u8a8c\uff0c\u5c31\u80fd\u77e5\u9053\u554f\u984c\u5361\u5728\u7db2\u5740\u3001\u7c3d\u7ae0\u9a57\u8b49\u3001\u4e8b\u4ef6\u8655\u7406\uff0c\u9084\u662f\u56de\u8986 API\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_91 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u6587\u7ae0\u76ee\u9304<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"\u986f\u793a\/\u96b1\u85cf\u5167\u5bb9\u76ee\u9304\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/wp.chih-hao.synology.me\/?p=647\/#%E7%A2%BA%E8%AA%8D%E5%85%AC%E9%96%8B_HTTPS_%E7%B6%B2%E5%9D%80%E5%8F%AF%E4%BB%A5%E6%8E%A5%E6%94%B6_POST\" >\u78ba\u8a8d\u516c\u958b HTTPS \u7db2\u5740\u53ef\u4ee5\u63a5\u6536 POST<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/wp.chih-hao.synology.me\/?p=647\/#Verify_%E6%88%90%E5%8A%9F%E5%BE%8C%EF%BC%8C%E7%94%A8%E4%B8%80%E5%B0%8D%E4%B8%80%E6%96%87%E5%AD%97%E8%A8%8A%E6%81%AF%E7%A2%BA%E8%AA%8D%E4%BA%8B%E4%BB%B6%E9%80%81%E9%81%94\" >Verify \u6210\u529f\u5f8c\uff0c\u7528\u4e00\u5c0d\u4e00\u6587\u5b57\u8a0a\u606f\u78ba\u8a8d\u4e8b\u4ef6\u9001\u9054<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/wp.chih-hao.synology.me\/?p=647\/#%E9%A9%97%E8%AD%89%E7%B0%BD%E7%AB%A0%EF%BC%8C%E5%8F%AA%E8%A8%98%E9%8C%84%E4%BA%8B%E4%BB%B6%E6%95%B8%E9%87%8F%E8%88%87%E9%A1%9E%E5%9E%8B\" >\u9a57\u8b49\u7c3d\u7ae0\uff0c\u53ea\u8a18\u9304\u4e8b\u4ef6\u6578\u91cf\u8207\u985e\u578b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/wp.chih-hao.synology.me\/?p=647\/#%E7%94%A8_Webhook_errors_%E5%B0%8D%E7%85%A7%E4%BC%BA%E6%9C%8D%E5%99%A8%E6%97%A5%E8%AA%8C\" >\u7528 Webhook errors \u5c0d\u7167\u4f3a\u670d\u5668\u65e5\u8a8c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/wp.chih-hao.synology.me\/?p=647\/#%E5%B7%B2%E6%94%B6%E5%88%B0_MessageEvent%EF%BC%8C%E5%86%8D%E6%9F%A5%E5%9B%9E%E8%A6%86_API\" >\u5df2\u6536\u5230 MessageEvent\uff0c\u518d\u67e5\u56de\u8986 API<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/wp.chih-hao.synology.me\/?p=647\/#SDK_%E4%BE%86%E6%BA%90%E8%88%87%E5%BB%B6%E4%BC%B8%E9%96%B1%E8%AE%80\" >SDK \u4f86\u6e90\u8207\u5ef6\u4f38\u95b1\u8b80<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%A2%BA%E8%AA%8D%E5%85%AC%E9%96%8B_HTTPS_%E7%B6%B2%E5%9D%80%E5%8F%AF%E4%BB%A5%E6%8E%A5%E6%94%B6_POST\"><\/span>\u78ba\u8a8d\u516c\u958b HTTPS \u7db2\u5740\u53ef\u4ee5\u63a5\u6536 POST<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u767b\u5165 LINE Developers Console\uff0c\u958b\u555f\u8a72\u5b98\u65b9\u5e33\u865f\u5c0d\u61c9\u7684 Messaging API channel\u3002\u5728 <strong>Messaging API<\/strong> \u5206\u9801\u7684 <strong>Webhook settings<\/strong>\uff0c\u628a <strong>Webhook URL<\/strong> \u8a2d\u6210\u5b8c\u6574\u7db2\u5740\uff0c\u4f8b\u5982 <code>https:\/\/bot.example.com\/callback<\/code>\u3002\u628a\u7bc4\u4f8b\u7db2\u57df\u63db\u6210\u81ea\u5df1\u7684\u7db2\u57df\uff0c\u8def\u5f91\u8981\u548c\u4f3a\u670d\u5668\u7684 POST \u8def\u7531\u5b8c\u5168\u4e00\u81f4\u3002\u5132\u5b58\u5f8c\u6309 <strong>Verify<\/strong>\uff0c\u6536\u5230\u5408\u6cd5\u9a57\u8b49\u8acb\u6c42\u6642\uff0c\u4f3a\u670d\u5668\u8981\u56de\u50b3 HTTP <code>200<\/code>\u3002<a href=\"https:\/\/developers.line.biz\/en\/docs\/messaging-api\/verify-webhook-url\/\" target=\"_blank\" rel=\"noopener\">LINE \u5b98\u65b9 Webhook URL \u9a57\u8b49\u6587\u4ef6<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Webhook \u63a5\u6536\u7aef\u8981\u80fd\u5f9e\u7db2\u969b\u7db2\u8def\u9023\u7dda\uff0c\u4e26\u4f7f\u7528\u516c\u958b\u6191\u8b49\u6a5f\u69cb\u7c3d\u767c\u4e14\u4ecd\u6709\u6548\u7684 TLS \u6191\u8b49\u3002\u82e5\u9a57\u8b49\u986f\u793a\u9023\u7dda\u5931\u6557\uff0c\u5148\u5c0d\u7167\u7db2\u57df\u3001\u6191\u8b49\u6709\u6548\u671f\u9650\u548c\u4e2d\u7e7c\u6191\u8b49\u93c8\u3002\u82e5\u4f3a\u670d\u5668\u5b58\u53d6\u65e5\u8a8c\u5df2\u51fa\u73fe\u8acb\u6c42\uff0c\u78ba\u8a8d\u5b83\u662f <code>POST \/callback<\/code>\u3002\u700f\u89bd\u5668\u6253\u958b\u7db2\u5740\u901a\u5e38\u9001\u7684\u662f GET\uff0c\u5728\u700f\u89bd\u5668\u770b\u5230\u7684\u7d50\u679c\u53ea\u80fd\u7528\u4f86\u78ba\u8a8d\u8a72\u6b21 GET\u3002<a href=\"https:\/\/developers.line.biz\/en\/docs\/messaging-api\/building-bot\/#setting-webhook-url\" target=\"_blank\" rel=\"noopener\">LINE \u5b98\u65b9 Webhook \u8a2d\u5b9a<\/a>\u3001<a href=\"https:\/\/developers.line.biz\/en\/docs\/messaging-api\/ssl-tls-spec-of-the-webhook-source\/\" target=\"_blank\" rel=\"noopener\">Webhook TLS \u898f\u683c<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Verify_%E6%88%90%E5%8A%9F%E5%BE%8C%EF%BC%8C%E7%94%A8%E4%B8%80%E5%B0%8D%E4%B8%80%E6%96%87%E5%AD%97%E8%A8%8A%E6%81%AF%E7%A2%BA%E8%AA%8D%E4%BA%8B%E4%BB%B6%E9%80%81%E9%81%94\"><\/span>Verify \u6210\u529f\u5f8c\uff0c\u7528\u4e00\u5c0d\u4e00\u6587\u5b57\u8a0a\u606f\u78ba\u8a8d\u4e8b\u4ef6\u9001\u9054<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6309\u4e0b Verify \u6642\uff0cLINE \u6703\u9001\u51fa\u7528\u65bc\u78ba\u8a8d\u9023\u7dda\u7684 POST\uff0c\u5167\u5bb9\u7684 <code>events<\/code> \u662f\u7a7a\u9663\u5217\u3002\u7c3d\u7ae0\u901a\u904e\u5f8c\u56de\u50b3 <code>200<\/code> \u5373\u53ef\u3002\u82e5\u7a0b\u5f0f\u4e00\u9032\u8def\u7531\u5c31\u53d6 <code>events[0]<\/code>\uff0c\u9019\u6b21\u9a57\u8b49\u6703\u78b0\u5230\u7d22\u5f15\u932f\u8aa4\u3002<a href=\"https:\/\/developers.line.biz\/en\/reference\/messaging-api\/nojs\/#webhooks\" target=\"_blank\" rel=\"noopener\">LINE \u5b98\u65b9 Webhook \u683c\u5f0f\u53ca\u56de\u61c9\u898f\u683c<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u8457\u5728\u540c\u4e00\u500b channel \u958b\u555f <strong>Use webhook<\/strong>\u3002\u7528\u81ea\u5df1\u7684 LINE \u5e33\u865f\u5728\u4e00\u5c0d\u4e00\u804a\u5929\u50b3\u4e00\u5247\u300c\u6e2c\u8a66\u300d\u7d66\u5c0d\u61c9\u7684\u5b98\u65b9\u5e33\u865f\uff0c\u8a18\u4e0b\u50b3\u9001\u6642\u9593\u3002\u4f3a\u670d\u5668\u61c9\u6536\u5230\u5305\u542b\u8a0a\u606f\u4e8b\u4ef6\u7684 POST\u3002\u7528\u4e0b\u65b9\u7bc4\u4f8b\u6bd4\u5c0d\u6642\uff0cVerify \u7684\u65e5\u8a8c\u6703\u986f\u793a <code>events=0<\/code>\uff0c\u6587\u5b57\u8a0a\u606f\u6703\u51fa\u73fe <code>MessageEvent<\/code>\u3002\u5982\u679c\u65e5\u8a8c\u53ea\u6709\u9a57\u8b49\u8acb\u6c42\uff0c\u5148\u78ba\u8a8d\u624b\u6a5f\u4e0a\u7684\u5b98\u65b9\u5e33\u865f\u548c Console \u4e2d\u958b\u555f\u7684\u662f\u540c\u4e00\u500b channel\u3002<a href=\"https:\/\/developers.line.biz\/en\/docs\/messaging-api\/receiving-messages\/\" target=\"_blank\" rel=\"noopener\">LINE \u5b98\u65b9\u4e8b\u4ef6\u63a5\u6536\u8aaa\u660e<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%A9%97%E8%AD%89%E7%B0%BD%E7%AB%A0%EF%BC%8C%E5%8F%AA%E8%A8%98%E9%8C%84%E4%BA%8B%E4%BB%B6%E6%95%B8%E9%87%8F%E8%88%87%E9%A1%9E%E5%9E%8B\"><\/span>\u9a57\u8b49\u7c3d\u7ae0\uff0c\u53ea\u8a18\u9304\u4e8b\u4ef6\u6578\u91cf\u8207\u985e\u578b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5230\u8a72 channel \u7684 <strong>Basic settings<\/strong> \u78ba\u8a8d Channel secret\uff0c\u5b58\u9032\u6e2c\u8a66\u6216\u90e8\u7f72\u74b0\u5883\u7684\u5bc6\u9470\u8a2d\u5b9a\uff0c\u8b93\u61c9\u7528\u7a0b\u5f0f\u5f9e <code>LINE_CHANNEL_SECRET<\/code> \u8b80\u53d6\u3002\u6536\u5230\u8acb\u6c42\u5f8c\uff0c\u628a\u539f\u59cb UTF-8 \u5167\u5bb9\u548c <code>X-Line-Signature<\/code> \u539f\u6a23\u4ea4\u7d66 SDK\u3002\u82e5\u5148\u628a JSON \u8f49\u6210\u7269\u4ef6\u518d\u8f38\u51fa\uff0c\u7a7a\u767d\u3001\u63db\u884c\u6216\u8df3\u812b\u5b57\u5143\u90fd\u53ef\u80fd\u6539\u8b8a\uff0c\u5c0e\u81f4\u7c3d\u7ae0\u9a57\u8b49\u5931\u6557\u3002<a href=\"https:\/\/developers.line.biz\/en\/docs\/messaging-api\/verify-webhook-signature\/\" target=\"_blank\" rel=\"noopener\">LINE \u5b98\u65b9\u7c3d\u7ae0\u9a57\u8b49\u8aaa\u660e<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f Python 3.10 \u6216\u66f4\u65b0\u7248\u672c\u7684 Flask \u8a3a\u65b7\u7bc4\u4f8b\u3002\u5728\u6e2c\u8a66\u5c08\u6848\u5b89\u88dd\u4f9d\u8cf4\uff0c\u628a\u7a0b\u5f0f\u5b58\u6210 <code>app.py<\/code>\u3002\u672c\u6a5f\u7df4\u7fd2\u53ef\u7528\u81ea\u8a02\u7684\u6e2c\u8a66\u5bc6\u9470\u3002\u8981\u7528 Console \u7684 Verify \u6e2c\u8a66\uff0c\u8acb\u7531\u6e2c\u8a66\u74b0\u5883\u7684\u516c\u958b HTTPS \u7db2\u5740\u8f49\u9001\u5230\u9019\u500b\u8def\u7531\uff0c\u4e26\u6ce8\u5165\u5c0d\u61c9 channel \u7684\u5bc6\u9470\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -m pip install Flask \"line-bot-sdk&gt;=3,&lt;4\"<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>import logging\nimport os\n\nfrom flask import Flask, request\nfrom linebot.v3 import WebhookParser\nfrom linebot.v3.exceptions import InvalidSignatureError\n\napp = Flask(__name__)\napp.logger.setLevel(logging.INFO)\nparser = WebhookParser(os.environ[\"LINE_CHANNEL_SECRET\"])\n\n\n@app.post(\"\/callback\")\ndef callback():\n    signature = request.headers.get(\"X-Line-Signature\")\n    if not signature:\n        app.logger.warning(\"webhook signature missing\")\n        return \"\", 400\n\n    body = request.get_data(as_text=True)\n    try:\n        events = parser.parse(body, signature)\n    except InvalidSignatureError:\n        app.logger.warning(\"webhook signature invalid\")\n        return \"\", 400\n    except (ValueError, KeyError, TypeError):\n        app.logger.warning(\"webhook payload invalid\")\n        return \"\", 400\n\n    event_types = [type(event).__name__ for event in events]\n    app.logger.info(\"webhook events=%d types=%s\", len(events), event_types)\n    return \"\", 200<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u60f3\u5148\u78ba\u8a8d\u7bc4\u4f8b\u80fd\u555f\u52d5\uff0c\u5728\u5b58\u6709 <code>app.py<\/code> \u7684\u8cc7\u6599\u593e\u958b PowerShell\uff0c\u7528\u6e2c\u8a66\u5b57\u4e32\u555f\u52d5\u672c\u6a5f\u8a3a\u65b7\u670d\u52d9\u3002\u9019\u500b\u6307\u4ee4\u53ea\u4f9b\u672c\u6a5f\u958b\u767c\uff0c\u9023\u63a5 Console \u6642\u8acb\u4f7f\u7528\u4f60\u6e2c\u8a66\u74b0\u5883\u7684\u6b63\u5f0f WSGI \u670d\u52d9\u548c HTTPS \u5165\u53e3\u3002 <a href=\"https:\/\/flask.palletsprojects.com\/en\/stable\/deploying\/\" target=\"_blank\" rel=\"noopener\">Flask \u90e8\u7f72\u6587\u4ef6<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$env:LINE_CHANNEL_SECRET = 'local-demo-only'\npython -m flask --app app run --host 127.0.0.1 --port 5000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u65e5\u8a8c\u986f\u793a <code>webhook signature missing<\/code>\uff0c\u6aa2\u67e5\u53cd\u5411\u4ee3\u7406\u8f49\u9001\u6642\u662f\u5426\u4fdd\u7559\u8a72\u6a19\u982d\u3002\u5b98\u65b9 Verify \u9001\u4f86\u7684\u8acb\u6c42\u82e5\u986f\u793a <code>webhook signature invalid<\/code>\uff0c\u6838\u5c0d\u90e8\u7f72\u74b0\u5883\u662f\u5426\u8f09\u5165\u6b64 channel \u7684 secret\uff0c\u4e5f\u78ba\u8a8d\u61c9\u7528\u7a0b\u5f0f\u548c\u4ee3\u7406\u6709\u4fdd\u7559\u539f\u59cb\u5167\u5bb9\u3002\u53ea\u8a18\u9304\u932f\u8aa4\u985e\u578b\u8207\u4e8b\u4ef6\u6578\u91cf\uff0c\u907f\u514d\u628a\u7c3d\u7ae0\u3001\u5bc6\u9470\u3001\u8a0a\u606f\u672c\u6587\u6216\u6b0a\u6756\u5beb\u5165\u65e5\u8a8c\u3002<a href=\"https:\/\/developers.line.biz\/en\/docs\/messaging-api\/verify-webhook-signature\/#common-signature-verification-failures-and-their-solutions\" target=\"_blank\" rel=\"noopener\">LINE \u5b98\u65b9\u5e38\u898b\u7c3d\u7ae0\u932f\u8aa4<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%94%A8_Webhook_errors_%E5%B0%8D%E7%85%A7%E4%BC%BA%E6%9C%8D%E5%99%A8%E6%97%A5%E8%AA%8C\"><\/span>\u7528 Webhook errors \u5c0d\u7167\u4f3a\u670d\u5668\u65e5\u8a8c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u540c\u4e00\u500b channel \u7684 <strong>Messaging API<\/strong> \u5206\u9801\u6253\u958b <strong>Use webhook<\/strong> \u548c <strong>Error statistics aggregation<\/strong>\uff0c\u518d\u5230 <strong>Webhook errors<\/strong> \u5206\u9801\u770b\u7d71\u8a08\u3002\u7cfb\u7d71\u5f9e\u555f\u7528\u6642\u958b\u59cb\u8a18\u9304\u6b63\u5f0f\u4e8b\u4ef6\u7684\u50b3\u9001\u932f\u8aa4\u3002\u62ff Console \u7684\u6642\u9593\u5c0d\u7167\u53f0\u7063\u6642\u9593\u6642\uff0cUTC+9 \u8981\u6e1b\u4e00\u5c0f\u6642\u3002<a href=\"https:\/\/developers.line.biz\/en\/docs\/messaging-api\/check-webhook-error-statistics\/\" target=\"_blank\" rel=\"noopener\">LINE \u5b98\u65b9 Webhook \u932f\u8aa4\u7d71\u8a08\u8aaa\u660e<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>could_not_connect<\/code> \u8868\u793a LINE \u9023\u4e0d\u5230\u63a5\u6536\u7aef\u3002\u4f9d\u932f\u8aa4\u7d30\u7bc0\u6aa2\u67e5 DNS \u89e3\u6790\u3001TLS \u6191\u8b49\u93c8\u548c\u5165\u53e3\u4ee3\u7406\u3002<\/li>\n\n\n\n<li><code>request_timeout<\/code> \u8868\u793a LINE \u5728\u5169\u79d2\u5167\u672a\u6536\u5230\u56de\u61c9\u3002\u8acb\u5148\u770b\u61c9\u7528\u7a0b\u5f0f\u662f\u5426\u5df2\u6536\u5230\u4e8b\u4ef6\u3002\u6b63\u5f0f\u7a0b\u5f0f\u53ef\u5728\u9a57\u7c3d\u4e26\u53ef\u9760\u6536\u4ef6\u5f8c\u56de\u61c9 <code>200<\/code>\uff0c\u518d\u4ea4\u7531\u80cc\u666f\u5de5\u4f5c\u8655\u7406\u8017\u6642\u7684\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li><code>error_status_code<\/code> \u8868\u793a\u63a5\u6536\u7aef\u56de\u50b3\u4e86\u932f\u8aa4\u72c0\u614b\u3002\u770b\u5230 404 \u6216 405 \u6642\u6838\u5c0d\u7db2\u5740\u548c POST \u8def\u7531\u3002\u770b\u5230 400 \u6642\u770b\u7c3d\u7ae0\u5224\u65b7\u3002\u770b\u5230 500 \u6642\u67e5\u61c9\u7528\u7a0b\u5f0f\u7684\u4f8b\u5916\u65e5\u8a8c\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%B7%B2%E6%94%B6%E5%88%B0_MessageEvent%EF%BC%8C%E5%86%8D%E6%9F%A5%E5%9B%9E%E8%A6%86_API\"><\/span>\u5df2\u6536\u5230 MessageEvent\uff0c\u518d\u67e5\u56de\u8986 API<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u65e5\u8a8c\u51fa\u73fe <code>MessageEvent<\/code> \u5f8c\uff0c\u67e5\u770b\u6587\u5b57\u8a0a\u606f\u6709\u6c92\u6709\u9032\u5165\u4f60\u7684\u8655\u7406\u51fd\u5f0f\uff0c\u4ee5\u53ca\u7a0b\u5f0f\u547c\u53eb <code>POST \/v2\/bot\/message\/reply<\/code> \u5f97\u5230\u4ec0\u9ebc\u72c0\u614b\u78bc\u3002Channel secret \u7528\u65bc\u9a57\u8b49\u6536\u5230\u7684 Webhook\u3002Channel access token \u7528\u65bc\u5411 Messaging API \u767c\u9001\u56de\u8986\u3002<code>replyToken<\/code> \u5247\u4f86\u81ea\u53ef\u56de\u8986\u7684\u90a3\u7b46\u4e8b\u4ef6\uff0c\u53ea\u80fd\u7528\u4e00\u6b21\uff0c\u61c9\u5118\u5feb\u4f7f\u7528\u3002<a href=\"https:\/\/developers.line.biz\/en\/reference\/messaging-api\/nojs\/#send-reply-message\" target=\"_blank\" rel=\"noopener\">LINE \u5b98\u65b9\u56de\u8986\u8a0a\u606f\u898f\u683c<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56de\u8986 API \u56de\u50b3 401 \u6642\uff0c\u5148\u78ba\u8a8d\u7a0b\u5f0f\u6709\u5e36\u4e0a\u6709\u6548\u7684 Channel access token\u3002\u82e5\u932f\u8aa4\u8a0a\u606f\u6307\u51fa <code>Invalid reply token<\/code>\uff0c\u6bd4\u5c0d\u662f\u5426\u7528\u4e86\u53e6\u4e00\u7b46\u4e8b\u4ef6\u7684\u6b0a\u6756\u3001\u5df2\u56de\u8986\u904e\u6216\u7b49\u592a\u4e45\u624d\u4f7f\u7528\u3002\u8a18\u9304\u56de\u8986 API \u7684\u72c0\u614b\u78bc\u8207 <code>x-line-request-id<\/code>\uff0c\u4fbf\u65bc\u67e5\u8a62\u8a72\u6b21\u547c\u53eb\u3002<a href=\"https:\/\/github.com\/line\/line-bot-sdk-python#how-to-get-x-line-request-id-header-and-error-message\" target=\"_blank\" rel=\"noopener\">Python SDK \u7684\u56de\u61c9\u8ffd\u8e64\u8aaa\u660e<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SDK_%E4%BE%86%E6%BA%90%E8%88%87%E5%BB%B6%E4%BC%B8%E9%96%B1%E8%AE%80\"><\/span>SDK \u4f86\u6e90\u8207\u5ef6\u4f38\u95b1\u8b80<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7bc4\u4f8b\u4f7f\u7528 LY Corporation \u63d0\u4f9b\u7684\u5b98\u65b9\u958b\u6e90 LINE Messaging API SDK for Python\u3002\u5957\u4ef6\u4f5c\u8005\u8207\u7dad\u8b77\u8005\u6b04\u4f4d\u767b\u8f09\u70ba RyosukeHasebe\u3002\u5c08\u6848\u63a1 Apache License 2.0 \u6388\u6b0a\uff0c<code>LICENSE<\/code> \u4fdd\u7559 2016 \u5e74 LINE Corporation \u7684\u6b77\u53f2\u7248\u6b0a\u6a19\u793a\u3002<a href=\"https:\/\/developers.line.biz\/en\/tips\/2026\/06\/04\/messaging-api-sdk\/\" target=\"_blank\" rel=\"noopener\">LY Corporation \u7684\u5b98\u65b9 SDK \u8aaa\u660e<\/a>\u3001<a href=\"https:\/\/github.com\/line\/line-bot-sdk-python\" target=\"_blank\" rel=\"noopener\">\u5b98\u65b9 Python SDK \u5c08\u6848<\/a>\u3001<a href=\"https:\/\/pypi.org\/project\/line-bot-sdk\/#metadata\" target=\"_blank\" rel=\"noopener\">PyPI \u5957\u4ef6\u8cc7\u8a0a<\/a>\u3001<a href=\"https:\/\/github.com\/line\/line-bot-sdk-python\/blob\/master\/LICENSE\" target=\"_blank\" rel=\"noopener\">\u5c08\u6848\u6388\u6b0a<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7bc4\u4f8b\u7684 HTTP \u8def\u7531\u4f7f\u7528 Pallets \u5718\u968a\u7dad\u8b77\u7684 Flask\uff0c\u63a1 BSD 3-Clause \u6388\u6b0a\u3002\u8a3a\u65b7\u7a0b\u5f0f\u7528 Python SDK 3.27.0 \u548c\u672c\u6a5f\u6a21\u64ec\u8acb\u6c42\u9a57\u8b49\uff0c\u6db5\u84cb\u7a7a\u4e8b\u4ef6\u3001\u6587\u5b57\u4e8b\u4ef6\u8207\u7c3d\u7ae0\u932f\u8aa4\u3002\u5be6\u969b LINE Console \u9001\u9054\u8981\u5728\u81ea\u5df1\u7684\u6e2c\u8a66 channel \u78ba\u8a8d\u3002 <a href=\"https:\/\/github.com\/pallets\/flask\" target=\"_blank\" rel=\"noopener\">Flask \u539f\u59cb\u78bc<\/a> \u00b7 <a href=\"https:\/\/flask.palletsprojects.com\/en\/stable\/license\/\" target=\"_blank\" rel=\"noopener\">Flask \u6388\u6b0a<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6b63\u5728\u5f9e\u982d\u642d\u5efa\uff0c\u53ef\u63a5\u8457\u770b\u7ad9\u5167\u7684 <a href=\"https:\/\/wp.chih-hao.synology.me\/?p=47\">\u5b89\u88dd\u74b0\u5883<\/a>\u3001<a href=\"https:\/\/wp.chih-hao.synology.me\/?p=61\">\u7533\u8acb LINE \u5b98\u65b9\u5e33\u865f<\/a>\u3001<a href=\"https:\/\/wp.chih-hao.synology.me\/?p=68\">Python LINE Bot \u7b2c\u4e09\u7bc7<\/a>\u8207<a href=\"https:\/\/wp.chih-hao.synology.me\/?p=323\">\u7b2c\u56db\u7bc7<\/a>\u3002<\/p>\n\n\n\n\n<nav class=\"tt5-series-nav\" id=\"series-navigation\" aria-label=\"LINE Bot \u7cfb\u5217\u5c0e\u89bd\">\n<p class=\"tt5-series-nav__title\">LINE Bot \u7cfb\u5217\u5c0e\u89bd<\/p>\n<div class=\"tt5-series-nav__steps\"><a class=\"tt5-series-nav__step\" href=\"\/?p=323\" rel=\"prev\"><span class=\"tt5-series-nav__direction\">\u4e0a\u4e00\u7bc7<\/span> <strong class=\"tt5-series-nav__destination\">\u8b93\u6a5f\u5668\u4eba\u56de\u8986\u8cbc\u5716<\/strong><\/a> <a class=\"tt5-series-nav__step\" href=\"\/?p=655\" rel=\"next\"><span class=\"tt5-series-nav__direction\">\u4e0b\u4e00\u7bc7<\/span> <strong class=\"tt5-series-nav__destination\">\u4e0a\u50b3\u81ea\u88fd\u5716\u7247\u8207\u8a2d\u5b9a\u9ede\u64ca\u5340<\/strong><\/a><\/div>\n<div class=\"tt5-series-nav__return\"><a href=\"\/?page_id=16#line-bot\">\u56de\u6559\u5b78\u5c0e\u8b80<\/a><\/div>\n<\/nav>\n","protected":false},"excerpt":{"rendered":"<p>LINE Bot \u6536\u4e0d\u5230\u8a0a\u606f\u6642\uff0c\u5148\u5230 LINE Developers Console \u6309\u4e00\u6b21 Verify\uff0c\u518d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-647","post","type-post","status-publish","format-standard","hentry","category-line-bot"],"_links":{"self":[{"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=647"}],"version-history":[{"count":2,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/647\/revisions"}],"predecessor-version":[{"id":681,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/647\/revisions\/681"}],"wp:attachment":[{"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}