This repository has been archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLineCross.php
294 lines (292 loc) · 12.8 KB
/
LineCross.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?php
namespace x9119x;
require_once __DIR__ . '/Thrift/ClassLoader/ThriftClassLoader.php';
require_once __DIR__ . '/Thrift/Exception/TException.php';
require_once __DIR__ . '/Thrift/x9119x/Types.php';
require __DIR__ . '/Thrift/x9119x/LineTalkService.php';
require __DIR__ . '/Thrift/x9119x/LinePollService.php';
require __DIR__ . '/Thrift/x9119x/LineService.php';
require __DIR__ . '/Thrift/x9119x/LineShopService.php';
@require __DIR__ . '/Thrift/Math/BigInteger.php';
@require __DIR__ . '/Thrift/Crypt/RSA.php';
use Thrift\ClassLoader\ThriftClassLoader;
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__);
$loader->register();
use Thrift\Protocol\TCompactProtocol;
use Thrift\Transport\TBufferedTransport;
use Thrift\Transport\TSocket;
use Thrift\Transport\THttpClient;
use Thrift\Transport\TTransport;
use Thrift\Exception\TException;
Class AuthInfo {
public $Mail;
public $Pass;
public $Cert;
public $Token;
public $Name;
public $Rev;
public function __construct($Token = NULL,$Mail = NULL, $Pass = NULL, $Cert = NULL, $Name = "GOD", $Rev = NULL) {
$this->Mail = $Mail;
$this->Pass = $Pass;
$this->Cert = $Cert;
$this->Token = $Token;
$this->Name = $Name;
$this->Rev = $Rev;
}
}
class Connection {
public $transport;
public $protocol;
public $client;
}
class Connections {
public $LineService;
public $LinePollService;
public $LineTalkService;
public function __construct() {
$this->LineService = new Connection();
$this->LinePollService = new Connection();
$this->LineTalkService = new Connection();
}
}
class EndPoint {
public $TalkService = '/api/v4/TalkService.do';
public $Wait = '/Q';
public $LineService = '/S4';
public $PollService = '/P4';
}
class Host {
public $Windows_1 = 'gd2.line.naver.jp';
public $Android_1 = 'gf.line.naver.jp';
public $ProfileURL = 'http://dl.profile.line-cdn.net/';
public $Host;
public function __construct() {
$this->Host = $this->Windows_1;
}
}
class AppType {
public $Mac_UA = 'DESKTOP:MAC:10.10.2-YOSEMITE-x64(4.5.0)';
public $Mac_APP = 'DESKTOPMAC 10.10.2-YOSEMITE-x64 MAC 4.5.0';
public $UA;
public $APP;
public function __construct() {
$this->UA = $this->Mac_UA;
$this->APP = $this->Mac_APP;
}
}
class ServiceInfo {
public $Host;
public $AppType;
public $EndPoint;
public function __construct() {
$this->Host = new Host();
$this->AppType = new AppType();
$this->EndPoint = new EndPoint();
}
}
class LineCross {
public $Connections;
public $AuthInfo;
public $LineService;
public $PollService;
public $ServiceInfo;
public function __construct($AuthInfo = NULL) {
$this->Connections = new Connections();
$this->ServiceInfo = new ServiceInfo();
$this->AuthInfo = $AuthInfo;
if (empty($AuthInfo)) {
$this->AuthInfo = new AuthInfo();
$this->LoginWithQR();
} elseif (!empty($AuthInfo->Mail) && !empty($AuthInfo->Pass) ) {
$this->LoginWhithMailPass();
}
$this->LineService = new Service($this->ServiceInfo, $this->AuthInfo, $this->Connections->LineService);
$this->PollService = new Poll($this->ServiceInfo, $this->AuthInfo, $this->Connections->LinePollService);
}
public function LoginWithQR() {
$this->Connections->LineTalkService->transport = new THttpClient($this->ServiceInfo->Host->Host, 443, $this->ServiceInfo->EndPoint->TalkService, 'https');
$this->Connections->LineTalkService->transport->addHeaders(["User-Agent" => $this->ServiceInfo->AppType->UA, "X-Line-Application" => $this->ServiceInfo->AppType->APP, ]);
$this->Connections->LineTalkService->protocol = new TCompactProtocol($this->Connections->LineTalkService->transport);
$this->Connections->LineTalkService->client = new LineTalkServiceClient($this->Connections->LineTalkService->protocol);
$msg = $this->Connections->LineTalkService->client->getAuthQrcode(true, $this->AuthInfo->Name);
$qrcode = $msg->qrcode;
$verifier = $msg->verifier;
echo ("line://au/q/" . $verifier . PHP_EOL);
$headers = ["User-Agent: {$this->ServiceInfo->AppType->UA}", "X-Line-Application: {$this->ServiceInfo->AppType->APP}", "X-Line-Access: " . $verifier];
$ch = curl_init();
$options = [CURLOPT_URL => 'https://' . $this->ServiceInfo->Host->Host . $this->ServiceInfo->EndPoint->Wait, CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_CUSTOMREQUEST => 'GET', ];
curl_setopt_array($ch, $options);
$res = json_decode(curl_exec($ch), true);
curl_close($ch);
$verifier = $res['result']['verifier'];
try {
$msg = $this->Connections->LineTalkService->client->loginWithVerifierForCertificate($verifier);
}
catch(TalkException $e) {
echo $e->reason . PHP_EOL;
exit;
}
$this->AuthInfo->Token = $msg->authToken;
echo 'authToken = ' . $this->AuthInfo->Token . PHP_EOL;
file_put_contents(__DIR__ . '/auth.txt', $this->AuthInfo->Token);
}
/* public function LoginWhithMailPass() {
$this->Connections->LineTalkService->transport = new THttpClient($this->ServiceInfo->Host->Host, 443, $this->ServiceInfo->EndPoint->TalkService, 'https');
$this->Connections->LineTalkService->transport->addHeaders(["User-Agent" => $this->ServiceInfo->AppType->UA, "X-Line-Application" => $this->ServiceInfo->AppType->APP, ]);
$this->Connections->LineTalkService->protocol = new TCompactProtocol($this->Connections->LineTalkService->transport);
$this->Connections->LineTalkService->client = new LineTalkServiceClient($this->Connections->LineTalkService->protocol);
$rsakey = $this->Connections->LineTalkService->client->getRSAKeyInfo(1);
$msg = utf8_encode(chr(mb_strlen($rsakey->sessionKey)) . $rsakey->sessionKey . chr(mb_strlen($this->AuthInfo->Mail)) . $this->AuthInfo->Mail . chr(mb_strlen($this->AuthInfo->Pass)) . $this->AuthInfo->Pass);
$crypted = $this->export_rsa($msg, $rsakey->nvalue, $rsakey->evalue);
$result = $this->Connections->LineTalkService->client->loginWithIdentityCredentialForCertificate(1, $rsakey->keynm, $crypted, true, '127.0.0.1', $this->AuthInfo->Name, $this->AuthInfo->Cert);
switch ($result->type) {
case 3: //pin required
echo 'type to your divice [' . $result->pinCode . ']' . PHP_EOL;
$headers = array("X-Line-Access: {$result->verifier}");
$ch = curl_init();
$options = [CURLOPT_URL => 'https://' . $this->ServiceInfo->Host->Host . $this->ServiceInfo->EndPoint->Wait, CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_CUSTOMREQUEST => 'GET', ];
curl_setopt_array($ch, $options);
$res = curl_exec($ch);
curl_close($ch);
$json_data = json_decode($res, true);
$vr = $json_data["result"]["verifier"];
$log_in = $this->Connections->LineTalkService->client->loginWithVerifierForCerificate($login->vr);
echo ('authToken = ' . $log_in->authToken . PHP_EOL);
file_put_contents(__DIR__ . '/auth.txt', $log_in->authToken);
$this->AuthInfo->Token = $log_in->authToken;
}
}
*/
private function export_rsa($message, $n, $e) {
$RSA = new \Crypt_RSA();
$A = new \Math_BigInteger($n, 16);
$B = new \Math_BigInteger($e, 16);
$public_key = $RSA->_convertPublicKey($A, $B);
$RSA->setPublicKey($public_key);
$pubkey = openssl_get_publickey($public_key);
$msg = openssl_public_encrypt($message, $crypted, $pubkey);
$crypted = bin2hex($crypted);
return $crypted;
}
}
class Service {
public $client;
public function __construct($ServiceInfo, $AuthInfo, $Connection) {
$Connection->transport = new THttpClient($ServiceInfo->Host->Host, 443, $ServiceInfo->EndPoint->LineService, 'https');
$Connection->transport->addHeaders(["User-Agent" => $ServiceInfo->AppType->UA,
"X-Line-Application" => $ServiceInfo->AppType->APP,
'X-Line-Access' => $AuthInfo->Token, ]);
$Connection->protocol = new TCompactProtocol($Connection->transport);
$Connection->client = new LineServiceClient($Connection->protocol);
$this->client = $Connection->client;
if(empty($AuthInfo->Rev)){
$AuthInfo->Rev = $Connection->client->getLastOpRevision();
}
}
public function getGroupIdsInvited() {
return $this->client->getGroupIdsInvited();
}
public function getUserTicket() {
return $this->client->getUserTicket();
}
public function findAndAddContactsByMid($mid) {
return $this->client->findAndAddContactsByMid(0, $mid);
}
public function getProfile() {
return $this->client->getProfile();
}
public function getCompactGroup($groupId) {
return $this->client->getCompactGroup($groupId);
}
public function getAuthQrcode($keepLoggedIn, $systemName) {
return $this->client->getAuthQrcode($keepLoggedIn, $systemName);
}
public function getContact($id){
return $this->client->getContact($id);
}
public function getContacts($Mids) {
return $this->client->getContacts($Mids);
}
public function acceptGroupInvitation($groupId) {
return $this->client->acceptGroupInvitation(0, $groupId);
}
public function leaveGroup($groupId) {
return $this->client->leaveGroup(0, $groupId);
}
public function kickoutFromGroup($groupId, $contactIds) {
return $this->client->kickoutFromGroup(0, $groupId, $contactIds);
}
public function getGroup($groupId) {
return $this->client->getGroup($groupId);
}
public function cancelGroupInvitation($groupId, $contactIds) {
return $this->client->cancelGroupInvitation(0, $groupId, $contactIds);
}
public function sendMessage($text, $id) {
$message = new Message();
$message->text = $text;
$message->to = $id;
return $this->client->sendMessage(0, $message);
}
public function updateGroup($group) {
return $this->client->updateGroup(0, $group);
}
public function getFavoriteMids() {
return $this->client->getFavoriteMids();
}
public function inviteIntoGroup($groupId, $contactIds) {
return $this->client->inviteIntoGroup(0, $groupId, $contactIds);
}
public function createGroup($name, $contactIds) {
return $this->client->createGroup(0, $name, $contactIds);
}
public function leaveRoom($roomId) {
return $this->client->leaveRoom(0, $roomId);
}
public function updateProfile($profile) {
return $this->client->updateProfile(0, $profile);
}
public function updateRegion($region) {
return $this->client->updateRegion($region);
}
public function getLastReadMessageIds($chatId) {
return $this->client->getLastReadMessageIds($chatId);
}
public function getMessageBoxWrapUp($mid) {
return $this->client->getMessageBoxWrapUp($mid);
}
public function getMessageBoxCompactWrapUpList($start, $messageBoxCount) {
return $this->client->getMessageBoxCompactWrapUpList($start, $messageBoxCount);
}
public function getSettings() {
return $this->client->getSettings();
}
public function getServerTime() {
return $this->client->getServerTime();
}
public function reissueGroupTicket($groupId) {
return $this->client->reissueGroupTicket($groupId);
}
public function findGroupByTicket($ticketId) {
return $this->client->findGroupByTicket($ticketId);
}
public function acceptGroupInvitationByTicket($groupId, $ticketId) {
return $this->client->acceptGroupInvitationByTicket(0, $groupId, $ticketId);
}
}
class Poll {
public $client;
public $AuthInfo;
public function __construct($ServiceInfo, $AuthInfo, $Connection) {
$this->AuthInfo = $AuthInfo;
$Connection->transport = new THttpClient($ServiceInfo->Host->Host, 443, $ServiceInfo->EndPoint->PollService, 'https');
$Connection->transport->addHeaders(array("User-Agent" => $ServiceInfo->AppType->UA, "X-Line-Application" => $ServiceInfo->AppType->APP, 'X-Line-Access' => $AuthInfo->Token,));
$Connection->protocol = new TCompactProtocol($Connection->transport);
$Connection->client = new LinePollServiceClient($Connection->protocol);
$this->client = $Connection->client;
}
public function start($count = 1) {
return $this->client->fetchOperations($this->AuthInfo->Rev, $count);
}
}