linux shell 发送图片,微信企业号:shell定时发送图片 到 指定人

#!/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=image" | 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": "image", "agentid": 0, "image": {"media_id": "'$2'"}, "safe":"0"}'

curl -d "$postdata"  "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$1"

}

corpid='xxxxxxxxxx' #使用前面记下来的值替换

corpsecret='xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'  #使用前面记下来的值替换

image='test.png'

text='这是发送的内容'

receiver='mer_aqu' #此处为接收者的id,根据企业号后台的设置(ID),可以是手机号、微信号或其它的。同时发送到多个关注者用“|”隔开。

token=`getToken $corpid $corpsecret`

sendText $token $text $receiver

media_id=`getMediaId $token $image`

sendImage $token $media_id $receiver

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值