Python enterprise micro-channel robot

# coding=gbk
import requests

#文字(text)机器人
def tony_bot_txt(boturl):
    storename='株洲'
    amount=12345.5
    headers={"Content-Type":"text/plain"}
    msg="门店:{}\n销售额:{}元".format(storename,str(amount))
    data={

        "msgtype": "text",

        "text": {
        "content": msg,

        "mentioned_list":["tony","@all"]
        }}
    res=requests.post(url=boturl,headers=headers,json=data)
    print(res.text)

#文字标记(markdown)机器人
def tony_bot_txt_markdown(boturl):
    weather="下雨"
    temperature="20度"
    headers={"Content-Type":"text/plain"}
    msg="天气:<font color=\"info\">{}</font> \n 气温:<font color=\"warning\">{}</font>".format(weather,temperature)
    data={
        "msgtype": "markdown",
 
        "markdown": {

        "content": msg
        }
}
    res=requests.post(url=boturl,headers=headers,json=data)
    print(res.text)


#带图片的机器人
def tony_bot_img(boturl):
    num=10
    money=1002.5
    headers={"Content-Type":"text/plain"}
    msg="数量:{}\n金额:{}元".format(str(num),str(money))
    data={
        "msgtype": "news",
        "news": {
 
        "articles" : [
{
 
             "title" : "庆祝新中国成立70周年",

             "description" : "新中国70周年的阅兵仪式,欢迎收看!",
             "url" : "https://www.baidu.com",

             "picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png"

             }]
}

    }
    res=requests.post(url=boturl,headers=headers,json=data)
    print(res.text)
#测试的企业微信机器人
tony_bot_txt('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx')
tony_bot_txt_markdown('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx')
tony_bot_img('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx')

 

-i https://pypi.douban.com/simple pyinstaller the install PIP
pyinstaller -F -w -i xxx.ico yy.py
generated exe file below the directory dist

Published 46 original articles · won praise 9 · views 3644

Guess you like

Origin blog.csdn.net/weixin_41896770/article/details/103089039