#!/bin/bash CropID='xxxxxxxxxxxxxxxxx' Secret='xxxxxxxxxxxxxxxx' GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret" Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F" '{print $10}') PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken" function body() { local int AppID=28 local UserID=$1 local PartyID=3 local Msg=$(echo "$@" | cut -d" " -f3-) printf '{ ' printf ' "touser" : "'"$UserID""", " printf ' "toparty" : "'"$PartyID""", " printf ' "totag" : "'"1""", " printf ' "msgtype" : "text", ' printf ' "agentid" : "'"$AppID""", " printf ' "text" : { ' printf ' "content" : "'"$Msg""" " printf ' } ' printf '} ' } /usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL