企业微信机器人图片发送:
import requests
import base64
import hashlib
def wx_image(image):
with open(image, 'rb') as file:
data = file.read()
encodestr = base64.b64encode(data)
image_data = str(encodestr, 'utf-8')
with open(image, 'rb') as file:
md = hashlib.md5()
md.update(file.read())
image_md5 = md.hexdigest()
url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=********-cebd-4506-844e-d94edf******"
headers = {"Content-Type": "application/json"}
data = {
"msgtype": "image",
"image": {
"base64": image_data,
"md5": image_md5
}
}
result = requests.post(url, headers=headers, json=data)
return result
wx_image('D:\\Py-thon\\pyhon-yunwei\\03.png')
输出结果:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/aaf2fe0ce231978a663896ad619b1c27.png)