利用飞信给自己发短信的shell脚本翻译自一个python脚本因为openwrt要装python太大了.所以用了两天非工作时间 翻译成了 shell脚本 .测试可用.
2012-12-31 更新:由于移动飞信加了验证码原来的已经不能用了,用了另一种方式处理了验证码现在可用。可用代码如下:
#!/bin/sh
#Convert Python Fetion To Shell @2012
user='xxxxxxxxx' #飞信账号 一般是你的手机号
password='xxxxx' #飞信密码,但愿只有你自己知道.
url_login='http://f.10086.cn/im5/login/loginHtml5.action' #'http://f.10086.cn/im/login/inputpasssubmit1.action'
url_logout='http://f.10086.cn/im5/login/login.action?type=logout'
url_msg='http://f.10086.cn/im5/chat/sendNewGroupShortMsg.action'
TempDir='/tmp/shfethionTmp'
Uagent='Mozilla/5.0'
if [ $# -ge 1 ]; then
msg=$1
else
read -p "please enter :" msg
fi
echo $msg
echo `date`
if [ -d "$TempDir" ]; then
rm -rf ${TempDir}
mkdir -p "$TempDir"
else
mkdir -p "$TempDir"
fi
throw () {
echo "$*" >&2
exit 1
}
tokenize () {
local ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
local CHAR='[^[:cntrl:]"\\]'
local STRING="\"$CHAR*($ESCAPE$CHAR*)*\""
local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
local KEYWORD='null|false|true'
local SPACE='[[:space:]]+'
egrep -ao "$STRING|$NUMBER|$KEYWORD|$SPACE|." |
egrep -v "^$SPACE$" # eat whitespace
}
parse_array () {
local index=0
local ary=''
read -r token
case "$token" in
']') ;;
*)
while :
do
parse_value "$1" "$index"
let index=$index+1
ary="$ary""$value"
read -r token
case "$token" in
']') break ;;
',') ary="$ary," ;;
*) throw "EXPECTED , or ] GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
value=`printf '[%s]' "$ary"`
}
parse_object () {
local key
local obj=''
read -r token
case "$token" in
'}') ;;
*)
while :
do
case "$token" in
'"'*'"') key=$token ;;
*) throw "EXPECTED string GOT ${token:-EOF}" ;;
esac
read -r token
case "$token" in
':') ;;
*) throw "EXPECTED : GOT ${token:-EOF}" ;;
esac
read -r token
parse_value "$1" "$key"
obj="$obj$key:$value"
read -r token
case "$token" in
'}') break ;;
',') obj="$obj," ;;
*) throw "EXPECTED , or } GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
value=`printf '{%s}' "$obj"`
}
parse_value () {
local jpath="${1:+$1,}$2"
case "$token" in
'{') parse_object "$jpath" ;;
'[') parse_array "$jpath" ;;
# At this point, the only valid single-character tokens are digits.
''|[^0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;;
*) value=$token ;;
esac
printf "[%s]\t%s\n" "$jpath" "$value"
}
parse () {
read -r token
parse_value
read -r token
case "$token" in
'') ;;
*) throw "EXPECTED EOF GOT $token" ;;
esac
}
wget -q -P ${TempDir} --save-cookies=${TempDir}/cookie -U ${Uagent} --keep-session-cookies --post-data "m=${user}&pass=${password}&captchaCode=&checkCodeKey=null" ${url_login}
arg_t=`tokenize < ${TempDir}/loginHtml5.action | parse | grep -e '^\[\"headurl\"]'| awk '{print $2}'|sed 's/"//g' | grep -Eo 't=\w+'`
#echo ${arg_t}
idUser=`tokenize < ${TempDir}/loginHtml5.action | parse | grep -e '^\[\"idUser\"]'| awk '{print $2}'|sed 's/"//g'`
#echo ${idUser}
wget -q -P ${TempDir} --load-cookies=${TempDir}/cookie -U ${Uagent} --keep-session-cookies --post-data "msg=${msg}&touserid= ,${idUser}" ${url_msg}?${arg_t}
#sendNewGroupShortMsg.action
tokenize < ${TempDir}/sendNewGroupShortMsg.action?${arg_t} | parse | grep -e '^\[\"info\"]'|awk '{print $2}'|sed 's/"//g'
wget -q -P ${TempDir} --load-cookies=${TempDir}/cookie -U ${Uagent} --keep-session-cookies ${url_logout}"&"${arg_t}
echo `date`
echo 'send end!'
exit 0
#rm -rf ${TempDir}
以下已经不能用了,请忽略!能用的在上面。
#!/bin/sh
#Convert Python Fetion To Shell @2012
user='xxxxxxxxx' #飞信账号 一般是你的手机号
password='xxxxx' #飞信密码,但愿只有你自己知道.
loginstatus='4'
url_login='http://f.10086.cn/im/login/inputpasssubmit1.action'
url_logout='http://f.10086.cn//im/index/logoutsubmit.action'
url_msg='http://f.10086.cn/im/user/sendMsgToMyselfs.action'
TempDir='shfethionTmp'
read -p "please enter :" msg
echo $msg
if [ -d "$TempDir" ]; then
rm -rf ${TempDir}
mkdir "$TempDir"
else
mkdir "$TempDir"
fi
wget -q -P ${TempDir} --save-cookies=${TempDir}/cookie --keep-session-cookies --post-data "m=${user}&pass=${password}&loginstatus=${loginstatus}" ${url_login}
url=`grep -Eo '<card id="start".*?(ontimer="(.*?))' ${TempDir}/inputpasssubmit1.action | grep -Eo '(\/+[^\s]*)n'`
arg_t=`grep -Eo '<card id="start".*?(ontimer="(.*?))' ${TempDir}/inputpasssubmit1.action | grep -Eo 't=\w+'`
echo $url
if [ "${url}" = '/im/login/login.action' ];then
echo 'Login Failed!'
exit 0
else
echo 'Login Successfully!'
fi
wget -q -P ${TempDir} --load-cookies=${TempDir}/cookie --keep-session-cookies --post-data "msg=${msg}" ${url_msg}
echo $arg_t
wget -q -P ${TempDir} --load-cookies=${TempDir}/cookie --keep-session-cookies --post-data "${arg_t}" ${url_logout}
echo 'Logout Successfully!'
rm -rf ${TempDir}