{"id":6667,"date":"2026-04-29T12:19:38","date_gmt":"2026-04-29T04:19:38","guid":{"rendered":"https:\/\/www.babel.cc\/blog\/?p=6667"},"modified":"2026-04-29T12:19:38","modified_gmt":"2026-04-29T04:19:38","slug":"%e4%bc%81%e4%b8%9a%e4%ba%91%e7%9b%98api%e9%9b%86%e6%88%90%e6%8c%87%e5%8d%97%ef%bc%9a%e5%a6%82%e4%bd%95%e4%b8%8ecicd%e6%b5%81%e6%b0%b4%e7%ba%bf%e6%89%93%e9%80%9a","status":"publish","type":"post","link":"https:\/\/www.babel.cc\/blog\/?p=6667","title":{"rendered":"\u4f01\u4e1a\u4e91\u76d8API\u96c6\u6210\u6307\u5357\uff1a\u5982\u4f55\u4e0eCI\/CD\u6d41\u6c34\u7ebf\u6253\u901a"},"content":{"rendered":"<p>\u6280\u672f\u56e2\u961f\u9009\u62e9\u4f01\u4e1a\u4e91\u76d8\uff0c\u6700\u7ec8\u90fd\u4f1a\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff1a<strong>\u5982\u4f55\u4e0e\u73b0\u6709\u5de5\u5177\u94fe\u96c6\u6210<\/strong>\u3002\u6ca1\u6709API\u7684\u4e91\u76d8\u4ea7\u54c1\uff0c\u6bcf\u6b21\u7ec4\u7ec7\u67b6\u6784\u8c03\u6574\u90fd\u9700\u8981\u7ba1\u7406\u5458\u624b\u52a8\u7ef4\u62a4\uff0c\u6548\u7387\u4f4e\u4e0b\u4e14\u5bb9\u6613\u51fa\u9519\u3002<\/p>\n<hr \/>\n<h2>\u4e00\u3001\u4e3a\u4ec0\u4e48API\u96c6\u6210\u5982\u6b64\u91cd\u8981<\/h2>\n<p>\u5de5\u7a0b\u5e08\u65e5\u5e38\u5de5\u4f5c\u5728GitLab\/Jenkins\/GitHub\u7b49\u5de5\u5177\u94fe\u4e2d\uff0c\u6587\u4ef6\u7ba1\u7406\u53ea\u662f\u5176\u4e2d\u4e00\u73af\u3002\u7406\u60f3\u72b6\u6001\u662f\uff1a<\/p>\n<ul>\n<li>\u4ee3\u7801\u63d0\u4ea4\u81ea\u52a8\u89e6\u53d1\u8bbe\u8ba1\u6587\u6863\u540c\u6b65<\/li>\n<li>CI\/CD\u6d41\u6c34\u7ebf\u4ea7\u51fa\u7269\u81ea\u52a8\u5f52\u6863\u5230\u4e91\u76d8<\/li>\n<li>\u7ec4\u7ec7\u67b6\u6784\u53d8\u66f4\u81ea\u52a8\u540c\u6b65\u5230\u4e91\u76d8\u6743\u9650\u4f53\u7cfb<\/li>\n<\/ul>\n<p>\u6ca1\u6709API\u7684\u4e91\u76d8\u610f\u5473\u7740\u6240\u6709\u8fd9\u4e9b\u90fd\u9700\u8981\u624b\u52a8\u64cd\u4f5c\uff0c\u6216\u8005\u6839\u672c\u505a\u4e0d\u5230\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u3001\u6838\u5fc3API\u80fd\u529b\u89e3\u6790<\/h2>\n<h3>1. \u7528\u6237\u76ee\u5f55\u540c\u6b65<\/h3>\n<p>\u4e0e\u4f01\u4e1a\u5fae\u4fe1\u3001\u9489\u9489\u3001\u98de\u4e66\u3001LDAP\/AD\u7ec4\u7ec7\u67b6\u6784\u540c\u6b65\uff1a<\/p>\n<pre><code class=\"language-python\"># \u5df4\u522b\u9e1f\u7528\u6237\u540c\u6b65\u793a\u4f8b\r\nimport requests\r\n\r\n# \u83b7\u53d6\u4f01\u4e1a\u7528\u6237\u5217\u8868\r\nusers = requests.get(\r\n    &quot;https:\/\/api.babel.cc\/v1\/users&quot;,\r\n    headers={&quot;Authorization&quot;: &quot;Bearer YOUR_API_KEY&quot;}\r\n).json()\r\n\r\n# \u540c\u6b65\u5230\u5df4\u522b\u9e1f\r\nfor dept in org_chart:\r\n    requests.post(\r\n        &quot;https:\/\/api.babel.cc\/v1\/departments&quot;,\r\n        json=dept\r\n    )\r\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u529f\u80fd\u5bf9\u4e8e50\u4eba\u4ee5\u4e0a\u7684\u4f01\u4e1a\u975e\u5e38\u91cd\u8981\uff0c\u6bcf\u6b21\u5458\u5de5\u5165\u804c\u3001\u8f6c\u5c97\u3001\u79bb\u804c\u90fd\u9700\u8981\u540c\u6b65\u8c03\u6574\u3002<\/p>\n<h3>2. \u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d<\/h3>\n<pre><code class=\"language-python\"># \u5927\u6587\u4ef6\u76f4\u63a5\u4e0a\u4f20\r\nwith open(&quot;design_file.dwg&quot;, &quot;rb&quot;) as f:\r\n    requests.post(\r\n        &quot;https:\/\/api.babel.cc\/v1\/files\/upload&quot;,\r\n        files={&quot;file&quot;: f},\r\n        headers={&quot;Authorization&quot;: &quot;Bearer YOUR_API_KEY&quot;}\r\n    )\r\n<\/code><\/pre>\n<p>CI\/CD\u6d41\u6c34\u7ebf\u4ea7\u51fa\u7684\u6784\u5efa\u4ea7\u7269\u53ef\u4ee5\u76f4\u63a5\u5f52\u6863\uff0c\u4e0d\u9700\u8981\u4eba\u5de5\u5e72\u9884\u3002<\/p>\n<h3>3. \u6743\u9650\u53d8\u66f4\u901a\u77e5<\/h3>\n<p>\u7ec4\u7ec7\u67b6\u6784\u8c03\u6574\u65f6\uff0c\u81ea\u52a8\u89e6\u53d1\u6743\u9650\u53d8\u66f4\uff1a<\/p>\n<pre><code class=\"language-python\"># \u5458\u5de5\u79bb\u804c\uff0c\u81ea\u52a8\u6536\u56de\u6743\u9650\r\ndef on_employee_leave(employee_id):\r\n    requests.post(\r\n        &quot;https:\/\/api.babel.cc\/v1\/users\/revoke&quot;,\r\n        json={&quot;user_id&quot;: employee_id}\r\n    )\r\n<\/code><\/pre>\n<hr \/>\n<h2>\u4e09\u3001\u4e0e\u4e3b\u6d41\u5de5\u5177\u94fe\u96c6\u6210\u5b9e\u6218<\/h2>\n<h3>GitLab CI\/CD\u96c6\u6210<\/h3>\n<pre><code class=\"language-yaml\"># .gitlab-ci.yml\r\narchive_artifacts:\r\n  stage: deploy\r\n  script:\r\n    - curl -X POST https:\/\/api.babel.cc\/v1\/files\/upload \\\r\n      -H &quot;Authorization: Bearer $BABEL_API_KEY&quot; \\\r\n      -F &quot;file=@build\/output.zip&quot; \\\r\n      -F &quot;path=\/ci-artifacts\/${CI_COMMIT_SHA}&quot;\r\n  only:\r\n    - main\r\n<\/code><\/pre>\n<p>\u6784\u5efa\u6210\u529f\u81ea\u52a8\u5f52\u6863\uff0c\u6bcf\u6b21\u53d1\u5e03\u90fd\u6709\u5b8c\u6574\u8bb0\u5f55\u3002<\/p>\n<h3>Jenkins Pipeline\u96c6\u6210<\/h3>\n<pre><code class=\"language-groovy\">pipeline {\r\n    stages {\r\n        stage('Archive') {\r\n            steps {\r\n                sh '''\r\n                    curl -X POST https:\/\/api.babel.cc\/v1\/files\/upload \\\r\n                    -H &quot;Authorization: Bearer ${BABEL_API_KEY}&quot; \\\r\n                    -F &quot;file=@dist\/${BUILD_NUMBER}.zip&quot; \\\r\n                    -F &quot;path=\/jenkins\/${JOB_NAME}\/${BUILD_NUMBER}&quot;\r\n                '''\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n<hr \/>\n<h2>\u56db\u3001\u96c6\u6210\u80fd\u529b\u5bf9\u6bd4<\/h2>\n<table>\n<thead>\n<tr>\n<th>API\u80fd\u529b<\/th>\n<th>\u5df4\u522b\u9e1f<\/th>\n<th>\u8054\u60f3Filez<\/th>\n<th>\u4f01\u5fae\u4e91\u76d8<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u7528\u6237\u540c\u6b65<\/td>\n<td>\u2705 RESTful<\/td>\n<td>\u2705 SOAP<\/td>\n<td>\u2705 \u4f01\u5faeAPI<\/td>\n<\/tr>\n<tr>\n<td>\u6587\u4ef6\u4e0a\u4f20<\/td>\n<td>\u2705 \u652f\u630150GB<\/td>\n<td>\u2705 \u6700\u592710GB<\/td>\n<td>\u2705 \u6700\u59275GB<\/td>\n<\/tr>\n<tr>\n<td>\u6743\u9650\u7ba1\u7406<\/td>\n<td>\u2705 \u5b8c\u6574API<\/td>\n<td>\u2705 \u90e8\u5206API<\/td>\n<td>\u274c \u4ec5\u57fa\u7840<\/td>\n<\/tr>\n<tr>\n<td>Webhook<\/td>\n<td>\u2705 \u652f\u6301<\/td>\n<td>\u274c \u4e0d\u652f\u6301<\/td>\n<td>\u274c \u4e0d\u652f\u6301<\/td>\n<\/tr>\n<tr>\n<td>\u5f00\u653e\u5e73\u53f0<\/td>\n<td>\u2705 \u5f00\u653e\u6ce8\u518c<\/td>\n<td>\u274c \u4ec5\u4f01\u4e1a<\/td>\n<td>\u274c \u4ec5\u96c6\u6210<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>\u4e94\u3001\u6700\u4f73\u5b9e\u8df5<\/h2>\n<ol>\n<li><strong>\u5148\u505a\u7528\u6237\u76ee\u5f55\u540c\u6b65<\/strong>\uff1a\u6240\u6709\u6743\u9650\u7ba1\u7406\u7684\u57fa\u7840\u662f\u7528\u6237\u6570\u636e\uff0c\u5148\u628a\u7ec4\u7ec7\u67b6\u6784\u6253\u901a<\/li>\n<li><strong>\u518d\u63a5\u6587\u4ef6\u5f52\u6863<\/strong>\uff1aCI\/CD\u4ea7\u51fa\u7684\u6784\u5efa\u4ea7\u7269\u81ea\u52a8\u5f52\u6863\uff0c\u51cf\u5c11\u4eba\u5de5\u64cd\u4f5c<\/li>\n<li><strong>\u6700\u540e\u63a5\u6743\u9650\u5ba1\u6279<\/strong>\uff1a\u6838\u5fc3\u6587\u4ef6\u589e\u52a0\u5ba1\u6279\u6d41\uff0c\u91cd\u8981\u64cd\u4f5c\u7559\u6709\u8bb0\u5f55<\/li>\n<\/ol>\n<hr \/>\n<h2>\u516d\u3001\u603b\u7ed3<\/h2>\n<p>\u6280\u672f\u56e2\u961f\u9009\u578b\u4e91\u76d8\uff0cAPI\u80fd\u529b\u5fc5\u987b\u4f5c\u4e3a\u6838\u5fc3\u8bc4\u4f30\u9879\uff1a<\/p>\n<ul>\n<li>\u6709\u6ca1\u6709\u5b8c\u6574\u7684\u7528\u6237\u7ba1\u7406API\uff1f<\/li>\n<li>\u6587\u4ef6\u4e0a\u4f20\u662f\u5426\u652f\u6301\u5927\u6587\u4ef6\uff08\u81f3\u5c1110GB\u4ee5\u4e0a\uff09\uff1f<\/li>\n<li>\u662f\u5426\u652f\u6301Webhook\uff0c\u53ef\u4ee5\u505a\u4e8b\u4ef6\u9a71\u52a8\uff1f<\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u5de5\u7a0b\u8bbe\u8ba1\u56e2\u961f\uff0c\u5df4\u522b\u9e1f\u768450GB\u5355\u6587\u4ef6\u4e0a\u4f20+\u5b8c\u6574\u7528\u6237\u6743\u9650API\u662f\u6700\u5b9e\u7528\u7684\u9009\u62e9\u3002<\/p>\n<hr \/>\n<p><em>\u672c\u6587\u7531\u5df4\u522b\u9e1f\u5e02\u573a\u90e8\u539f\u521b<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6280\u672f\u56e2\u961f\u9009\u62e9\u4f01\u4e1a\u4e91\u76d8\uff0c\u6700\u7ec8\u90fd\u4f1a\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff1a\u5982\u4f55\u4e0e\u73b0\u6709\u5de5\u5177\u94fe&#8230; <a class=\"read-more\" href=\"https:\/\/www.babel.cc\/blog\/?p=6667\">[Continue Reading]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-6667","post","type-post","status-publish","format-standard","hentry","category-2","no-post-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6667"}],"version-history":[{"count":1,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6667\/revisions"}],"predecessor-version":[{"id":6668,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6667\/revisions\/6668"}],"wp:attachment":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}