Python micro-trust public platform enterprise number for monitoring and alarm research

Source: Internet
Author: User


1. Public number, public number use template information to send users 10w daily information 2. Enterprise number, give the employee unlimited send information:


The function of enterprise number:


Enterprise number is suitable for communication between enterprise and employee or upstream and downstream supply chain.


1, the enterprise may send the message to the employee voluntarily, the message quantity is unrestricted.


2. The enterprise number appears in the first level of the micro-trust session list, and has a separate classification in the Address Book.


3, you can customize the menu.


4, with multiple sub numbers.


5, more attention and security, the need for both sides certification.


As a compulsive disease control, that must use the enterprise, ah, here needs the support of the boss, enterprise number is not able to apply, fortunately my boss far-sighted, has applied for good. (Xi hee, hope the boss can see)


Scan two-dimensional code for login: https://qy.weixin.qq.com/


New application after landing:


Input application name for monitoring and alerting a new application called monitoring alarm, after the new completed view Application ID, here to use.


Setup Administrator:


Specifies the administrator for the application. Click to set-> Rights Management-> management-> New Administrative Group--> add administrators and permissions. Then you'll get corpid and Sceret. We'll use it back here, too.


Development


1, read the development document. Document location: Micro-Credit Development document


I read only to establish a connection, manage the address book, send messages. Well, it's enough to send an alarm, it's simple.


2, establish a connection to obtain access_token.


This token is an effective time key for subsequent operational authentication.


HTTPS Request mode: Get


Https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=id&corpsecret=secrect


Normally it feeds a JSON and gets the Access_token


You can send a message after you have played access_token based on the document.

The script code I wrote is as follows:


#!/usr/bin/env python
# Coding:utf-8
Import Sys
Import Urllib2
Import time
Import JSON
Import requests

Reload (SYS)
Sys.setdefaultencoding (' Utf-8 ')

title = sys.argv[2] # position parameter Fetch title applies to Zabbix
Content = sys.argv[3] # position parameter fetch content applies to Zabbix


Class Token (object):
# Get Token
def __init__ (self, Corpid, Corpsecret):
Self.baseurl = ' https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1} '. Format (
Corpid, Corpsecret)
Self.expire_time = Sys.maxint

def get_token (self):
If Self.expire_time > Time.time ():
Request = Urllib2. Request (Self.baseurl)
Response = Urllib2.urlopen (Request)
ret = Response.read (). Strip ()
ret = json.loads (ret)
If ' Errcode ' in Ret.keys ():
Print >> ret[' errmsg '], Sys.stderr
Sys.exit (1)
Self.expire_time = Time.time () + ret[' expires_in ']
Self.access_token = ret[' Access_token ']
Return Self.access_token


def send_msg (title, content):
# Send Message
Corpid = "" # Fill in your own application
Corpsecret = "" # Fill in your own application
Qs_token = token (corpid=corpid, Corpsecret=corpsecret). Get_token ()
url = "Https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}". Format (
Qs_token)
Payload = {
"Touser": "User1|user2",
"Msgtype": "Text",
"Agentid": "3",
' Text ': {
"Content": "title: {0}\n contents: {1}". Format (title, content)

},
"Safe": "0"
}
ret = requests.post (URL, data=json.dumps (payload, ensure_ascii=false))
Print Ret.json ()

if __name__ = = ' __main__ ':
# Print title, content
Send_msg (title, content)

Related Article

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.