python push enterprise wechat robot 6- template card type

Posted by ifuschini on Wed, 05 Jan 2022 16:27:20 +0100

Parameter description

parameterRequiredexplain
msgtypeyesThe message type is fixed to template at this time_ card
template_cardyesSpecific template card parameters

template_ Parameter description of card

parameterRequiredexplain
card_typeyesTemplate type of template card. The type of text notification template card is text_notice
sourcenoCard source style information. It is not required to fill in the source style
source.icon_urlnourl of the source image
source.descnoThe description of the source picture should not exceed 13 words
main_titleyesThe main content of the template card, including the first level title and title auxiliary information
main_title.titleyesFirst level title, no more than 26 words recommended
main_title.descnoTitle auxiliary information, no more than 30 words recommended
emphasis_contentnoKey data style
emphasis_content.titlenoThe data content of key data style should not exceed 10 words
emphasis_content.descnoThe data description content of key data style should not exceed 15 words
sub_title_textnoLevel 2 ordinary text, no more than 112 words recommended
horizontal_content_listnoSecondary title + text list, this field can be an empty array, but if there is data, confirm whether the corresponding field is required, and the length of the list shall not exceed 6
horizontal_content_list.typenoLink type: 0 or no means normal text, 1 means jump url, and 2 means download attachment
horizontal_content_list.keynameyesSecondary title, no more than 5 words recommended
horizontal_content_list.valuenoSecondary text, if horizontal_content_list.type is 2. This field represents the file name (including the file type). It is recommended that it should not exceed 26 words
horizontal_content_list.urlnourl of link jump, horizontal_ content_ list. Required when type is 1
horizontal_content_list.media_idnoAttached media_id,horizontal_ content_ list. Required when type is 2
jump_listnoJump to the list of guidance style. This field can be an empty array, but if there is data, confirm whether the corresponding field is required, and the length of the list shall not exceed 3
jump_list.typenoJump link type: 0 or no means not a link, 1 means jump url, and 2 means jump applet
jump_list.titleyesJump link style copy content, no more than 13 words are recommended
jump_list.urlnourl of jump link, jump_ list. Required when type is 1
jump_list.appidnoappid, jump of linked applet_ list. Required when type is 2
jump_list.pagepathnopagepath, jump of linked applet_ list. Optional if type is 2
card_actionyesClick jump event of the whole card, text_ This field is required in the notice template card
card_action.typenoCard jump type: 0 or no means not a link, 1 means jump url, and 2 means open applet. text_ The value range of this field in the notice template card is [1,2]
card_action.urlnourl of jump event, card_ action. Required when type is 1
card_action.appidnoappid, card of the applet of the jump event_ action. Required when type is 2
card_action.pagepathnopagepath, card of applet for jump event_ action. Optional if type is 2

Effect display

Demo Code

# -*- coding: utf-8 -*-
# coding:unicode_escape
# Created on January 5, 2021

# @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":"Welcome CSDN",
                "desc":"Your friends are inviting you to join 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 My blog is really easy to use~\nBalian: A lot of great technical articles!"
            },
            "sub_title_text":"download CSDN And grab red envelopes!",
            "horizontal_content_list":[
                {
                    "keyname":"Invitee",
                    "value":"Joker"
                },
                {
                    "keyname":"CSDN Official website",
                    "value":"Click to access",
                    "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'}  # The specified submission is 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()

Topics: Python wechat