Call the Enterprise number API to send a message

Source: Internet
Author: User

Personal Zabbix Alarm Use write relatively simple default will send messages to the first department interested in can own consult API document modification under very simple attached code

#!/usr/bin/env python# -*- coding: utf-8 -*-"" "author =  ' Perling ' time  =  ' 2016/11/21 ' "" "Import sysreload (SYS) sys.setdefaultencoding (' UTF8 ') import urllib2import  jsoncorpid =  ' secret =  ' def http_get (URL):    req =  Urllib2. Request (URL)     resp = urllib2.urlopen (req)     resp_json  = json.loads (Resp.read ())     return resp_jsondef http_post (url,post_ Data):     post_data = json.dumps (Post_data,ensure_ascii=false)      req = urllib2. Request (Url, post_data)     req.add_header (' Content-type ',  ' Application/json ')     req.add_header (' Encoding ',  ' utf-8 ')     resp =  Urllib2.urlopen (req)     resp_json = json.loads (Resp.read ())  &NBsp;  return resp_jsondef get_access_key ():     resp = http_ Get ("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s"% (Corpid,secret))      if resp.has_key ("Access_token"):        return  resp["Access_token"]    else:        return  Falsedef send_message (access_key,user,party,message):    data = {          "Touser": user,         "Toparty": party,         "Totag":  "",          "Msgtype":  "text",         "Agentid" : 0,         "Text": {              "Content": message        },          "Safe": 0    }    return http_post ("https ://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s "%access_key,data) if __name__ ==  ' __ Main__ ':     access_key = get_access_key ()     if access_ key:        send_user =  ""   #用户id          send_party =  "1"   #部门id          message = sys.argv[3]        print send_message ( Access_key,send_user,send_party,message)


This article is from the "perling" blog, make sure to keep this source http://zhaolin.blog.51cto.com/9397923/1881051

Call the Enterprise number API to send a message

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.