#!/bin/sh # open_server_hw.sh # Call the gmweb /v1/pay/openServer endpoint for overseas (HW) open-server notification. # Usage: # ./open_server_hw.sh sid name time gameid signkey # ./open_server_hw.sh sid name time gameid signkey # Examples: # ./open_server_hw.sh 1 "Server One" "2026-02-01 10:00:00" mygamekey mysignkey # ./open_server_hw.sh http://127.0.0.1:8080/v1/pay/openServer 1 "Server One" "2026-02-01 10:00:00" mygamekey mysignkey # Notes: # - If you provide 5 args (or 6 with base URL), the script will work as before. # - If `time` is passed without quotes (split into multiple tokens like 2025-11-20 12:00:00), # the script will rejoin the middle tokens into the time string automatically. # - Values that include spaces are still best passed quoted; this just provides convenience for the # common date-time case where users forget to quote the string. # - The script uses curl --get --data-urlencode so values are URL-encoded safely. usage() { echo "Usage: $0 sid name time gameid signkey" echo " or: $0 sid name time gameid signkey" exit 1 } DEFAULT_URL="http://127.0.0.1:8086/v1/pay/openServer" if [ $# -lt 5 ]; then usage fi # detect optional base URL (starts with http:// or https://) case "$1" in http://*|https://*) BASE_URL="$1" shift ;; *) BASE_URL="$DEFAULT_URL" ;; esac # Now we expect at least 5 positional parts: sid name time... gameid signkey if [ $# -lt 5 ]; then usage fi sid="$1" name="$2" # We treat the last two tokens as gameid and signkey, and everything between name and gameid as the time # Count remaining args N=$# # get signkey (last arg) signkey=$(eval "echo \${$N}") # get gameid (arg N-1) idx=`expr $N - 1` gameid=$(eval "echo \${$idx}") # build time from args 3 .. N-2 time="" start=3 end=`expr $N - 2` idx=$start while [ $idx -le $end ]; do part=$(eval "echo \${$idx}") if [ -z "$time" ]; then time="$part" else time="$time $part" fi idx=`expr $idx + 1` done if ! command -v curl >/dev/null 2>&1; then echo "curl not found. Please install curl." exit 1 fi echo "Calling ${BASE_URL} with:" \ "sid=${sid}" "name=${name}" "time=${time}" "gameid=${gameid}" # Use curl --get --data-urlencode for safe encoding of parameters (handles spaces and special chars) curl -S -G "$BASE_URL" \ --data-urlencode "sid=${sid}" \ --data-urlencode "name=${name}" \ --data-urlencode "time=${time}" \ --data-urlencode "gameid=${gameid}" \ --data-urlencode "signkey=${signkey}" echo echo "-----done-----"