昨天突然想起来飞信有问题,怎么搞都不行,后来发现我用的那个飞信,,即使正常网页用也是这个问题
换了个接口,重新写了,从昨天晚上,每五分钟发一次,一直发到今天早上,今天早上又测试发送的频率,两分钟发了248条,然后被网站墙了(访问了大概一千五百次)
先发第一个模块
coding:utf-8
**import **re
**import **urllib
**import **urllib2
**import **cookielib
**class **CookieBrowser(object):
构造方法,用来传递初值
**def **__init__(self):
self.cookie=cookielib.MozillaCookieJar()
self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
**def **saveCookie(self,filename):
self.cookie.save(filename,ignore_expires=True,ignore_discard=True)
**def **loadCookie(self,filename):
self.cookie.load(filename,ignore_expires=True,ignore_discard=True)
**def **getCookies(self):
**return **self.cookie
**def **setCookies(self,cookie):
self.cookie=cookie
self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
**def **resetCookies(self):
self.cookie=cookielib.CookieJar()
self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
**def **open(self,addr,param):
**return **self.opener.open(addr,param)
**def **read(self,addr):
**return **self.opener.open(addr).read()
**def **post(self,url,**param):
postdata=urllib.urlencode(param)
**return **self.opener.open(url,postdata)
**def **rawpost(self,url,param):
**return **self.opener.open(url,param)
**def **hasStr(self,url,parrent):
**return **re.findall(parrent,self.read(url))
然后发飞信
coding:utf-8
**from **CookieBrowser **import **CookieBrowser
**import **json
**import **urllib
**import **threading
**import **time
**import **ssl
ssl._create_default_https_context = ssl._create_unverified_context
**def *getT():
times=str(time.time()).replace(’.’,’’)+‘0’
**return **times+((13-len(times))‘0’)
**class **Fetion:
**def **init(self,username):
self.brow=CookieBrowser()
self.ssid=’‘
self.phone = username
self.info = {}
self.loginStatus=False
self.count=7
self.friend=]
**def **getInfo(self):
postdata=urllib.urlencode({
‘ssid’:self.ssid
})
ret=json.loads(self.brow.open(‘http://webim.feixin.10086.cn/WebIM/GetPersonalInfo.aspx?Version=1’,postdata).read())
**if **ret’rc’] == 200:
self.info=ret’rv’]
**return **True
**return **False
**def **heartbeat(self):
**while **True:
time.sleep(4)
url=‘http://webim.feixin.10086.cn/WebIM/GetConnect.aspx?Version=’+str(self.count)
self.count+=1
# print url
data=json.loads(self.brow.post(url,reported=’’,ssid=self.ssid).read())
**if **data’rc’]==200:
self.friend=data’rv’]
**def **getVerify(self):
postdata = urllib.urlencode({
‘uname’: self.phone
})
result=self.brow.open(‘http://webim.feixin.10086.cn/WebIM/GetSmsPwd.aspx’,postdata).read()
**def **login(self,check):
postdata = urllib.urlencode({
‘AccountType’: ‘1’,
‘Ccp’: ‘’,
‘OnlineStatus’:‘400’,
‘Pwd’:check,
‘UserName’:self.phone
})
result=self.brow.open(‘http://webim.feixin.10086.cn/WebIM/Login.aspx’,postdata).read()
**if **json.loads(result)‘rc’]==200:
**for **x **in **self.brow.getCookies():
x=str(x)
**if **‘webim_sessionid’ **in **x:
self.ssid=x.split(’=’)[1].split(’ for ‘)[0]
self.brow.read(‘http://webim.feixin.10086.cn/SetCounter.aspx?Version=0&coutertype=500300002,500200016,500800002&tag=default&val=1&rand=0.7514041980337672’)
self.loginStatus = self.getInfo()
**if **self.loginStatus:
self.brow.post(‘http://webim.feixin.10086.cn/WebIM/GetCredit.aspx?Version=2’, ssid=self.ssid)
self.brow.read(‘http://webim.feixin.10086.cn/WebIM/GetBackground.aspx?Version=3&uid=’ + str(
self.info’uid’]) + ‘&mn=’ + self.phone + ‘&ssid=’ + self.ssid + ‘&=’ + getT())
self.brow.read(
‘http://webim.feixin.10086.cn/WebIM/GetContactList.aspx?Version=4&ssid=’ + self.ssid + '&=’ + getT())
self.brow.post(‘http://webim.feixin.10086.cn/WebIM/GetGroupList.aspx?Version=5’, ssid=self.ssid)
self.brow.post(‘http://webim.feixin.10086.cn/WebIM/GetALInfo.aspx?Version=6’, ssid=self.ssid)
threading.Thread(target=self.heartbeat).start()
**return **True
**return **False
**def **send2me(self,message):
result=self.brow.post(‘http://webim.feixin.10086.cn/Views/WebIM/SendSMS.aspx?Version=’+str(self.count),Msg=message,ssid=self.ssid,Receivers=str(self.info’uid’]),UserName=str(self.info’uid’])).read()
self.count+=1
**print **result
result=json.loads(result)
**if **result.get(‘rc’,’’) == 200:
**return **True
**return **False
**def **sendbyPhone(self,phone,message):
**for **user **in **self.friend:
**if **user’Data’].get(‘mn’,’’)==str(phone):
result = self.brow.post(‘http://webim.feixin.10086.cn/WebIM/SendMsg.aspx?Version=’ + str(self.count),
IsSendSms=1, Msg=message, ssid=self.ssid,To=user’Data’]‘uid’]).read()
self.count+=1
**if **json.loads(result)‘rc’] == 200:
**return **True
**return **False
**return **False
**def **getTime():
times=time.struct_time(time.localtime())
**return **str(times.tm_year)+‘年’+str(times.tm_mon)+‘月’+str(times.tm_mday)+‘日 ‘+str(times.tm_hour)+’:’+str(times.tm_min)+’:’+str(times.tm_sec)
fetion=Fetion(‘your Phone’)
fetion.getVerify()
vc=raw_input(‘VerifyCode:’)
**print **fetion.login(vc)
**print **‘获取用户信息中’
**while **True:
**if **len(fetion.friend)>0:
**print **‘用户信息获取成功’
**break
****print **fetion.send2me(getTime())
注意!!!,这个飞信只能登陆在一个设备,也就是说会互相挤掉,只能在一个程序里运行,网页版登陆也会挤掉他!!!,一个手机号每天只能发8次验证码,半小时以内可以屏蔽掉fetion.getVerify()这句代码,不获取验证码,用上一次的登陆