Python企业微信机器人

# 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="天气:{} \n 气温:{}".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')

 

pip install -i https://pypi.douban.com/simple pyinstaller
pyinstaller -F -w -i xxx.ico yy.py
在dist目录下面生成exe文件

你可能感兴趣的:(Python)