#!/bin/bash #返回access token function getToken(){ #传入参数$1为corpid,参数$2为corpsecret curl -s "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$1&corpsecret=$2" | awk -F '"' '{print $4}' } #返回media_id function getMediaId(){ #传入参数$1为access token;参数$2为图片文件 curl -s -F media=@$2 "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=$1&type=p_w_picpath" | awk -F '"' '{print $8}' } #发送文字消息 function sendText(){ #传入参数$1为access token,$2为消息内容,$3指定接收消息的账号 curl -d '{"touser": "'$3'", "msgtype": "text", "agentid": 0, "text": {"content": "'$2'"}, "safe":"0"}' "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$1" } #发送图片消息 function sendImage(){ #传入参数$1为access token;参数$2为media_id,$3指定接收消息的账号 postdata='{"touser": "'$3'", "msgtype": "p_w_picpath", "agentid": 0, "p_w_picpath": {"media_id": "'$2'"}, "safe":"0"}' curl -d "$postdata" "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$1" } corpid='xxxxxxxxxx' #使用前面记下来的值替换 corpsecret='xxxxxxxxxxxxxxxxxxxxxxxxxxxxx' #使用前面记下来的值替换 p_w_picpath='test.png' text='这是发送的内容' receiver='mer_aqu' #此处为接收者的id,根据企业号后台的设置(ID),可以是手机号、微信号或其它的。同时发送到多个关注者用“|”隔开。 token=`getToken $corpid $corpsecret` sendText $token $text $receiver media_id=`getMediaId $token $p_w_picpath` sendImage $token $media_id $receiver
微信企业号:shell定时发送图片 到 指定人
原创
©著作权归作者所有:来自51CTO博客作者go工程师的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Alertmanager告警发送到企业微信群机器人Prometheus Alertmanager 监控告警 企业 群机器人
-
PowerShell收集服务器日检报告,并发邮件给指定人员
PowerShell收集服务器日检报告,并发邮件给指定人员
PowerShell 服务器信息 服务器信息邮件发送