python推送企业微信机器人4-图文类型

参数说明

参数是否必填说明
msgtype消息类型,此时固定为news
articles图文消息,一个图文消息支持1到8条图文
title标题,不超过128个字节,超过会自动截断
description描述,不超过512个字节,超过会自动截断
url点击后跳转的链接。
picurl图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图 1068455,小图150150。

效果展示

在这里插入图片描述

Demo Code

# -*- coding: utf-8 -*-
# coding:unicode_escape
# Created on 2021年12月31日

# @author: LinHuang(Joker)

import requests
import json


# mian function
def main():
    oWX_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=50d640d9-9ad6-4d39-98aa-c94c2002e6d4'
    sent_msg = {
        "msgtype": "news",
        "news": {
        "articles" : [
            {
                "title" : "Joke's blog",
                "description" : "Find your solution",
                "url" : "https://blog.csdn.net/huanglin6",
                "picurl" : "https://profile.csdnimg.cn/0/0/B/1_huanglin6"
            }
            ]
        }
    }

    headers = {'Content-Type': 'application/json'}  # 指定提交的是json
    try:
        # 转换为json字符串
        r = requests.post(url=oWX_URL, data=json.dumps(sent_msg), headers=headers, timeout=5)
    except Exception as e:
        print(e.args[0]) 
if __name__ == '__main__':

    main()

posted @   linhuang  阅读(20)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2020-12-31 2020年终总结
点击右上角即可分享
微信分享提示