python版飞信

import sys
import httplib
import urllib
import re
import json
import time

class Fetion:

         url = "https://quanapi.sinaapp.com/fetion.php?u="
        def __init__(self,toTel,msg,fromTel='*****',pwd=‘******'):
                self.fromTel=fromTel
                self.pwd=pwd
                self.toTel=toTel
                self.msg=msg
        def format_url(self):
                url_address=self.url+self.fromTel+"&p="+self.pwd+"&to="+self.toTel+"&m="+self.msg
                return url_address
        def SendMsg(self):
                return urllib.urlopen(self.format_url())

def main():
        toTel=raw_input("Input the target telephone number:")
        if toTel=="":
                toTel='*******'
        msg=raw_input("Message:")
        if msg=="":
                sys.exit(0)
        else:
                ff=Fetion(toTel,msg)
                answer=ff.SendMsg()
                data=answer.read()
                print data
                jdata=json.loads(data)
                print jdata
        if jdata['result']==0:
                print "ok"
        else:
                error
if __name__=='__main__':
        main()

你可能感兴趣的:(python版飞信)