Created
November 22, 2018 04:13
-
-
Save CuberL/fa758c2361a8ee2d89b201b491bb0050 to your computer and use it in GitHub Desktop.
sendsms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AccessKeyId LTAIL****N6gpzW6 | |
SignatureVersion 1.0 | |
SignatureMethod HMAC-SHA1 | |
Format JSON | |
Action SendSms | |
Version 2017-05-25 | |
RegionId cn-hangzhou | |
SignName **** | |
TemplateCode **** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage | |
# echo -e "PhoneNumber 1300000000\nTemplateParam {...}" | ./sendsms.sh | |
secretKey="z71BMf**********fB58aQdlSqxNZ7" | |
urlencode() { | |
local str=`echo ${@:1}`; | |
local length=${#str}; | |
for (( i = 0; i < length; i++ )); do | |
local c="${str:i:1}" | |
case $c in | |
[a-zA-Z0-9.*\-_]) printf "$c" ;; | |
'\ ') printf "+" ;; | |
'%') printf "%%25" ;; | |
*) printf "$c" | xxd -p -u -c1 | while read x;do printf "%%%s" "$x";done | |
esac | |
done | |
} | |
special_urlencode() { | |
result=`urlencode $1 | sed 's/+/%20/g' | sed "s/\*/\%2A/g" | sed "s/\%7E/~/g"` | |
echo $result | |
} | |
getArgs() { | |
paras=`echo "${@:1}" | sort | awk '{printf("$(special_urlencode \"%s\")=$(special_urlencode \"%s\")&", $1, $2)}'` | |
cmd='echo "'${paras}'"' | |
args=$(eval $cmd) | |
echo ${args%?} | |
} | |
sign() { | |
stringToSign=`echo $(special_urlencode "${@:1}")` | |
sign=`echo -n "GET&%2F&${stringToSign}" | openssl dgst -binary -sha1 -hmac "${secretKey}&" | base64` | |
signEncoded=`echo $(special_urlencode "$sign")` | |
echo $signEncoded | |
} | |
send() { | |
input=`echo "${@:1}"` | |
uuid="SignatureNonce $(uuidgen)" | |
date="Timestamp $(TZ=GMT date +%Y-%m-%dT%H:%M:%SZ)" | |
args=`echo -e "$input\n$uuid\n$date"` | |
echo "$args" | |
allArgs=$(getArgs "$args") | |
signValue=$(sign "$allArgs") | |
data=`echo "${allArgs}&Signature=${signValue}"` | |
# echo "http://dysmsapi.aliyuncs.com?${data}" | |
curl "http://dysmsapi.aliyuncs.com?${data}" | |
} | |
send "`paste -s -d "\n" /dev/stdin ./config`" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment