溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

MSSQL/WMI/PowerShell結(jié)合篇(四)PowerShell發(fā)送微信信息

發(fā)布時(shí)間:2020-06-24 22:31:00 來(lái)源:網(wǎng)絡(luò) 閱讀:941 作者:易語(yǔ)隨風(fēng)去 欄目:系統(tǒng)運(yùn)維

本文介紹如何通過(guò)PowerShell發(fā)送微信信息


先申請(qǐng)企業(yè)微信(企業(yè)、政府、組織三種類(lèi)型),通過(guò)PowerShell調(diào)用企業(yè)微信的API群發(fā)接口發(fā)送微信信息,API詳細(xì)信息可參考企業(yè)微信開(kāi)發(fā)者文檔


以下為PowerShell調(diào)用企業(yè)微信API發(fā)送文本信息

----Script File: send_WeChat.ps1


param($param1,$param2,$param3)


##設(shè)置16-32位長(zhǎng)度的密鑰

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($_))}

}


##發(fā)送微信方法

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

}


##解析帳號(hào)密碼

$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


##調(diào)用發(fā)送方法

send_WeChat_To_DBA -corpid $corpid -pwd $pwd -Content $content



##send_WeChat.ps1調(diào)用方式

E:\Monitor\send_WeChat.ps1 $param1 $param2 $param3


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI