省去安装requests依赖,直接调用
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import urllib.request
import json
def msg(text):
url='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=换成企业给的接口'
data={
"msgtype": "text",
"text": {
"content": text,
"mentioned_mobile_list": ""
},
}
request=urllib.request.Request(url,json.dumps(data).encode('utf-8'))
reponse=urllib.request.urlopen(request).read().decode('utf-8')
print(reponse)
msg("这是一条测试消息")
发送到企业微信