利用飞信给自己发短信的shell脚本(2012-12-31更新,处理验证码,目前可用)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/maxjove/article/details/7211337

利用飞信给自己发短信的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}



展开阅读全文

飞信发短信,openfetion怎么用?

08-20

rn下载到了openfetion。不过不知道怎么用。rn贴接口代码:rn[code=PHP] */rnfunction main($argc, $argv) rn global $fetion_proxy;rn global $fetion_debug;rn $user_mobile = "13500000000";rn $password = "xxxxx";rn $sendto_sid = "xxxxx";rn $content = "xxxxx";rnrn if ($argc < 2) rn usage();rn return 1;rn rn for ($I = 1; $I < $argc; ++$I) rn if ($argv[$I] == '-p') rn $fetion_proxy = $argv[++$I];rn else if ($argv[$I] == '-d') rn $fetion_debug = true;rn else rn $user_mobile = $argv[$I++];rn $password = $argv[$I++];rn if (isset($argv[$I])) rn $sendto_sid = $argv[$I++];rn $content = $argv[$I];rn rn break;rn rn rnrn $login_info = fetion_login($user_mobile, $password);rn if ($login_info === false) rn print "[*] login failed\r\n";rn return 1;rn rn $ssic = $login_info['ssic'];rn $sid = $login_info['sid'];rn $domain = $login_info['domain'];rn print "[*] login successful\r\n";rn $ok = fetion_http_register($ssic, $sid, $domain, $password);rn if ($ok === false) rn print "[*] register failed\r\n";rn return 1;rn rn print "[*] register successful\r\n";rnrn if (empty($sendto_sid) || empty($content)) rn $buddies = fetion_get_buddy_list($ssic, $sid);rn if ($buddies === false) rn print "[*] get buddy list failed\r\n";rn else rn print " [sid] [name]\r\n";rn foreach ($buddies as $sid=>$name) rn printf(" %35s => %s\r\n", $sid, $name);rn rn rn else rn $ok = fetion_http_send_sms($ssic, $sid, $sendto_sid, $content);rn print "[*] send sms ".strval($ok ? 'successful' : 'failed')."\r\n";rn rnrnmain($argc, $argv);[/code]rn前面的$sendto_sid是什么意思了?rn还有main($argc, $argv)里参数怎么填?rnrn还有没有其它方法可以免费发短信的?rnrn谢谢了 论坛

没有更多推荐了,返回首页