温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

通过Powershell 发送微信消息

发布时间:2020-07-14 06:10:45 来源:网络 阅读:3703 作者:handsome7038 栏目:开发技术

前期需要注册一个微信企业号(度娘可以找到好多帖子)这部分就不再详细说了。

主要通过Powershell 调取微信企业号API来实现发送消息的目的。

下面是一个写好的函数大家可以直接调用:

function send-weixin {
Param(
        [Parameter(Mandatory = $True, Position = 1)]
        [String]$Username,
        [Parameter(Mandatory = $True, Position = 2)]
        [String]$Content
      )
$auth_string = https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=【你自己的Corpid】&corpsecret= 【你自己的密码】
$auth_values = Invoke-RestMethod $auth_string
# Send message 下面是微信JSON内容的写法
$token = $auth_values.access_token
$body="{
`"touser`":`"$username`",
`"msgtype`":`"text`",
`"agentid`":`"1`",
`"text`":
{`"content`":`"$content`"},
`"safe`":`"0`"
}"
$chinese=[System.Text.Encoding]::UTF8.GetBytes($body) #这里是解决中文编码问题的即发送中文消息时候使用。
Invoke-RestMethod "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$token" -ContentType "application/json"  -Method Post  -Body $chinese
}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI