Created
December 16, 2015 07:57
-
-
Save wsky/9cd419083e0aeb1655ef to your computer and use it in GitHub Desktop.
top api call
This file contains hidden or 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 | |
#how to: . call.sh | |
call_api() { | |
local APPKEY=$1 | |
local SECRET=$2 | |
local SESSION=$3 | |
local METHOD=$4 | |
local URL=$5 | |
local IP=$6 | |
local SSL=$7 | |
shift | |
shift | |
shift | |
shift | |
shift | |
shift | |
shift | |
local PARAMETERS_APP=("$@") | |
##################################################################################### | |
local PARAMETERS_BASE=( | |
"method=$METHOD" | |
"v=2.0" | |
"app_key=$APPKEY" | |
"timestamp=$(date +"%s")" | |
"format=json" | |
"partner_id=sdk-bash" | |
) | |
if [ $SESSION == "null" ] | |
then | |
echo "no session" | |
else | |
PARAMETERS_BASE=( | |
"${PARAMETERS_BASE[@]}" | |
"session=$SESSION" | |
) | |
fi | |
local PARAMETERS=( | |
"${PARAMETERS_APP[@]}" | |
"${PARAMETERS_BASE[@]}" | |
) | |
#http://www.microbrew.org/tools/md5sha1sum/md5sha1sum-0.9.5.tar.gz | |
#md5 sign | |
PARAMETERS=($(printf '%s\n' "${PARAMETERS[@]}"|sort)) | |
local SIGN=$SECRET | |
for a in "${PARAMETERS[@]}" | |
do | |
KEY="${a%%=*}" | |
VALUE="${a##*=}" | |
printf "%s=%s\n" "$KEY" "$VALUE" | |
SIGN=$SIGN$KEY$VALUE | |
done | |
#old | |
#SIGN=$SIGN$SECRET | |
echo $SIGN | |
SIGN="$(echo -n "$SIGN"|md5sum|awk '{print $1}')" | |
SIGN="$(echo "$SIGN"|awk '{print toupper($0)}')" | |
echo $SIGN | |
PARAMETERS=( | |
"${PARAMETERS[@]}" | |
"sign=$SIGN" | |
) | |
local QUERY="" | |
for a in "${PARAMETERS[@]}" | |
do | |
QUERY="$QUERY&$a" | |
done | |
QUERY="$(echo "$QUERY"| cut -c 2-)" | |
echo $QUERY | |
local URL="$URL?$QUERY" | |
echo "" | |
echo $URL | |
echo "" | |
curl -H "x-real-ip:$IP" -H "Top-LB-From:$SSL" "$URL" | |
echo "" | |
echo "" | |
} | |
Author
wsky
commented
Dec 16, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment