{"id":163,"date":"2020-07-04T16:00:11","date_gmt":"2020-07-04T08:00:11","guid":{"rendered":"https:\/\/blog.xbgit.cn\/?p=163"},"modified":"2020-07-04T16:00:11","modified_gmt":"2020-07-04T08:00:11","slug":"python%e9%92%89%e9%92%89%e6%9c%ba%e5%99%a8%e4%ba%ba","status":"publish","type":"post","link":"https:\/\/blog.xbgit.cn\/index.php\/2020\/07\/04\/python%e9%92%89%e9%92%89%e6%9c%ba%e5%99%a8%e4%ba%ba\/","title":{"rendered":"python\u5b9e\u73b0\u63a8\u9001\u6d88\u606f\u5230\u9489\u9489\u673a\u5668\u4eba"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u9605\u8bfb\u4e86<a href=\"https:\/\/ding-doc.dingtalk.com\/doc#\/serverapi2\/qf2nxq\" target=\"_blank\" aria-label=\"undefined\uff08\u5728\u65b0\u6807\u7b7e\u9875\u4e2d\u6253\u5f00\uff09\" rel=\"noreferrer noopener nofollow\">\u5b98\u65b9\u6587\u6863<\/a>\uff0c\u6574\u5408\u5230\u4e86\u4e00\u4e2a\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python line-numbers\">#  Copyright (c) 2020.\n#  \u4f5c\u8005\uff1asky\n#  \u90ae\u7bb1\uff1aztianb@foxmail.com\n#  \u65e5\u671f\uff1a2020-06-16 09:44\n#  ---\n#  \u9879\u76ee\uff1atest\n#  \u6587\u4ef6\u540d\uff1ato\u9489\u9489\u673a\u5668\u4eba.py\n#  \u8def\u5f84\uff1aD:\/pythonworkspace\/test\/to\u9489\u9489\u673a\u5668\u4eba.py\n#  Copyright (c) 2020\nimport json\n\nimport requests\n\nurl = r\"https:\/\/oapi.dingtalk.com\/robot\/send?access_token=\"\nheaders = {\n    \"Content-Type\": \"application\/json\",\n    \"X-Forwarded-For\": \"123.57.151.56\"\n}\n\n\ndef textData(content, at, isAtAll):\n    data = {\n        \"msgtype\": \"text\",\n        \"text\": {\n            \"content\": content\n        },\n        \"at\": {\n            # \"atMobiles\": [\n            #     \"156xxxx8827\",\n            #     \"189xxxx8325\"\n            # ],\n            \"isAtAll\": isAtAll\n        }\n    }\n    return data\n\n\ndef linkData(title, content, picUrl, messageUrl):\n    data = {\n        \"msgtype\": \"link\",\n        \"link\": {\n            \"text\": content,\n            \"title\": title,\n            \"picUrl\": picUrl,\n            \"messageUrl\": messageUrl\n        }\n    }\n    return data\n\n\ndef markdownData(title, content, at, isAtAll):\n    data = {\n        \"msgtype\": \"markdown\",\n        \"markdown\": {\n            \"title\": title,\n            \"text\": content\n        },\n        \"at\": {\n            \"atMobiles\": at,\n            \"isAtAll\": isAtAll\n        }\n    }\n    return data\n\n\ndef ZTActionCardData(title, content, singleURL, picUrl):\n    data = {\n        \"actionCard\": {\n            \"title\": title,\n            \"text\": \"![screenshot](\" + picUrl + \")\" + content,\n            \"btnOrientation\": \"0\",\n            \"singleTitle\": \"\u9605\u8bfb\u5168\u6587\",\n            \"singleURL\": singleURL\n        },\n        \"msgtype\": \"actionCard\"\n    }\n    return data\n\n\ndef DLActionCardData(title, content, singleURL, picUrl):\n    data = {\n        \"actionCard\": {\n            \"title\": title,\n            \"text\": \"![screenshot](\" + picUrl + \")\" + content,\n            \"btnOrientation\": \"0\",\n            \"btns\": [\n                {\n                    \"title\": \"\u5185\u5bb9\u4e0d\u9519\",\n                    \"actionURL\": \"https:\/\/www.dingtalk.com\/\"\n                },\n                {\n                    \"title\": \"\u4e0d\u611f\u5174\u8da3\",\n                    \"actionURL\": \"https:\/\/www.dingtalk.com\/\"\n                }\n            ]\n        },\n        \"msgtype\": \"actionCard\"\n    }\n    return data\n\n\ndef FeedCardData(links):\n    data = {\n        \"feedCard\": {\n            \"links\": links\n        },\n        \"msgtype\": \"feedCard\"\n    }\n    return data\n\n\ndef dingTalk():\n    # data = markdownData(\"aa\", \"#### \u676d\u5dde\u5929\u6c14 \\n\", [], True)\n    data = ZTActionCardData(\"\u6574\u4f53\u8df3\u8f6c\u5361\u7247\u6d4b\u8bd5\",\"\u8fd9\u662f\u4e2a\u6d4b\u8bd5\",\"https:\/\/www.dingtalk.com\/\",\"https:\/\/gw.alicdn.com\/tfs\/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png\")\n    data = FeedCardData([{\n                \"title\": \"\u65f6\u4ee3\u7684\u706b\u8f66\u5411\u524d\u5f00\",\n                \"messageURL\": \"https:\/\/www.dingtalk.com\/s?__biz=MzA4NjMwMTA2Ng==&amp;mid=2650316842&amp;idx=1&amp;sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&amp;scene=2&amp;srcid=09189AnRJEdIiWVaKltFzNTw&amp;from=timeline&amp;isappinstalled=0&amp;key=&amp;ascene=2&amp;uin=&amp;devicetype=android-23&amp;version=26031933&amp;nettype=WIFI\",\n                \"picURL\": \"https:\/\/gw.alicdn.com\/tfs\/TB1ayl9mpYqK1RjSZLeXXbXppXa-170-62.png\"\n            },\n            {\n                \"title\": \"\u65f6\u4ee3\u7684\u706b\u8f66\u5411\u524d\u5f002\",\n                \"messageURL\": \"https:\/\/www.dingtalk.com\/s?__biz=MzA4NjMwMTA2Ng==&amp;mid=2650316842&amp;idx=1&amp;sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&amp;scene=2&amp;srcid=09189AnRJEdIiWVaKltFzNTw&amp;from=timeline&amp;isappinstalled=0&amp;key=&amp;ascene=2&amp;uin=&amp;devicetype=android-23&amp;version=26031933&amp;nettype=WIFI\",\n                \"picURL\": \"https:\/\/gw.alicdn.com\/tfs\/TB1ayl9mpYqK1RjSZLeXXbXppXa-170-62.png\"\n            }])\n    json_data = json.dumps(data)\n    response = requests.post(url=url, data=json_data, headers=headers)\n    print(response)\n\n\ndingTalk()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9605\u8bfb\u4e86\u5b98\u65b9\u6587\u6863\uff0c\u6574\u5408\u5230\u4e86\u4e00\u4e2a\u6587\u4ef6\u4f7f\u7528python\u5b9e\u73b0\u63a8\u9001\u6d88\u606f\u5230\u9489\u9489\u673a\u5668\u4eba<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3],"tags":[34,47],"class_list":["post-163","post","type-post","status-publish","format-standard","hentry","category-python","category-3","tag-python","tag-47"],"_links":{"self":[{"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/posts\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":0,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xbgit.cn\/index.php\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}