| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #!/bin/sh
- usage() {
- echo "Usage: $0 serNum uid \"title\" \"content\" [reward]"
- exit 1
- }
- # Positional parameters only: serNum uid title content [reward]
- serNum="$1"
- uid="$2"
- title="$3"
- content="$4"
- reward="${5:-0}"
- # Validate required params
- if [ -z "$serNum" ] || [ -z "$uid" ]; then
- echo "server id and uid are required"
- usage
- fi
- # urlencode: prefer python3, then python, fallback to simple sed
- urlencode() {
- if command -v python3 >/dev/null 2>&1; then
- python3 -c "import sys,urllib.parse as u; print(u.quote(sys.argv[1]))" "$1"
- elif command -v python >/dev/null 2>&1; then
- python -c "import sys,urllib; print(urllib.quote(sys.argv[1]))" "$1"
- else
- # best-effort simple replacement for common problematic chars
- 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'
- fi
- }
- # ...existing code... (server list lookup)
- url=""
- for server in `cat /data/shell/jenkins/serverlist`;do
- attr1=`echo $server | cut -d',' -f1`
- attr2=`echo $server | cut -d',' -f2`
- if [[ $attr1 == $serNum ]];then
- url=$attr2
- break
- fi
- done
- if [[ $url == "" ]];then
- echo "服务器未配置,需要手动添加"
- exit 0
- fi
- echo "传入的服务器id:$serNum"
- echo "传入的玩家uid:$uid"
- echo "传入的邮件标题:$title"
- echo "传入的邮件内容:$content"
- echo "传入的邮件奖励:$reward"
- # URL-encode title and content
- enc_title=$(urlencode "${title}")
- enc_content=$(urlencode "${content}")
- if [[ "$reward" == "0" ]];then
- curl "${url}/gm/mail?type=add&id=1&uid=${uid}&title=${enc_title}&content=${enc_content}"
- else
- curl "${url}/gm/mail?type=add&id=1&uid=${uid}&title=${enc_title}&content=${enc_content}&reward=${reward}"
- fi
- echo "-----执行完毕-----"
|