发送文本类型消息
Import-Module Microsoft.PowerShell.Utility
Function SendWechat($user,$days) {
$corpid = "wechat"
$secret = "123-446"
$agentid = "1000000"
$auth_sring = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$secret"
$auth_values = Invoke-RestMethod $auth_sring
$token = $auth_values.access_token
$content = "$user 您好,您的邮箱密码即将在 $days 天后过期"
$body = "{
`"touser`":`"$user`",
`"agentid`":`"$agentid`",
`"text`":{`"content`":`"$content`"},
`"msgtype`":`"text`"
}"
$body_u8 = [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 $body_u8
}
$user = "zhangsan"
SendWechat $user 6
发送卡片类型消息
Function SendWechatCard($user,$days) {
$corpid = "wecorp"
$secret = "1234"
$agentid = "1000000"
$auth_sring = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$secret"
$auth_values = Invoke-RestMethod $auth_sring
$token = $auth_values.access_token
$content = "$user 您好,您的邮箱密码即将在 $days 天后过期,为了不影响您正常登录公司系统,请尽快修改新密码"
$body = "{
`"touser`":`"$user`",
`"agentid`":`"$agentid`",
`"textcard`":{`"title`":`"密码到期提醒`",`"description`":`"$content`",`"url`":`"www.baidu.com`",`"btntext`":`"More`"},
`"msgtype`":`"textcard`"
}"
$body_u8 = [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 $body_u8
}