{"id":28529,"date":"2024-11-25T17:20:19","date_gmt":"2024-11-25T09:20:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28529\/"},"modified":"2024-11-25T17:20:19","modified_gmt":"2024-11-25T09:20:19","slug":"%e8%af%a6%e7%bb%86%e6%ad%a5%e9%aa%a4%ef%bc%8czabbix%e9%85%8d%e7%bd%ae%e5%be%ae%e4%bf%a1%e4%bc%81%e4%b8%9a%e5%8f%b7%e5%ae%9e%e7%8e%b0%e6%8a%a5%e8%ad%a6%e6%96%b9%e6%b3%95-%e9%99%84%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28529\/","title":{"rendered":"\u8be6\u7ec6\u6b65\u9aa4\uff0czabbix\u914d\u7f6e\u5fae\u4fe1\u4f01\u4e1a\u53f7\u5b9e\u73b0\u62a5\u8b66\u65b9\u6cd5-\u9644\u4ee3\u7801"},"content":{"rendered":"<p>\u7528\u4f01\u4e1a\u53f7\u5982\u4f55\u62a5\u8b66\uff1f\u5404\u4f4d\u770b\u5b98\uff0c\u6211\u662forange\u521d\u5b66\u8005\uff0c\u521d\u51fa\u8305\u5e90\uff0c\u4e0d\u8db3\u4e4b\u5904\u8fd8\u8bf7\u6307\u6559\uff0c\u4ee5\u4e0b\u662f\u6211\u7684\u4ee3\u7801\u5206\u4eab\uff01\uff01<\/p>\n<p><strong>1.\u6211\u5148\u628a\u6211\u7684\u4ee3\u7801\u7529\u51fa\u6765\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u4e00\u4e0b\uff0c\u633a\u4e11\u7684\uff0c\u522b\u4ecb\u610f\u54e6\uff01<\/strong><\/p>\n<pre>#!\/usr\/bin\/python\n\nimport&nbsp;requests&nbsp;\nimport&nbsp;sys\nimport&nbsp;json\n\nuserID=sys.argv[1]\nsubject=sys.argv[2]\ncontent=sys.argv[3]\n\ncorpid='CorpID'&nbsp;&nbsp;#\u6b64\u5904\u4e3a\u6743\u9650\u7ba1\u7406\u4e2d\u6bcf\u4e2a\u7ec4\u7684ID,\u5176\u5b9e\u8bf4\u5c31\u4e00\u4e2aID\uff0c\u5168\u90e8\u76f8\u540c\u7684\ncorpsecret=\"CortSecret\"#\u6b64\u5904\u4e3a\u6743\u9650\u7ba1\u7406\u4e2d\u7684\u5bc6\u7801\uff0c\u5176\u5b9e\u4e25\u683c\u6765\u8bf4\u662f\u6765\u533a\u5206\u5176\u4ed6\u7ec4\u7684ID\n\nclass&nbsp;WeiXin(object):\n#\u521d\u59cb\u5316\u53d8\u91cf&nbsp;\ndef&nbsp;&nbsp;__init__(self,corpid,corpsecret):\nself.corpid=corpid\nself.corpsecret=corpsecret\n#\u83b7\u53d6token\u7684\u503c\ndef&nbsp;get_token(self):\n\nurl='https:\/\/qyapi.weixin.qq.com\/cgi-bin\/gettoken?corpid='+\nself.corpid+'&amp;amp;corpsecret='+self.corpsecret\nget_data=requests.request(\"GET\",url)\nget_token=get_data.json()\ntoken=get_token.get('access_token')\nreturn&nbsp;token\n#\u53d1\u9001data\uff0c\u4e5f\u5c31\u662f\u63a8\u9001\u5230\u7528\u6237&nbsp;\ndef&nbsp;send_data(self,user,subject,content):\naccess_token=self.get_token()\nurl='https:\/\/qyapi.weixin.qq.com\/cgi-bin\/message\/send?access_token='+\naccess_token\nsend_data={\n\"touser\":&nbsp;user,&nbsp;&nbsp;#\u8fd9\u662f\u6307\u7684\u662f\u901a\u4fe1\u5f55\u4e2d\u4e0d\u540c\u7ec4\u7684\u7528\u6237\uff0c\u5f53\u53d1\u9001\u7684\u7528\u6237\u5728\u7ec4\u4e2d\u65e0\u6cd5\u627e\u5230\uff0c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;\u9ed8\u8ba4\u4f1a\u5411\u6240\u6709\u7528\u6237\u53d1\u9001\n\"toparty\":&nbsp;3,&nbsp;&nbsp;&nbsp;&nbsp;#\u8fd9\u91cc\u6307\u7684\u662f\u901a\u4fe1\u5f55\u4e2d\u7684\u7ec4ID\uff0c\n\"msgtype\":&nbsp;\"text\",\n\"agentid\":&nbsp;3,&nbsp;&nbsp;&nbsp;&nbsp;#\u8fd9\u91cc\u6307\u7684\u662f\u5e94\u7528\uff0c\u4e5f\u5c31\u662f\u6d88\u606f\u7ba1\u7406\uff0c\u90a3\u4e9b\u4eba\u53ef\u4ee5\u6536\u5230\u672c\u7ec4\u4fe1\u606f\u90a3\u4e9b\u4e0d\u53ef\u4ee5\n\"text\":&nbsp;{\n\"content\":&nbsp;'{0}{1}{2}'.format(subject,content,user)\n},\n\"safe\":&nbsp;0\n}\ndata=json.dumps(send_data,ensure_ascii=False)\nret=requests.post(url,data=data)\nprint&nbsp;ret.json()\n\nif&nbsp;'__main__'==__name__:\nUser=WeiXin(corpid,corpsecret)\nUser.send_data(userID,subject,content)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2.\u66fe\u7ecf\u8d70\u8fc7\u7684\u5751<\/strong><\/p>\n<pre> \uff08a\uff09 \u6743\u9650\u95ee\u9898\uff0c\u548c\u4e24\u4e2a\u5730\u65b9\u6709\u5173\u7cfb\uff0c\u7b2c\u4e00\u4e0e\u5e94\u7528\u4e2d\u5fc3\u7684\u67d0\u4e2a\u5e94\u7528\u7684\u53ef\u89c1\u8303\u56f4\u6709\u5173\u7cfb\uff1b\u7b2c\u4e8c\u548c\u8bbe\u7f6e\u91cc\u9762\u529f\u80fd\u8bbe\u7f6e\u4e2d\u7684\u6743\u9650\u7ba1\u7406\u6709\u5173\u3002\n\n \uff08b\uff09\u5fae\u4fe1\u7684\u4f7f\u7528\u95ee\u9898\uff0c\u7b2c\u4e00\u8981\u5efa\u4e2a\u901a\u4fe1\u5f55\uff0c\u627e\u5230\u6b63\u786e\u7684\u7ec4ID\uff0c\u7b2c\u4e8c\uff0c\u5e94\u7528\u4e2d\u5fc3agentid\u7684\u521b\u5efa\u5e76\u4f7f\u7528\uff0c\u7b2c\u4e09\uff0c\u8bbe\u7f6e\u4e2d\u5206\u7ec4\u8981\u521b\u5efa\uff1b<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5751\uff0c\u89e3\u51b3\u6389\u5c31\u662f\u8def\uff0c\u89e3\u51b3\u4e0d\u4e86\u8fd8\u662f\u5751\u3002<\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8be6\u7ec6\u6b65\u9aa4\uff0czabbix\u914d\u7f6e\u4f01\u4e1a\u53f7\u5b9e\u73b0\u62a5\u8b66\u65b9\u6cd5-\u9644\u4ee3\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u4f01\u4e1a\u53f7\u5982\u4f55\u62a5\u8b66\uff1f\u5404\u4f4d\u770b\u5b98\uff0c\u6211\u662forange\u521d\u5b66\u8005\uff0c\u521d\u51fa\u8305\u5e90\uff0c\u4e0d\u8db3\u4e4b\u5904\u8fd8\u8bf7\u6307\u6559\uff0c\u4ee5\u4e0b\u662f\u6211\u7684\u4ee3\u7801\u5206\u4eab\uff01\uff01 1.\u6211\u5148\u628a\u6211\u7684\u4ee3\u7801\u7529\u51fa\u6765\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\u4e00\u4e0b\uff0c\u633a\u4e11\u7684\uff0c\u522b\u4ecb\u610f\u54e6\uff01 #!\/usr\/bin\/python import&nbsp;requests&nbsp; import&nbsp;sys import&nbsp;json userID=sys.argv[1] subject=sys.argv[2] content=sys.argv[3] corpid=&#8217;CorpID&#8217;&nbsp;&nbsp;#\u6b64\u5904\u4e3a\u6743\u9650\u7ba1\u7406\u4e2d\u6bcf\u4e2a\u7ec4\u7684ID,\u5176\u5b9e\u8bf4\u5c31\u4e00\u4e2aID\uff0c\u5168\u90e8\u76f8\u540c\u7684 corpsecret=&#8221;CortSecret&#8221;#\u6b64\u5904\u4e3a\u6743\u9650\u7ba1\u7406\u4e2d\u7684\u5bc6\u7801\uff0c\u5176\u5b9e\u4e25\u683c\u6765\u8bf4\u662f\u6765\u533a\u5206\u5176\u4ed6\u7ec4\u7684ID class&nbsp;WeiXin(object): #\u521d\u59cb\u5316\u53d8\u91cf&nbsp; def&nbsp;&nbsp;__init__(self,corpid,corpsecret): self.corpid=corpid self.corpsecret=corpsecret #\u83b7\u53d6token\u7684\u503c def&nbsp;get_token(self): url=&#8217;https:\/\/qyapi.weixin.qq.com\/cgi-bin\/gettoken?corpid=&#8217;+ self.corpid+&#8217;&amp;amp;corpsecret=&#8217;+self.corpsecret get_data=requests.request(&#8220;GET&#8221;,url) get_token=get_data.json() token=get_token.get(&#8216;access_token&#8217;) return&nbsp;token #\u53d1\u9001data\uff0c\u4e5f\u5c31\u662f\u63a8\u9001\u5230\u7528\u6237&nbsp; def&nbsp;send_data(self,user,subject,content): access_token=self.get_token() url=&#8217;https:\/\/qyapi.weixin.qq.com\/cgi-bin\/message\/send?access_token=&#8217;+ access_token send_data={ &#8220;touser&#8221;:&nbsp;user,&nbsp;&nbsp;#\u8fd9\u662f\u6307\u7684\u662f\u901a\u4fe1\u5f55\u4e2d\u4e0d\u540c\u7ec4\u7684\u7528\u6237\uff0c\u5f53\u53d1\u9001\u7684\u7528\u6237\u5728\u7ec4\u4e2d\u65e0\u6cd5\u627e\u5230\uff0c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;\u9ed8\u8ba4\u4f1a\u5411\u6240\u6709\u7528\u6237\u53d1\u9001 &#8220;toparty&#8221;:&nbsp;3,&nbsp;&nbsp;&nbsp;&nbsp;#\u8fd9\u91cc\u6307\u7684\u662f\u901a\u4fe1\u5f55\u4e2d\u7684\u7ec4ID\uff0c &#8220;msgtype&#8221;:&nbsp;&#8220;text&#8221;, &#8220;agentid&#8221;:&nbsp;3,&nbsp;&nbsp;&nbsp;&nbsp;#\u8fd9\u91cc\u6307\u7684\u662f\u5e94\u7528\uff0c\u4e5f\u5c31\u662f\u6d88\u606f\u7ba1\u7406\uff0c\u90a3\u4e9b\u4eba\u53ef\u4ee5\u6536\u5230\u672c\u7ec4\u4fe1\u606f\u90a3\u4e9b\u4e0d\u53ef\u4ee5 &#8220;text&#8221;:&nbsp;{ &#8220;content&#8221;:&nbsp;&#8216;{0}{1}{2}&#8217;.format(subject,content,user) }, &#8220;safe&#8221;:&nbsp;0 } data=json.dumps(send_data,ensure_ascii=False) ret=requests.post(url,data=data) print&nbsp;ret.json() if&nbsp;&#8216;__main__&#8217;==__name__: User=WeiXin(corpid,corpsecret) User.send_data(userID,subject,content) \u767b\u5f55\u540e\u590d\u5236 2.\u66fe\u7ecf\u8d70\u8fc7\u7684\u5751 \uff08a\uff09 \u6743\u9650\u95ee\u9898\uff0c\u548c\u4e24\u4e2a\u5730\u65b9\u6709\u5173\u7cfb\uff0c\u7b2c\u4e00\u4e0e\u5e94\u7528\u4e2d\u5fc3\u7684\u67d0\u4e2a\u5e94\u7528\u7684\u53ef\u89c1\u8303\u56f4\u6709\u5173\u7cfb\uff1b\u7b2c\u4e8c\u548c\u8bbe\u7f6e\u91cc\u9762\u529f\u80fd\u8bbe\u7f6e\u4e2d\u7684\u6743\u9650\u7ba1\u7406\u6709\u5173\u3002 \uff08b\uff09\u5fae\u4fe1\u7684\u4f7f\u7528\u95ee\u9898\uff0c\u7b2c\u4e00\u8981\u5efa\u4e2a\u901a\u4fe1\u5f55\uff0c\u627e\u5230\u6b63\u786e\u7684\u7ec4ID\uff0c\u7b2c\u4e8c\uff0c\u5e94\u7528\u4e2d\u5fc3agentid\u7684\u521b\u5efa\u5e76\u4f7f\u7528\uff0c\u7b2c\u4e09\uff0c\u8bbe\u7f6e\u4e2d\u5206\u7ec4\u8981\u521b\u5efa\uff1b \u767b\u5f55\u540e\u590d\u5236 \u5751\uff0c\u89e3\u51b3\u6389\u5c31\u662f\u8def\uff0c\u89e3\u51b3\u4e0d\u4e86\u8fd8\u662f\u5751\u3002 \u76f8\u5173\u63a8\u8350\uff1a \u4ee5\u4e0a\u5c31\u662f\u8be6\u7ec6\u6b65\u9aa4\uff0czabbix\u914d\u7f6e\u4f01\u4e1a\u53f7\u5b9e\u73b0\u62a5\u8b66\u65b9\u6cd5-\u9644\u4ee3\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-28529","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=28529"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28529\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}