Created
July 22, 2020 02:52
-
-
Save hoangitk/25ac662f0818570b5d08fbf93e9f448a to your computer and use it in GitHub Desktop.
[send-weixin(wechat)] #powershell #wechat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://blog.51cto.com/lixiaosong/1689886 | |
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment