Пример #1
0
 def get(self):
     args = parser.parse_args()
     token = args['token']
     client = LineClient(authToken=token)
     lineTokenChecker = LineTokenChecker()
     if (lineTokenChecker.check(client)) :
         profile = str(client.getProfile())
         return json.loads(profile), 200, {'Access-Control-Allow-Origin': '*'}
     else :
         return json.loads(lineTokenChecker.msg),505,{'Access-Control-Allow-Origin': '*'}
Пример #2
0
def send_to_line(message, image):
    """Send message and image to Line Messanger."""
    try:
        client = LineClient(conf.LINE_USERNAME, conf.LINE_PASSWORD)
        myline = client.getProfile()
        myline.sendMessage(message)
        myline.sendImage(image)
        return True
    except:
        pass
    return False
Пример #3
0
while True:
    op_list = []

    for op in client.longPoll():
        op_list.append(op)

    for op in op_list:
        sender = op[0]
        receiver = op[1]
        message = op[2]
        msg = message
        text = msg.text
        to = msg.to
        dari = msg._from

        if msg.toType == 0 or msg.toType == 1 or msg.toType == 2:
            if msg.toType == 0:
                if sender != client.getProfile().id:
                    to = dari
                else:
                    to = to
            elif msg.toType == 1:
                to = to
            elif msg.toType == 2:
                to = to
            if text is not None:
                print("[ %s ] %s : \'%s\'" % (receiver, sender.name, msg))
                if text.lower() == "hi":
                    client.sendText(to, "Hi too")
    def lineLogin(data):
        
        self = lineDemo(data)

        """Login to LINE server."""
        

        j = self.get_json(self.LINE_SESSION_LINE_URL)
        

        session_key = j['session_key']
        message     = (chr(len(session_key)) + session_key +
                       chr(len(self.id)) + self.id +
                       chr(len(self.password)) + self.password).encode('utf-8')

        keyname, n, e = j['rsa_key'].split(",")
        pub_key       = rsa.PublicKey(int(n,16), int(e,16))
        crypto        = rsa.encrypt(message, pub_key).encode('hex')

        self.transport = THttpClient.THttpClient(self.LINE_HTTP_URL)
        self.transport.setCustomHeaders(self._headers)

        self.protocol = TCompactProtocol.TCompactProtocol(self.transport)
        self._client   = CurveThrift.Client(self.protocol)
      
        msg = self._client.loginWithIdentityCredentialForCertificate(
                self.id, self.password, keyname, crypto, False, self.ip,
                self.com_name, self.provider, "")
        
        self._headers['X-Line-Access'] = msg.verifier
        self._pinCode = msg.pinCode
        message = "Enter PinCode '%s' to your mobile phone in 2 minutes"\
                % self._pinCode
        yield message
        print message
        

        j = self.get_json(self.LINE_CERTIFICATE_URL)

        self.verifier = j['result']['verifier']

        msg = self._client.loginWithVerifierForCertificate(self.verifier)

        if msg.type == 1:
            self.certificate = msg.certificate
            self.authToken = self._headers['X-Line-Access'] = msg.authToken
            client = LineClient(authToken= self.authToken)  
            authToken = msg.authToken
            id = str(client.getProfile().id)
            email = str(self.id)
            yield '<BR>ID :'+ id 
            conn = sqlite3.connect('line_api.db')
            c = conn.cursor()
            c.execute("SELECT count(line_id) FROM line_authtoken WHERE line_id = '"+id+"'")
            count = c.fetchone()
            if (count[0] == 0 ) :
                c.execute("INSERT INTO line_authtoken (line_id, email, line_authtoken ) VALUES ('"+id+"','"+email+"','"+authToken+"')")
            else:
                c.execute("UPDATE line_authtoken SET  line_authtoken = '"+msg.authToken+"' ")
            conn.commit()
            yield '<br> Your Token is <br> <textarea readonly="readonly" cols="20" rows="5">'+ authToken+'</textarea>'
            return 
        elif msg.type == 2:
            msg = "require QR code"
            self.raise_error(msg)
        else:
            msg = "require device confirm"
            self.raise_error(msg)
        return 
Пример #5
0
while True:
    op_list = []

    for op in client.longPoll():
        op_list.append(op)

    for op in op_list:
        sender      = op[0]
        receiver    = op[1]
        message     = op[2]
        msg         = message
        text        = msg.text
        to          = msg.to
        dari        = msg._from

        if msg.toType == 0 or msg.toType == 1 or msg.toType == 2:
            if msg.toType == 0:
                if dari != client.getProfile().id:
                    to = dari
                else:
                    to = to
            elif msg.toType == 1:
                to = to
            elif msg.toType == 2:
                to = to
            if text is not None:
                print("[ %s ] %s : \'%s\'" % (receiver, sender.name, msg))
                if text.lower() == "hi":
                    client.sendText(to, "Hi too")