您好,登錄后才能下訂單哦!
本文介紹如何通過PowerShell發送微信信息
先申請企業微信(企業、政府、組織三種類型),通過PowerShell調用企業微信的API群發接口發送微信信息,API詳細信息可參考企業微信開發者文檔
以下為PowerShell調用企業微信API發送文本信息
----Script File: send_WeChat.ps1
param($param1,$param2,$param3)
##設置16-32位長度的密鑰
function Set-Key {
param([string]$string)
$length = $string.length
$pad = 32-$length
if (($length -lt 16) -or ($length -gt 32)) {Throw "String must be between 16 and 32 characters"}
$encoding = New-Object System.Text.ASCIIEncoding
$bytes = $encoding.GetBytes($string + "0" * $pad)
return $bytes
}
##解密方法
function Get-EncryptedData {
param($key,$data)
$data | ConvertTo-SecureString -key $key |
ForEach-Object {[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($_))}
}
##發送微信方法
function send_WeChat_To_DBA {
Param(
[String]$corpid,
[String]$pwd,
[String]$Content
)
$auth_string = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$pwd"
$auth_values = Invoke-RestMethod $auth_string
$token = $auth_values.access_token
$body="{
`"toparty`":`"receive group id`",
`"agentid`":`"your agent id`",
`"text`":{
`"content`":`"$content`"
},
`"msgtype`":`"text`"
}"
$CN=[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 $CN
}
##解析帳號密碼
$cidstr= Get-Content E:\Monitor\cidstr.txt;
$pwdstr = Get-Content E:\Monitor\keystr.txt;
$cidkey = Set-Key $cidstr;
$pwdkey = Set-Key $pwdstr;
$cidfromFile = Get-Content E:\Monitor\wxcid.txt;
$pwdfromFile = Get-Content E:\Monitor\wxpwd.txt;
$corpid = Get-EncryptedData -data $cidfromFile -key $cidkey;
$pwd = Get-EncryptedData -data $pwdfromFile -key $pwdkey;
$content=$param1+$param2+$param3
##調用發送方法
send_WeChat_To_DBA -corpid $corpid -pwd $pwd -Content $content
##send_WeChat.ps1調用方式
E:\Monitor\send_WeChat.ps1 $param1 $param2 $param3
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。