pythonとエンタープライズ微信ロボットで画像を送信
754 ワード
import requests
import base64
import hashlib
# base64
with open("F:\\a.png","rb") as f:
base64_data = base64.b64encode(f.read())
# base64.b64decode(base64data)
print(base64_data)
# md5
file = open("F:\\a.png", "rb")
md = hashlib.md5()
md.update(file.read())
res1 = md.hexdigest()
print(res1)
#
url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=37b4b749-f8dc-4ddb-a585-1e4d6ebf15aaaaaa"
headers = {"Content-Type": "text/plain"}
data = {
"msgtype": "image",
"image": {
"base64": base64_data,
"md5": res1
}
}
r = requests.post(url, headers=headers, json=data)
print(r.text)