秒嘀短信(三)curl发送短信

api文档:https://www.miaodiyun.com/developer.html#smsSend

请求地址: https://openapi.miaodiyun.com/distributor/sendSMS

请求方式: POST

编码格式: UTF-8

响应格式: JSON,XML

请求包头: Content-type:application/x-www-form-urlencoded

请求参数:

请求字段 是否必返 字段说明
respDataType 可选 响应数据类型,JSON 或 XML 格式。默认为JSON
accountSid 必填 开发者主账号(ACCOUNT SID)。开发者账号唯一标识符
templateid 可选 模板ID,和短信内容必传一个
smsContent 可选 短信内容,和模板ID必传一个
to 必填 发送手机号,多个手机号,用英文逗号隔开
timestamp 必填 时间戳(毫秒),格式:1547005945480
sig 必填 签名:MD5(ACCOUNT SID + AUTH TOKEN + timestamp)。共32位(小写)
expandId 可选 短信扩展号
param 可选 短信变量,多个变量用英文逗号隔开
subCode 可选 中转子码
accountId 可选 子账号ID
smsType 可选 短信类型(100000:验证码通知,100003:会员营销)

短信模版我已经申请好了,真的不容易

模版编号是239595,这个号码待会儿要用,短信内容传递了6个变量,待会儿也要传递用

shell脚本

这个变量按顺序写进去就行了,我的是zabbix报警短信,第一个变量和最后一个变量随便填的

[root@tomcat1 ~]# cat send_ms.sh 
URL="https://openapi.miaodiyun.com/distributor/sendSMS"
accountSid=2xxxxxxxxxxxxxxxxxxxxe
timestamp="$(date +%s)000"
auth_token="3xxxxxxxxxxxxxxxxx59c"
sig=$(echo -n "${accountSid}${auth_token}${timestamp}" | md5sum - | awk '{print $1}')
templateid=239595
to=15674708129
#param是变量,三个变量的话就按顺序写进去
param="50,12:47:03 on 2019.06.13,Zabbix agent on Cali is unreachable for 5 minutes,cali,average,0"
smsType=100000

curl -s -X "POST" "${URL}"  \
    -H "Content-type:application/x-www-form-urlencoded" \
    -d "accountSid=${accountSid}" \
    -d "timestamp=${timestamp}" \
    -d "sig=${sig}" \
    -d "templateid=${templateid}" \
    -d "to=${to}" \
    -d "param=${param}" \
    -d "smsType=${smsType}"

效果:

遇到的问题:

1、param变量传递问题

原来,变量依次写到param里面就行了