Commit 8da3a65f4259d8100c1067d07d95a8774aaa3681

Authored by Nadya Sutjiadi
Committed by GitHub
1 parent 4f240989

Delete Talk.py

Showing 1 changed file with 0 additions and 120 deletions
LINETCR/Api/Talk.py deleted
1   -# -*- coding: utf-8 -*-
2   -import os, sys
3   -path = os.path.join(os.path.dirname(__file__), '../lib/')
4   -sys.path.insert(0, path)
5   -
6   -import requests, rsa
7   -
8   -from thrift.transport import THttpClient
9   -from thrift.protocol import TCompactProtocol
10   -
11   -from curve import LineService
12   -from curve.ttypes import *
13   -
14   -class Talk:
15   - client = None
16   -
17   - auth_query_path = "/api/v4/TalkService.do";
18   - http_query_path = "/S4";
19   - wait_for_mobile_path = "/Q";
20   - host = "gd2.line.naver.jp";
21   - port = 443;
22   -
23   - UA = "Line/1.4.17"
24   - LA = "IOSIPAD\x097.14.0\x09iPhone_OS\x0910.12.0"
25   -
26   - authToken = None
27   - cert = None
28   -
29   - def __init__(self):
30   - self.transport = THttpClient.THttpClient('https://gd2.line.naver.jp:443'+self.auth_query_path)
31   - self.transport.setCustomHeaders({
32   - "User-Agent" : self.UA,
33   - "X-Line-Application" : self.LA,
34   - })
35   - self.transport.open()
36   - self.protocol = TCompactProtocol.TCompactProtocol(self.transport);
37   - self.client = LineService.Client(self.protocol)
38   -
39   - def login(self, mail, passwd, cert=None, callback=None):
40   - self.transport.path = self.auth_query_path
41   - rsakey = self.client.getRSAKeyInfo(IdentityProvider.LINE)
42   - crypt = self.__crypt(mail, passwd, rsakey)
43   -
44   - result = self.client.loginWithIdentityCredentialForCertificate(
45   - IdentityProvider.LINE,
46   - rsakey.keynm,
47   - crypt,
48   - True,
49   - '127.0.0.1',
50   - 'http://dg.b9dm.com/KoenoKatachi.mp4',
51   - cert
52   - )
53   -
54   - if result.type == 3:
55   - callback(result.pinCode)
56   - header = {"X-Line-Access": result.verifier}
57   - r = requests.get(url="https://" + self.host + self.wait_for_mobile_path, headers=header)
58   -
59   - result = self.client.loginWithVerifierForCerificate(r.json()["result"]["verifier"])
60   - self.transport.setCustomHeaders({
61   - "X-Line-Application" : self.LA,
62   - "User-Agent" : self.UA,
63   - "X-Line-Access" : result.authToken
64   - })
65   -
66   - self.authToken = result.authToken
67   - self.cert = result.certificate
68   - self.transport.path = self.http_query_path
69   -
70   - elif result.type == 1:
71   - self.authToken = result.authToken
72   - self.cert = result.certificate
73   - self.transport.setCustomHeaders({
74   - "X-Line-Application" : self.LA,
75   - "User-Agent" : self.UA,
76   - "X-Line-Access" : result.authToken
77   - })
78   - self.transport.path = self.http_query_path
79   -
80   - def TokenLogin(self, authToken):
81   - self.transport.setCustomHeaders({
82   - "X-Line-Application" : self.LA,
83   - "User-Agent" : self.UA,
84   - "X-Line-Access" : authToken,
85   - })
86   - self.authToken = authToken
87   - self.transport.path = self.http_query_path
88   -
89   - def qrLogin(self, callback):
90   - self.transport.path = self.auth_query_path
91   -
92   - qr = self.client.getAuthQrcode(True, "Bot")
93   - callback("Copy to Line and Click\nYour LINK QR is: line://au/q/" + qr.verifier)
94   -
95   - r = requests.get("https://" + self.host + self.wait_for_mobile_path, headers={
96   - "X-Line-Application": self.LA,
97   - "X-Line-Access": qr.verifier,
98   - })
99   -
100   - vr = r.json()["result"]["verifier"]
101   - lr = self.client.loginWithVerifierForCerificate(vr)
102   - self.transport.setCustomHeaders({
103   - "X-Line-Application" : self.LA,
104   - "User-Agent" : self.UA,
105   - "X-Line-Access": lr.authToken
106   - })
107   - self.authToken = lr.authToken
108   - self.cert = lr.certificate
109   - self.transport.path = self.http_query_path
110   -
111   -
112   - def __crypt(self, mail, passwd, RSA):
113   - message = (chr(len(RSA.sessionKey)) + RSA.sessionKey +
114   - chr(len(mail)) + mail +
115   - chr(len(passwd)) + passwd).encode('utf-8')
116   -
117   - pub_key = rsa.PublicKey(int(RSA.nvalue, 16), int(RSA.evalue, 16))
118   - crypto = rsa.encrypt(message, pub_key).encode('hex')
119   -
120   - return crypto