{"id":441566,"date":"2025-05-07T09:18:23","date_gmt":"2025-05-07T01:18:23","guid":{"rendered":"https:\/\/www.idc.net\/help\/?p=441566"},"modified":"2025-05-07T09:18:23","modified_gmt":"2025-05-07T01:18:23","slug":"%e5%a6%82%e4%bd%95%e5%b0%86-coze-%e6%99%ba%e8%83%bd%e4%bd%93%e9%9b%86%e6%88%90%e8%87%b3%e5%89%8d%e7%ab%af%e7%b3%bb%e7%bb%9f%ef%bc%9a%e5%bc%80%e5%8f%91%e6%8c%87%e5%8d%97%e4%b8%8e%e9%a6%99%e6%b8%af","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/441566\/","title":{"rendered":"\u5982\u4f55\u5c06 Coze \u667a\u80fd\u4f53\u96c6\u6210\u81f3\u524d\u7aef\u7cfb\u7edf\uff1a\u5f00\u53d1\u6307\u5357\u4e0e\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u90e8\u7f72\u5efa\u8bae"},"content":{"rendered":"<h2>\u4e00\u3001\u6ce8\u518c Coze \u5e73\u53f0\u4e0e\u51c6\u5907\u5f00\u53d1\u73af\u5883<\/h2>\n<p>\u5728\u96c6\u6210 Coze \u667a\u80fd\u4f53\u524d\uff0c\u5f00\u53d1\u8005\u9996\u5148\u9700\u5b8c\u6210\u4ee5\u4e0b\u51c6\u5907\u5de5\u4f5c\uff1a<\/p>\n<ol>\n<li><strong>\u6ce8\u518c\u8d26\u53f7\u4e0e\u767b\u5f55<\/strong>\uff1a\u8bbf\u95ee Coze \u5b98\u65b9\u5e73\u53f0\uff0c\u521b\u5efa\u5f00\u53d1\u8005\u8d26\u53f7\u5e76\u767b\u5f55\uff1b<\/li>\n<li><strong>\u521b\u5efa\u667a\u80fd\u4f53\uff08Bot\uff09<\/strong>\uff1a\u5728 Coze \u63a7\u5236\u53f0\u4e2d\u65b0\u5efa\u667a\u80fd\u4f53\uff0c\u8bbe\u5b9a\u529f\u80fd\uff0c\u5982\u610f\u56fe\u8bc6\u522b\u3001\u4e0a\u4e0b\u6587\u5bf9\u8bdd\u7b49\uff1b<\/li>\n<li><strong>\u83b7\u53d6 API Token<\/strong>\uff1a\u524d\u5f80\u5f00\u53d1\u8005\u4e2d\u5fc3\u751f\u6210\u8bbf\u95ee\u4ee4\u724c\uff08API Key\uff09\uff0c\u4fdd\u5b58\u597d\u4ec5\u663e\u793a\u4e00\u6b21\u7684\u5bc6\u94a5\u3002<\/li>\n<\/ol>\n<blockquote><p>\u5efa\u8bae\u4f7f\u7528\u6027\u80fd\u7a33\u5b9a\u7684<strong>\u9999\u6e2fVPS<\/strong>\u8fdb\u884c\u5f00\u53d1\u4e0e\u8c03\u8bd5\uff0c\u4e0d\u4ec5\u53ef\u52a0\u5feb API \u8c03\u7528\u54cd\u5e94\u901f\u5ea6\uff0c\u8fd8\u80fd\u89c4\u907f\u5927\u9646\u8bbf\u95ee\u5883\u5916\u670d\u52a1\u65f6\u7684\u5ef6\u8fdf\u95ee\u9898\u3002<\/p><\/blockquote>\n<h2>\u4e8c\u3001\u4e86\u89e3 Coze API \u63a5\u53e3\u89c4\u8303<\/h2>\n<p>\u5728\u5f00\u59cb\u7f16\u7a0b\u524d\uff0c\u5fc5\u987b\u719f\u6089 Coze API \u7684\u57fa\u672c\u7ed3\u6784\u548c\u4f7f\u7528\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li><strong>API \u5730\u5740<\/strong>\uff1a\u5982 <code>https:\/\/api.coze.com\/v1\/chat<\/code><\/li>\n<li><strong>\u8bf7\u6c42\u65b9\u6cd5<\/strong>\uff1a\u4e00\u822c\u4f7f\u7528 <code>POST<\/code><\/li>\n<li><strong>\u8bf7\u6c42\u5934\u4fe1\u606f<\/strong>\uff1a\u5305\u62ec <code>Authorization: Bearer &lt;API_KEY&gt;<\/code> \u4e0e <code>Content-Type: application\/json<\/code><\/li>\n<li><strong>\u8bf7\u6c42\u4f53\u683c\u5f0f<\/strong>\uff1a\u901a\u5e38\u4e3a JSON \u683c\u5f0f\uff0c\u5305\u542b <code>input<\/code>\uff08\u7528\u6237\u8f93\u5165\uff09\u3001<code>session_id<\/code>\uff08\u4f1a\u8bddID\uff09\u7b49\u5b57\u6bb5<\/li>\n<li><strong>\u54cd\u5e94\u683c\u5f0f<\/strong>\uff1aJSON\uff0c\u8fd4\u56de\u7ed3\u6784\u5305\u542b\u667a\u80fd\u4f53\u56de\u590d\u3001\u72b6\u6001\u7801\u7b49\u4fe1\u606f<\/li>\n<\/ul>\n<h2>\u4e09\u3001\u524d\u7aef\u9879\u76ee\u4e2d\u7684\u96c6\u6210\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u4e3a JavaScript \u73af\u5883\u4e0b\u901a\u8fc7 <code>fetch<\/code> \u5b9e\u73b0 Coze API \u8c03\u7528\u7684\u57fa\u672c\u65b9\u5f0f\uff1a<\/p>\n<pre><code class=\"language-javascript\">const apiKey = 'YOUR_API_KEY';\r\nconst apiUrl = 'https:\/\/api.coze.com\/v1\/chat';\r\n\r\nasync function sendMessageToCoze(message) {\r\n  try {\r\n    const response = await fetch(apiUrl, {\r\n      method: 'POST',\r\n      headers: {\r\n        'Content-Type': 'application\/json',\r\n        'Authorization': `Bearer ${apiKey}`\r\n      },\r\n      body: JSON.stringify({\r\n        input: message,\r\n        session_id: 'user_123'\r\n      })\r\n    });\r\n\r\n    const data = await response.json();\r\n    return data.response;\r\n  } catch (error) {\r\n    console.error('Error:', error);\r\n    return null;\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u6b64\u65b9\u6cd5\u9002\u7528\u4e8e\u76f4\u63a5\u4ece\u524d\u7aef\u53d1\u9001\u8bf7\u6c42\uff0c\u4f46\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u5e94\u907f\u514d\u66b4\u9732 API Key\u3002<\/p>\n<h2>\u56db\u3001\u89e3\u51b3\u8de8\u57df\u95ee\u9898\u4e0e\u540e\u7aef\u4ee3\u7406\u8bbe\u7f6e<\/h2>\n<p>\u5f53 API \u4e0d\u652f\u6301 CORS \u65f6\uff0c\u53ef\u901a\u8fc7 Node.js \u8bbe\u7f6e\u4ee3\u7406\u670d\u52a1\u5668\uff1a<\/p>\n<pre><code class=\"language-javascript\">const express = require('express');\r\nconst axios = require('axios');\r\nconst app = express();\r\nconst apiKey = 'YOUR_API_KEY';\r\n\r\napp.use(express.json());\r\n\r\napp.post('\/proxy\/coze', async (req, res) =&gt; {\r\n  try {\r\n    const response = await axios.post('https:\/\/api.coze.com\/v1\/chat', req.body, {\r\n      headers: {\r\n        'Authorization': `Bearer ${apiKey}`,\r\n        'Content-Type': 'application\/json'\r\n      }\r\n    });\r\n    res.json(response.data);\r\n  } catch (error) {\r\n    res.status(500).json({ error: 'Proxy error' });\r\n  }\r\n});\r\n\r\napp.listen(3000, () =&gt; console.log('Proxy server running on port 3000'));\r\n<\/code><\/pre>\n<p>\u4ee3\u7406\u90e8\u7f72\u63a8\u8350\u4f7f\u7528<strong>\u9999\u6e2f\u72ec\u7acb\u670d\u52a1\u5668<\/strong>\uff0c\u5728\u7a33\u5b9a\u6027\u3001\u5b89\u5168\u6027\u548c\u56fd\u9645\u5e26\u5bbd\u65b9\u9762\u4f18\u52bf\u660e\u663e\uff0c\u9002\u5408\u4f01\u4e1a\u7ea7\u667a\u80fd\u7cfb\u7edf\u3002<\/p>\n<h2>\u4e94\u3001\u6700\u4f73\u5b9e\u8df5\u4e0e\u5b89\u5168\u5efa\u8bae<\/h2>\n<p>\u4e3a\u4e86\u4fdd\u969c\u7cfb\u7edf\u7684\u53ef\u9760\u6027\u4e0e\u5b89\u5168\u6027\uff0c\u5e94\u9075\u5faa\u4ee5\u4e0b\u5f00\u53d1\u5efa\u8bae\uff1a<\/p>\n<ul>\n<li><strong>\u4ee4\u724c\u4fdd\u62a4<\/strong>\uff1aAPI Token \u5e94\u5b58\u50a8\u5728\u670d\u52a1\u7aef\uff0c\u907f\u514d\u524d\u7aef\u786c\u7f16\u7801\uff1b<\/li>\n<li><strong>\u8f93\u5165\u6821\u9a8c<\/strong>\uff1a\u9632\u6b62\u7528\u6237\u6076\u610f\u8f93\u5165\u5bfc\u81f4\u7684\u6ce8\u5165\u6216\u5f02\u5e38\uff1b<\/li>\n<li><strong>\u9519\u8bef\u5904\u7406<\/strong>\uff1a\u8bbe\u7f6e\u5bf9 429 \u9650\u6d41\u30015xx \u670d\u52a1\u5f02\u5e38\u7b49\u9519\u8bef\u7684\u5904\u7406\u903b\u8f91\uff1b<\/li>\n<li><strong>\u4f1a\u8bdd\u7ba1\u7406<\/strong>\uff1a\u4f7f\u7528 <code>session_id<\/code> \u5b9e\u73b0\u4e0a\u4e0b\u6587\u8fde\u7eed\u5bf9\u8bdd\uff1b<\/li>\n<li><strong>\u6d41\u5f0f\u8f93\u51fa<\/strong>\uff1a\u5bf9\u4e8e\u957f\u5bf9\u8bdd\u53ef\u542f\u7528 WebSocket \u6216 SSE \u5904\u7406\u5b9e\u65f6\u8fd4\u56de\u3002<\/li>\n<\/ul>\n<h2>\u516d\u3001\u90e8\u7f72\u63a8\u8350\uff1a\u9999\u6e2f\u670d\u52a1\u5668\u52a9\u529b AI \u5e94\u7528\u4e0a\u7ebf<\/h2>\n<p>AI \u667a\u80fd\u4f53\u5bf9\u7cfb\u7edf\u7684\u7f51\u7edc\u7a33\u5b9a\u6027\u4e0e\u54cd\u5e94\u901f\u5ea6\u8981\u6c42\u6781\u9ad8\uff0c\u9009\u62e9\u5408\u9002\u7684\u90e8\u7f72\u5e73\u53f0\u5c24\u4e3a\u5173\u952e\u3002\u76f8\u6bd4\u5185\u5730\u670d\u52a1\u5668\uff0c<strong>\u9999\u6e2f\u4e91\u670d\u52a1\u5668<\/strong>\u65e0\u9700\u5907\u6848\u3001\u5e26\u5bbd\u56fd\u9645\u76f4\u8fde\uff0c\u6781\u5927\u63d0\u5347\u4e86\u8bbf\u95ee\u901f\u5ea6\u4e0e\u90e8\u7f72\u6548\u7387\uff0c\u7528\u6237\u53ef\u9009\u62e9\u9ad8\u6027\u80fd <strong>\u9999\u6e2fVPS<\/strong>\u3001\u9ad8\u53ef\u7528 <strong>\u9999\u6e2f\u72ec\u7acb\u670d\u52a1\u5668<\/strong> \u7b49\u591a\u79cd\u65b9\u6848\uff0c\u652f\u6301\u5f39\u6027\u914d\u7f6e\u4e0e\u5feb\u901f\u4ea4\u4ed8\uff0c\u9002\u5408\u5404\u7c7b\u524d\u7aef\u96c6\u6210\u573a\u666f\u3002<\/p>\n<h2>\u7ed3\u8bed<\/h2>\n<p>\u901a\u8fc7\u672c\u6587\u4ecb\u7ecd\u7684\u6280\u672f\u6d41\u7a0b\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5feb\u901f\u5c06 Coze \u667a\u80fd\u4f53\u96c6\u6210\u8fdb\u7f51\u9875\u3001\u5e94\u7528\u7b49\u524d\u7aef\u7cfb\u7edf\u4e2d\uff0c\u63d0\u5347\u4ea4\u4e92\u4f53\u9a8c\u548c\u667a\u80fd\u5316\u7a0b\u5ea6\u3002\u7ed3\u5408 <a href=\"https:\/\/idc.net\/\"><strong>\u9999\u6e2f\u670d\u52a1\u5668<\/strong><\/a> \u7684\u4f18\u8d8a\u6027\u80fd\uff0c\u60a8\u7684 AI \u9879\u76ee\u5c06\u62e5\u6709\u66f4\u9ad8\u7684\u8fd0\u884c\u6548\u7387\u4e0e\u670d\u52a1\u8d28\u91cf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6ce8\u518c Coze \u5e73\u53f0\u4e0e\u51c6\u5907\u5f00\u53d1\u73af\u5883 \u5728\u96c6\u6210 Coze \u667a\u80fd\u4f53\u524d\uff0c\u5f00\u53d1\u8005\u9996\u5148\u9700\u5b8c\u6210\u4ee5\u4e0b\u51c6\u5907\u5de5\u4f5c\uff1a \u6ce8\u518c\u8d26\u53f7\u4e0e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7023],"tags":[],"class_list":["post-441566","post","type-post","status-publish","format-standard","hentry","category-chatgpt"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/441566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=441566"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/441566\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=441566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=441566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=441566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}