{"id":604,"date":"2025-05-09T20:17:00","date_gmt":"2025-05-09T12:17:00","guid":{"rendered":"https:\/\/www.jumoon.top\/?p=604"},"modified":"2026-01-08T22:58:36","modified_gmt":"2026-01-08T14:58:36","slug":"%e9%92%89%e9%92%89%e5%bc%80%e5%8f%91%e5%ae%9e%e7%8e%b0%e5%86%85%e9%83%a8%e6%b6%88%e6%81%af%e6%89%b9%e9%87%8f%e6%8e%a8%e9%80%81","status":"publish","type":"post","link":"https:\/\/www.jumoon.top\/?p=604","title":{"rendered":"\u9489\u9489\u5f00\u53d1\u7ed3\u5408Python\u5b9e\u73b0\u6279\u91cf\u63a8\u9001\u4fe1\u606f"},"content":{"rendered":"\n<p>\u57fa\u4e8e\u9489\u9489\u5f00\u653e\u5e73\u53f0\uff0c\u521b\u5efa\u5e94\u7528\uff0c\u6388\u6743\u6210\u5458\u4fe1\u606f\u8bfb\u6743\u9650\uff0c\u8c03\u7528\u4f01\u4e1aAPI\u57fa\u7840\u6743\u9650\uff0c\u901a\u8fc7py\u8c03\u7528api\u63a5\u53e3\u5b9e\u73b0\u4f01\u4e1a\u5185\u90e8\u6279\u91cf\u63a8\u9001\u4fe1\u606f\u3002\u65b0\u5efaExcel\u6587\u4ef6\uff0cA\uff0cB\u5217\u6807\u9898\u5206\u522b\u4e3a userid\uff0c\u6d88\u606f\u5185\u5bb9\u3002\u7b2c\u4e8c\u884c\u4f60\u5f00\u59cb\u586b\u5199\u9700\u8981\u88ab\u63a8\u9001\u7528\u6237\u7684\u9489\u9489ID\uff0c\u53ca\u8981\u63a8\u9001\u7684\u6587\u672c\u3002\u5c06\u811a\u672c\u548cExcel\u6587\u4ef6\u653e\u5728\u540c\u4e00\u76ee\u5f55\u6267\u884c\u811a\u672c\uff0c\u5373\u53ef\u5b9e\u73b0\u6279\u91cf\u63a8\u9001\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\">\u4ee5\u4e0b\u662f\u4ee3\u7801\u793a\u4f8b:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import requests\nfrom openpyxl import load_workbook\n\n# \u9489\u9489\u914d\u7f6e\uff08\u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u7684\u503c\uff09\nAPP_KEY = \"AppKey\"          # \u5f00\u653e\u5e73\u53f0\u5e94\u7528\u7684AppKey\nAPP_SECRET = \"AppSecret\"   # \u5f00\u653e\u5e73\u53f0\u5e94\u7528\u7684AppSecret\nAGENT_ID = \"AgentId\"           # \u5e94\u7528\u8be6\u60c5\u9875\u4e2d\u7684AgentId\n\ndef get_access_token():\n    url = f\"https:\/\/oapi.dingtalk.com\/gettoken?appkey={APP_KEY}&amp;appsecret={APP_SECRET}\"\n    response = requests.get(url)\n    return response.json().get(\"access_token\")\ndef send_dingtalk_message(userid, content, token):\n    url = \"https:\/\/oapi.dingtalk.com\/topapi\/message\/corpconversation\/asyncsend_v2\"\n    headers = {\"Content-Type\": \"application\/json\"}\n    data = {\n        \"agent_id\": AGENT_ID,\n        \"userid_list\": userid,\n        \"msg\": {\n            \"msgtype\": \"text\",\n            \"text\": {\"content\": content}\n        }\n    }\n    response = requests.post(\n        url,\n        json=data,\n        params={\"access_token\": token},\n        headers=headers\n    )\n    return response.json()\ndef push_from_excel(file_path):\n    wb = load_workbook(file_path)\n    ws = wb.active\n    token = get_access_token()\n    for row in ws.iter_rows(min_row=2, values_only=True):\n        userid = str(row&#91;0]).strip()\n        content = str(row&#91;1]) if row&#91;1] else \"\uff08\u7a7a\u5185\u5bb9\uff09\"\n        print(f\"\u51c6\u5907\u63a8\u9001 -&gt; UserID: '{userid}' (\u7c7b\u578b: {type(userid)}, \u957f\u5ea6: {len(userid)}), \u5185\u5bb9: '{content}'\")\n        result = send_dingtalk_message(userid, content, token)\n        print(f\"\u63a8\u9001\u7ed3\u679c: {result}\\n\")\nif __name__ == \"__main__\":\n    excel_file = \"\u4eba\u5458\u6d88\u606f\u5217\u8868.xlsx\"  # \u66ff\u6362\u4e3a\u4f60\u7684Excel\u6587\u4ef6\u8def\u5f84\n    print(f\"\u5f00\u59cb\u5904\u7406Excel\u6587\u4ef6: {excel_file}\")\n    push_from_excel(excel_file)\n    print(\"\u5904\u7406\u5b8c\u6210\uff01\")\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e\u9489\u9489\u5f00\u653e\u5e73\u53f0\uff0c\u521b\u5efa\u5e94\u7528\uff0c\u6388\u6743\u6210\u5458\u4fe1\u606f\u8bfb\u6743\u9650\uff0c\u8c03\u7528\u4f01\u4e1aAPI\u57fa\u7840\u6743\u9650\uff0c\u901a\u8fc7py\u8c03\u7528api\u63a5\u53e3\u5b9e\u73b0\u4f01\u4e1a\u5185\u90e8\u6279\u91cf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","site-transparent-header":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[19],"tags":[],"class_list":["post-604","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts\/604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=604"}],"version-history":[{"count":1,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts\/604\/revisions"}],"predecessor-version":[{"id":985,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts\/604\/revisions\/985"}],"wp:attachment":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}