python 推送企业微信机器人6-模版卡片类型

参数说明

参数是否必填说明
msgtype消息类型,此时固定为template_card
template_card具体的模版卡片参数

template_card的参数说明

参数是否必填说明
card_type模版卡片的模版类型,文本通知模版卡片的类型为text_notice
source卡片来源样式信息,不需要来源样式可不填写
source.icon_url来源图片的url
source.desc来源图片的描述,建议不超过13个字
main_title模版卡片的主要内容,包括一级标题和标题辅助信息
main_title.title一级标题,建议不超过26个字
main_title.desc标题辅助信息,建议不超过30个字
emphasis_content关键数据样式
emphasis_content.title关键数据样式的数据内容,建议不超过10个字
emphasis_content.desc关键数据样式的数据描述内容,建议不超过15个字
sub_title_text二级普通文本,建议不超过112个字
horizontal_content_list二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
horizontal_content_list.type链接类型,0或不填代表是普通文本,1 代表跳转url,2 代表下载附件
horizontal_content_list.keyname二级标题,建议不超过5个字
horizontal_content_list.value二级文本,如果horizontal_content_list.type是2,该字段代表文件名称(要包含文件类型),建议不超过26个字
horizontal_content_list.url链接跳转的url,horizontal_content_list.type是1时必填
horizontal_content_list.media_id附件的media_id,horizontal_content_list.type是2时必填
jump_list跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
jump_list.type跳转链接类型,0或不填代表不是链接,1 代表跳转url,2 代表跳转小程序
jump_list.title跳转链接样式的文案内容,建议不超过13个字
jump_list.url跳转链接的url,jump_list.type是1时必填
jump_list.appid跳转链接的小程序的appid,jump_list.type是2时必填
jump_list.pagepath跳转链接的小程序的pagepath,jump_list.type是2时选填
card_action整体卡片的点击跳转事件,text_notice模版卡片中该字段为必填项
card_action.type卡片跳转类型,0或不填代表不是链接,1 代表跳转url,2 代表打开小程序。text_notice模版卡片中该字段取值范围为[1,2]
card_action.url跳转事件的url,card_action.type是1时必填
card_action.appid跳转事件的小程序的appid,card_action.type是2时必填
card_action.pagepath跳转事件的小程序的pagepath,card_action.type是2时选填

效果展示

在这里插入图片描述

Demo Code

# -*- coding: utf-8 -*-
# coding:unicode_escape
# Created on 2021年01月05日

# @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'
    data={
        "msgtype":"template_card",
        "template_card":{
            "card_type":"text_notice",
            "source":{
                "icon_url":"http://119.29.121.148/ui5/com.joker.shop/uimodule/webapp/img/ShopCarouselShipping.jpg",
                "desc":"Joker's Blog",
                "desc_color":0
            },
            "main_title":{
                "title":"欢迎使用CSDN",
                "desc":"您的好友正在邀请您加入CSDN"
            },
            "emphasis_content":{
                "title":"Joker",
                "desc":"Joker's Blog"
            },
            "quote_area":{
                "type":1,
                "url":"https://blog.csdn.net/",
                "appid":"APPID",
                "pagepath":"PAGEPATH",
                "title":"Joker",
                "quote_text":"Joker:Joker的博客真的很好用~\nBalian:很多很棒的技术文章!"
            },
            "sub_title_text":"下载CSDN还能抢红包!",
            "horizontal_content_list":[
                {
                    "keyname":"邀请人",
                    "value":"Joker"
                },
                {
                    "keyname":"CSDN官网",
                    "value":"点击访问",
                    "type":1,
                    "url":"https://blog.csdn.net/"
                }
            ],        
            "jump_list":[
                {
                    "type":1,
                    "url":"https://blog.csdn.net/huanglin6",
                    "title":"Joker"
                }
            ],        
            "card_action":{
                "type":1,
                "url":"https://blog.csdn.net/huanglin6",
                "appid":"APPID",
                "pagepath":"PAGEPATH"
            }        
        }
    }

    headers = {'Content-Type': 'application/json'}  # 指定提交的是json
    try:
        response = requests.post(url=oWX_URL, json=data, headers=headers, timeout=5)
    except Exception as e:
        print(e.args[0])


if __name__ == '__main__':

    main()

posted @ 2022-01-05 18:09  linhuang  阅读(73)  评论(0编辑  收藏  举报  来源