1、首先申请开通微信企业号
2、新建一个应用
3、把应用id、企业Id、Secret 替换以下winxin.py文件
# -*- coding: utf-8 -*-
import requests
import json
import time
import sys
AppId = "1000001" # 应用id
CropID = 'wx00000000000000' # 企业Id
Secret = 'S_00000000000000000000000'
Gtoken = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + CropID + "&corpsecret=" + Secret
Purl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="
headers = {'Content-Type': 'application/json'}
Time = "\n告警时间:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
def gettoken():
try:
r = requests.get(Gtoken)
json_data = json.loads(r.content.decode())
token = json_data["access_token"]
return token
except:
exit(1)
def senddata(user, content):
token = gettoken()
send_values = {
"touser": user,
"msgtype": "text",
"agentid": AppId,
"text": {
"content": content + Time
},
"safe": "0"
}
push = requests.post(Purl + token, data=json.dumps(send_values), headers=headers)
code = json.loads(push.content.decode())
if __name__ == '__main__':
user = str(sys.argv[1])
title = str(sys.argv[2])
content = str(sys.argv[3])
senddata(user, content) 标签:__,微信,send,json,接口,content,token,user,区块 From: https://www.cnblogs.com/nbjjy/p/17488315.html