十、区块量化 通用文件 微信接口
1、首先申请开通微信企业号
2、新建一个应用
3、把应用id、企业Id、Secret 替换以下weixin.py文件
# -*- coding: utf-8 -*-
import requests
import json
import time
import sys
AppId = "1000002" # 应用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)
import requests
import json
import time
import sys
AppId = "1000002" # 应用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)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)