在办公自动化中有一个场景会经常用到,及时使用企业微信机器人发哦那个图片,这个我将范例分享给大家。
import requests
def send_image_to_wechat(image_path, robot_key, proxy_host, proxy_port):
    with open(image_path, 'rb') as file:
        data = file.read()
        encodestr = base64.b64encode(data)
        image_data = str(encodestr, 'utf-8')
    with open(image_path, 'rb') as file:
        md = hashlib.md5()
        md.update(file.read())
        image_md5 = md.hexdigest()
    url = f"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={robot_key}"
    headers = {
        "Content-Type": "application/json",
        "User-Agent": "Your User-Agent String"
    }
    data = {
        "msgtype": "image",
        "image": {
            "base64": image_data,
            "md5": image_md5
        }
    }
    proxies = {
        "http": f"http://{proxy_host}:{proxy_port}",
        "https": f"http://{proxy_host}:{proxy_port}"
    }
    result = requests.post(url, headers=headers, json=data, proxies=proxies)版权属于:青阳のBlog
本文链接:https://www.hipyt.cn/380.html
作品采用:《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
转载时须注明出处及本声明
 
                             
                            
此处评论已关闭