-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.rb
More file actions
95 lines (74 loc) · 2.9 KB
/
app.rb
File metadata and controls
95 lines (74 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require 'thrift'
$:.push('gen-rb')
require 'line_main_constants'
require 'line_constants'
require 'talk_service'
require 'json'
require 'open-uri'
require 'openssl'
require './helper'
require 'net/http'
email = ''
password = ''
# ====================================================
LINE_DOMAIN = "http://gd2.line.naver.jp"
LINE_HTTP_URL = LINE_DOMAIN + "/api/v4/TalkService.do"
LINE_HTTP_IN_URL = LINE_DOMAIN + "/P4"
LINE_CERTIFICATE_URL = LINE_DOMAIN + "/Q"
LINE_SESSION_LINE_URL = LINE_DOMAIN + "/authct/v1/keys/line" # email
LINE_SESSION_NAVER_URL = LINE_DOMAIN + "/authct/v1/keys/naver" # id
ip = "127.0.0.1"
version = "3.7.0"
com_name = "eddie"
revision = 0
json = JSON.parse(open(LINE_SESSION_LINE_URL).read)
session_key = json['session_key']
message = "#{encode_message(session_key)}#{encode_message(email)}#{encode_message(password)}"
keyname, n, e = json['rsa_key'].split(",")
# puts session_key
# puts "\n"
# puts keyname
# puts "\n"
# puts "message: #{message.inspect}, n: #{n.to_i(16)} e: #{e.to_i(16)}"
pub_key = OpenSSL::PKey::RSA.new
pub_key.n, pub_key.e = n.to_i(16), e.to_i(16)
crypto = Digest.hexencode(pub_key.public_encrypt(message))
# ==================
os_version = "10.9.4-MAVERICKS-x64"
user_agent = "DESKTOP:MAC:#{os_version}(#{version})"
app_code = "DESKTOPMAC\t#{version}\tMAC\t#{os_version}"
headers = { "User-Agent" => user_agent, "X-Line-Application" => app_code }
# ==================
transport = Thrift::HTTPClientTransport.new(LINE_HTTP_URL)
transport.add_headers(headers)
# transport = Thrift::BufferedTransport.new()
protocol = Thrift::CompactProtocol.new(transport)
client = Line::TalkService::Client.new(protocol)
begin
# 1. 第一次登入
msg = client.loginWithIdentityCredentialForCertificate(Line::IdentityProvider::LINE, email, password, true, ip, com_name, "")
puts "please input pin code in your devise: #{msg.pinCode}"
# 2. blocking request 等待輸入 pin code
uri = URI(LINE_CERTIFICATE_URL)
req = Net::HTTP::Get.new(uri)
req['X-Line-Access'] = msg.verifier
Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }
# 3. 取得 cert & authToken
auth_info = client.loginWithVerifierForCertificate(msg.verifier)
transport.add_headers("X-Line-Access" => auth_info.authToken)
# 4. 使用 auth token 重新登入 (back to step 1.)
client.loginWithIdentityCredentialForCertificate(Line::IdentityProvider::LINE, email, password, true, ip, com_name, "")
# === 已取得權限
# a. 得到 revision
revision = client.getLastOpRevision()
puts "revision: #{revision}"
# b. 得到 profile information
profile = client.getProfile()
puts "LineID: #{profile.userid}, phone: #{profile.phone}, displayName: #{profile.displayName}, regionCode: #{profile.regionCode}"
# c. 得到 contact ids
contact_ids = client.getAllContactIds()
puts contact_ids.inspect
rescue Exception => e
puts e.inspect
end
# transport.open