mail_role.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. usage() {
  3. echo "Usage: $0 serNum uid \"title\" \"content\" [reward]"
  4. exit 1
  5. }
  6. # Positional parameters only: serNum uid title content [reward]
  7. serNum="$1"
  8. uid="$2"
  9. title="$3"
  10. content="$4"
  11. reward="${5:-0}"
  12. # Validate required params
  13. if [ -z "$serNum" ] || [ -z "$uid" ]; then
  14. echo "server id and uid are required"
  15. usage
  16. fi
  17. # urlencode: prefer python3, then python, fallback to simple sed
  18. urlencode() {
  19. if command -v python3 >/dev/null 2>&1; then
  20. python3 -c "import sys,urllib.parse as u; print(u.quote(sys.argv[1]))" "$1"
  21. elif command -v python >/dev/null 2>&1; then
  22. python -c "import sys,urllib; print(urllib.quote(sys.argv[1]))" "$1"
  23. else
  24. # best-effort simple replacement for common problematic chars
  25. printf '%s' "$1" | sed -e 's/ /%20/g' -e 's/&/%26/g' -e 's/?/%3F/g' -e 's/+/ %2B/g' -e 's/=/ %3D/g' | sed 's/ */ /g'
  26. fi
  27. }
  28. # ...existing code... (server list lookup)
  29. url=""
  30. for server in `cat /data/shell/jenkins/serverlist`;do
  31. attr1=`echo $server | cut -d',' -f1`
  32. attr2=`echo $server | cut -d',' -f2`
  33. if [[ $attr1 == $serNum ]];then
  34. url=$attr2
  35. break
  36. fi
  37. done
  38. if [[ $url == "" ]];then
  39. echo "服务器未配置,需要手动添加"
  40. exit 0
  41. fi
  42. echo "传入的服务器id:$serNum"
  43. echo "传入的玩家uid:$uid"
  44. echo "传入的邮件标题:$title"
  45. echo "传入的邮件内容:$content"
  46. echo "传入的邮件奖励:$reward"
  47. # URL-encode title and content
  48. enc_title=$(urlencode "${title}")
  49. enc_content=$(urlencode "${content}")
  50. if [[ "$reward" == "0" ]];then
  51. curl "${url}/gm/mail?type=add&id=1&uid=${uid}&title=${enc_title}&content=${enc_content}"
  52. else
  53. curl "${url}/gm/mail?type=add&id=1&uid=${uid}&title=${enc_title}&content=${enc_content}&reward=${reward}"
  54. fi
  55. echo "-----执行完毕-----"