First of all,

Obtain the webhook of the group robot through the group robot created in the wechat group of the enterprise. Please do not easily provide your webhook to others!

Obtain it as follows:

1. Add swarm robots (if there is a swarm)

Right click add robot, follow the instructions to complete the creation of the robot.

2. Locate webhook

The second

Plain text type message

import requests

class WXWork_SMS:
    # Text type message
    def send_msg_txt(self) :
        headers = {"Content-Type": "text/plain"}
        send_url = "webhook_url"    # webhook_URL is the webhook for swarm robots
        send_data = {
            "msgtype": "text".# message type: text
            "text": {
                "content": "It's really hot in summer \n Would be happy to have a cold watermelon".# Text content, must be UTF8 encoding
                #"mentioned_list": ["@all"],
                A list of userids that alert specified members of the group (@ a member), @all that alert everyone
            }
        }

        res = requests.post(url=send_url, headers=headers, json=send_data)
        print(res.text)

if __name__ == '__main__':
    sms = WXWork_SMS()
    sms.send_msg_txt()
Copy the code

Text type message

import requests

class WXWork_SMS:
    # text type message
    def send_msg_txt_img(self) :
        headers = {"Content-Type": "text/plain"}
        send_url = "webhook_url"    # webhook_URL is the webhook for swarm robots
        send_data = {
            "msgtype": "news".# Message type: news
            "news": {
                "articles": [  A text message supports 1 to 8 text messages
                    {
                        "title": "Just Google it and you'll know.".# header, no more than 128 bytes
                        "description": "Go to the link at the top.".Description, no more than 512 bytes
                        "url": "www.baidu.com".# Click the link to jump to the picture.
                        "picurl": "C://Users//lenovo//Desktop//1.png"  # Can be linked to web pictures
                        Image link of text message supports JPG and PNG format
                    }
                ]
            }
        }
        res = requests.post(url=send_url, headers=headers, json=send_data)
        print(res.text)

if __name__ == '__main__':
    sms = WXWork_SMS()
    sms.send_msg_txt_img()
Copy the code

The last

Did you learn? Go test it out for yourself!!