open_server_hw.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. # open_server_hw.sh
  3. # Call the gmweb /v1/pay/openServer endpoint for overseas (HW) open-server notification.
  4. # Usage:
  5. # ./open_server_hw.sh sid name time gameid signkey
  6. # ./open_server_hw.sh <base_url> sid name time gameid signkey
  7. # Examples:
  8. # ./open_server_hw.sh 1 "Server One" "2026-02-01 10:00:00" mygamekey mysignkey
  9. # ./open_server_hw.sh http://127.0.0.1:8080/v1/pay/openServer 1 "Server One" "2026-02-01 10:00:00" mygamekey mysignkey
  10. # Notes:
  11. # - If you provide 5 args (or 6 with base URL), the script will work as before.
  12. # - If `time` is passed without quotes (split into multiple tokens like 2025-11-20 12:00:00),
  13. # the script will rejoin the middle tokens into the time string automatically.
  14. # - Values that include spaces are still best passed quoted; this just provides convenience for the
  15. # common date-time case where users forget to quote the string.
  16. # - The script uses curl --get --data-urlencode so values are URL-encoded safely.
  17. usage() {
  18. echo "Usage: $0 sid name time gameid signkey"
  19. echo " or: $0 <base_url> sid name time gameid signkey"
  20. exit 1
  21. }
  22. DEFAULT_URL="http://127.0.0.1:8086/v1/pay/openServer"
  23. if [ $# -lt 5 ]; then
  24. usage
  25. fi
  26. # detect optional base URL (starts with http:// or https://)
  27. case "$1" in
  28. http://*|https://*)
  29. BASE_URL="$1"
  30. shift
  31. ;;
  32. *)
  33. BASE_URL="$DEFAULT_URL"
  34. ;;
  35. esac
  36. # Now we expect at least 5 positional parts: sid name time... gameid signkey
  37. if [ $# -lt 5 ]; then
  38. usage
  39. fi
  40. sid="$1"
  41. name="$2"
  42. # We treat the last two tokens as gameid and signkey, and everything between name and gameid as the time
  43. # Count remaining args
  44. N=$#
  45. # get signkey (last arg)
  46. signkey=$(eval "echo \${$N}")
  47. # get gameid (arg N-1)
  48. idx=`expr $N - 1`
  49. gameid=$(eval "echo \${$idx}")
  50. # build time from args 3 .. N-2
  51. time=""
  52. start=3
  53. end=`expr $N - 2`
  54. idx=$start
  55. while [ $idx -le $end ]; do
  56. part=$(eval "echo \${$idx}")
  57. if [ -z "$time" ]; then
  58. time="$part"
  59. else
  60. time="$time $part"
  61. fi
  62. idx=`expr $idx + 1`
  63. done
  64. if ! command -v curl >/dev/null 2>&1; then
  65. echo "curl not found. Please install curl."
  66. exit 1
  67. fi
  68. echo "Calling ${BASE_URL} with:" \
  69. "sid=${sid}" "name=${name}" "time=${time}" "gameid=${gameid}"
  70. # Use curl --get --data-urlencode for safe encoding of parameters (handles spaces and special chars)
  71. curl -S -G "$BASE_URL" \
  72. --data-urlencode "sid=${sid}" \
  73. --data-urlencode "name=${name}" \
  74. --data-urlencode "time=${time}" \
  75. --data-urlencode "gameid=${gameid}" \
  76. --data-urlencode "signkey=${signkey}"
  77. echo
  78. echo "-----done-----"