前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >企业微信机器人发图片范例

企业微信机器人发图片范例

原创
作者头像
青阳
发布2023-07-21 11:01:51
6450
发布2023-07-21 11:01:51
举报
文章被收录于专栏:玩转云服务玩转云服务

在办公自动化中有一个场景会经常用到,及时使用企业微信机器人发哦那个图片,这个我将范例分享给大家。

代码语言:javascript
复制
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)

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档