0
点赞
收藏
分享

微信扫一扫

企业微信机器人发送消息脚本

需要获取如下地址填入代码即可

企业微信机器人发送消息脚本_json


Python代码

import requests
import json

# 企业微信机器人 Webhook 地址
webhook_url = '填入发送地址即可'

# 发送消息的函数
def send_message(msg):
    headers = {'Content-Type': 'application/json'}
    data = {'msgtype': 'text', 'text': {'content': msg}}
    r = requests.post(webhook_url, headers=headers, data=json.dumps(data))
    return r.json()
# 调用函数发送消息
if __name__ == "__main__":
    while True:
        sen_data = input("请输入你要发送的消息数据:")
        if sen_data == "exit" :
            send_message("管理员邓鹏已经退出群发信息")
            exit()
        else:
            send_message(sen_data)


Powershell代码

$webhookUrl = '填入发送地址即可'

function Send-Message {
    param (
        [string]$msg
    )
    
    $jsonPayload = @{
        msgtype = "text"
        text = @{
            content = $msg
        }
    } | ConvertTo-Json -Depth 10
    
    Invoke-RestMethod -Uri $webhookUrl -Method Post -Body $jsonPayload -ContentType 'application/json; charset=utf-8'
}

$sendMessage = Read-Host -Prompt "请输入要发送的消息"

Send-Message -msg $sendMessage


Shell代码

#!/bin/bash
# 企业微信机器人 Webhook 地址
webhookUrl="填入发送地址即可"

function send_message {
    local message=$1
    
    jsonPayload=$(cat <<EOF
{
    "msgtype": "text",
    "text": {
        "content": "$message"
    }
}
EOF
)

    curl -H "Content-Type: application/json" -X POST -d "$jsonPayload" $webhookUrl
}

read -p "请输入要发送的消息: " sendMessage

send_message "$sendMessage"


举报

相关推荐

0 条评论