shell机器人企业微信通知

 vi  test.sh

curl 那行是机器人webbook

   #/bin/bash
   
   curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=cd462b46-a552-422b-3123-2313111331231231' \
   -H 'Content-Type: application/json' \
   -d '
   {
        "msgtype": "text",
        "text": {
            "content": "test\n [爱心]请点击以下链接\nhttps://123.com/projects\n[嘿哈][嘿哈]",
            "mentioned_list":["ALL"]
        }
   }'

ALL改@ALL 会@所有人

chmod +x test.sh

./test.sh

其它格式https://work.weixin.qq.com/api/doc/90000/90135/90236

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要实现在用户登录后通过微信通知的功能,您需要使用以下步骤: 1. 安装 WeChat Work API Python SDK。 2. 创建企业微信应用,获取应用 ID(agentid)、CorpID、SecretKey。 3. 使用 Python 编写脚本,通过调用 WeChat Work API 实现微信通知功能。可以使用以下代码: ```python import requests # 设置企业微信应用参数 CORP_ID = "your_corp_id" AGENT_ID = "your_agent_id" SECRET_KEY = "your_secret_key" # 获取 access_token def get_access_token(): url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}".format(CORP_ID, SECRET_KEY) result = requests.get(url).json() return result["access_token"] # 发送消息 def send_message(content): access_token = get_access_token() url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + access_token data = { "touser": "@all", "msgtype": "text", "agentid": AGENT_ID, "text": {"content": content}, "safe": 0 } result = requests.post(url, json=data).json() return result # 监控用户登录 def monitor_login(user): send_message("用户 {} 已登录系统。".format(user)) # 主函数 if __name__ == "__main__": user = "testuser" monitor_login(user) ``` 4. 将上述代码保存为脚本文件(例如,monitor_login.sh)。 5. 使用 crontab 在用户登录后执行该脚本。例如,您可以在 /etc/profile 中添加以下内容: ```bash # 在用户登录后执行微信通知脚本 if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then /path/to/monitor_login.sh fi ``` 这样,当用户登录系统时,脚本将被执行,并通过企业微信应用向所有用户发送通知消息。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值