diff --git a/lib/oicq.js b/lib/oicq.js index a0cb18c1..8d37b31e 100644 --- a/lib/oicq.js +++ b/lib/oicq.js @@ -204,9 +204,9 @@ Client.prototype._register = async function () { }; Client.prototype._var4 = 0; -Client.prototype._runCircleTask = function () { +Client.prototype._runCircleTask = async function () { if (this._var4++ > 10) { - this._wt.exchangeEmp(); + await this._wt.refreshD2(); if (this.config.platform != 2 && this.config.platform != 3) this.setOnlineStatus(this.online_status); this._var4 = 0; @@ -222,7 +222,7 @@ Client.prototype._startHeartbeat = function () { if (this._heartbeat) return; this._heartbeat = setInterval(async () => { - this._runCircleTask(); + await this._runCircleTask(); if (!await this.pbGetMsg() && this.isOnline()) { this.logger.warn("GetMsg timeout!"); if (!await this.pbGetMsg() && this.isOnline()) diff --git a/lib/wtlogin/login-password.js b/lib/wtlogin/login-password.js index 0585d04e..1c37b470 100644 --- a/lib/wtlogin/login-password.js +++ b/lib/wtlogin/login-password.js @@ -11,9 +11,11 @@ const fs = require("fs"); const path = require("path"); const { randomBytes } = require("crypto"); -const { WtLogin } = require("./wt"); +const { WtLogin, readTlv } = require("./wt"); const Writer = require("./writer"); -const { md5 } = require("../common"); +const { md5, NOOP, timestamp } = require("../common"); +const tea = require("../algo/tea"); +const Readable = require("stream").Readable; WtLogin.prototype.passwordLogin = async function () { this.session_id = randomBytes(4); @@ -166,3 +168,46 @@ WtLogin.prototype.tokenLogin = function (d2) { .read(); this.sendLogin("wtlogin.exchange_emp", body); } + +WtLogin.prototype.refreshD2 = async function () { + if (!this.c.isOnline() || timestamp() - this.sig.emp_time < 14000) + return + this.device.tgtgt = md5(this.sig.d2key); + const t = this.tlvPacker; + const body = new Writer() + .writeU16(11) + .writeU16(16) + .writeBytes(t(0x100)) + .writeBytes(t(0x10a)) + .writeBytes(t(0x116)) + .writeBytes(t(0x144)) + .writeBytes(t(0x143, this.sig.d2)) + .writeBytes(t(0x142)) + .writeBytes(t(0x154)) + .writeBytes(t(0x18)) + .writeBytes(t(0x141)) + .writeBytes(t(0x8)) + .writeBytes(t(0x147)) + .writeBytes(t(0x177)) + .writeBytes(t(0x187)) + .writeBytes(t(0x188)) + .writeBytes(t(0x202)) + .writeBytes(t(0x511)) + .read(); + const pkt = this._buildLoginPacket("wtlogin.exchange_emp", this._buildOICQPacket(body), 2); + try { + let payload = await this.c.send(pkt); + payload = tea.decrypt(payload.slice(16, payload.length - 1), this.ecdh.share_key); + const stream = Readable.from(payload, { objectMode: false }); + stream.read(2); + const type = stream.read(1).readUInt8(); + stream.read(2); + const t = readTlv(stream); + if (type === 0) + this.decodeT119(t[0x119], true); + const success = await this.register(); + if (!success) + return this.c.emit("internal.network", "服务器繁忙(register)"); + await this.exchangeEmp(); + } catch { } +} diff --git a/lib/wtlogin/wt.js b/lib/wtlogin/wt.js index be3af1ab..6f468c5a 100644 --- a/lib/wtlogin/wt.js +++ b/lib/wtlogin/wt.js @@ -90,7 +90,7 @@ class WtLogin { sig_key: t[0x133] ? t[0x133] : this.sig.sig_key, ticket_key: t[0x134] ? t[0x134] : this.sig.ticket_key, device_token: t[0x322] ? t[0x322] : this.sig.device_token, - emp_time: token ? 0 : timestamp(), + emp_time: timestamp(), }; fs.writeFile( path.join(this.dir, "token"), @@ -352,7 +352,7 @@ class WtLogin { } async exchangeEmp() { - if (!this.password_md5 || !this.c.isOnline() || timestamp() - this.sig.emp_time < 14400) + if (!this.password_md5 || !this.c.isOnline()) return; const t = this.tlvPacker; const body = new Writer() @@ -392,13 +392,8 @@ class WtLogin { const stream = Readable.from(payload, { objectMode: false }); stream.read(5); const t = readTlv(stream); - if (t[0x119]) { + if (t[0x119]) this.decodeT119(t[0x119]); - } else { - this.deleteToken() - this.sig.emp_time = 0xffffffff; - this.logger.warn("刷新cookies失败,可能是由于你切换过登录协议或其他原因所导致。如果你需要使用依赖cookies的功能建议立即重新登录。"); - } } catch (e) { this.logger.warn("刷新cookies失败。"); this.logger.warn(e); diff --git a/package.json b/package.json index a0b87a96..8f3a50a0 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "oicq", "app_name": "oicq", - "version": "1.21.1", - "app_version": "1.21.1", - "upday": "2021/10/03", + "version": "1.21.2", + "app_version": "1.21.2", + "upday": "2021/10/10", "protocol_version": "v11", "description": "QQ protocol!", "main": "index.js",