54 lines
1.3 KiB
Bash
54 lines
1.3 KiB
Bash
#!/bin/bash
|
|
QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g')
|
|
urldecode() {
|
|
local data
|
|
data="${*//+/ }"
|
|
echo -e "${data//%/\\x}"
|
|
}
|
|
|
|
if [ "${QUERY_STRING}" ]; then
|
|
export IFS="&"
|
|
for cmd in ${QUERY_STRING}; do
|
|
if [[ "$cmd" == *=* ]]; then
|
|
key=$(echo "$cmd" | awk -F '=' '{print $1}')
|
|
value=$(echo "$cmd" | awk -F '=' '{print $2}')
|
|
eval "$key"="$(urldecode "$value")"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
phone_number="$number"
|
|
message_encoded="$msg"
|
|
|
|
phone_number="+86$phone_number"
|
|
|
|
send_at_command() {
|
|
local cmd=$1
|
|
echo "Sending command: $cmd" >&2
|
|
echo -en "$cmd\r" | microcom -t 1000 /dev/ttyOUT2
|
|
sleep 2
|
|
local response=$(microcom -t 1000 /dev/ttyOUT2)
|
|
echo "Response: $response" >&2
|
|
echo "$response"
|
|
}
|
|
|
|
send_at_command "AT+CMGF=1"
|
|
send_at_command "AT+CSCS=\"UCS2\""
|
|
|
|
encode_ucs2() {
|
|
local input="$1"
|
|
local output=""
|
|
local i
|
|
for ((i=0; i<${#input}; i++)); do
|
|
hex=$(printf "%04X" "'${input:$i:1}")
|
|
output="$output$hex"
|
|
done
|
|
echo "$output"
|
|
}
|
|
|
|
phone_number_ucs2=$(encode_ucs2 "$phone_number")
|
|
ATCMD="AT+CMGS=\"$phone_number_ucs2\""
|
|
send_at_command "$ATCMD"
|
|
|
|
runcmd=$((echo -en "$message_encoded"; sleep 1; echo -en "\x1A") | microcom -t 1000 /dev/ttyOUT2)
|
|
echo "$runcmd" |