TaoGOGO的技术博客,始于2007年,通过文字分享技术、记录生活

python发送飞信脚本

2012-07-13

用python模拟登陆,发送飞信,现在还能用,header里面的user-agent不要发送

#-*- coding:UTF-8 -*-

import urllib,urllib2,cookielib,re
class Fetion:
    __mobile = ''
    __password = ''
    __cookie = None
    __cookieFile = './fetion_cookie.dat'
    __serverUrl = "http://f.10086.cn"
    __header = {
        "Host":"f.10086.cn",
        "Content-Type":"application/x-www-form-urlencoded",
       # "User-Agent":"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5",
        }


    def __init__(self,mobile,passwd):
        self.__mobile = mobile
        self.__password = passwd
        self.__cookie = cookielib.LWPCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.__cookie))
        urllib2.install_opener(opener)


    def login(self):
        postData = {
            'm':self.__mobile,
            'pass':self.__password,
            'loginstatus':1
        }


        postUri = "/im/login/inputpasssubmit1.action"


        return self.__postByCookie( postUri , postData )


    def getFetionUid(self , mobile):
        postData = {
            'searchText':mobile,
        }


        postUri = "/im/index/searchOtherInfoList.action"


        result = self.__postByCookie( postUri , postData )
        uids = re.findall(r"name="internalid" value="(d*?)" />", str( result ))


        return uids[0]


    def __toFetionUid(self,fetionUid,msg):


        postData = {
            'msg':msg,
            }


        postUri = "/im/chat/sendMsg.action?touserid="+fetionUid


        return self.__postByCookie( postUri , postData )


    def send(self,mobile,msg):
        if( msg =="" ):
            raise Exception( "message is empty" )
            #Exception.__init__()
            return False
        if( mobile == self.__mobile):
            return self.toSelf( msg )


        fetionUid = self.getFetionUid( mobile )
        return self.__toFetionUid( fetionUid , msg )


    def toSelf(self,msg):
        postData = {
            'msg':msg,
            }


        postUri = "/im/user/sendMsgToMyselfs.action"


        return self.__postByCookie( postUri , postData )


    def __postByCookie(self , path  , postData ):


        #发起请求
        req = urllib2.Request(
            url=self.__serverUrl + path,
            data= urllib.urlencode(postData),#请求数据
            headers = self.__header #请求头
        )


        result = urllib2.urlopen(req).read()
        self.__cookie.save(self.__cookieFile)
        return  result


    def logout(self):
        postData = {}
        postUri = "/im/index/logoutsubmit.action"


        return self.__postByCookie( postUri , postData )
    def __del__(self):
        #self.logout()
        pass


'''
fetionObj = Fetion("13681462000" , "mima")
fetionObj.login()


print fetionObj.send("13681462000","定时任务执行完毕1,gaga")
fetionObj.logout()

类别: | 阅读:180303 | 评论:3 | 标签:python 飞信

想收藏或者和大家分享这篇好文章→

“python发送飞信脚本”共有3条留言

  1. taogogo @2013-06-12 16:10 回复

    @珏 这个脚本现在已经不可用了,你需要自己分析f.10086.cn 的代码

  2. @2013-06-12 13:23 回复

    邮箱的判断也有问题,现在QQ邮箱已经很常用了,但使用qq
    邮箱却不能在你这留言、、、可能是正则表达式出问题了吧

  3. @2013-06-12 13:22 回复

    你好,这个程序有语法错误,修正后扔不能用,我是来请教如何通过程序使用飞信给指定的人定期发送信息的,比如天气预报,我见你在micolog上上传过一个雅虎天气预报的插件,貌似它现在不能用了

发表评论

姓名:

邮箱:

网址:

验证码:

公告

҉百度内部推荐,高级研发/PM(需2年以上工作经验)。
有意者微博私信联系~

微博言语

文章分类