Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
fix big pic
Browse files Browse the repository at this point in the history
  • Loading branch information
takayama-lily committed Feb 20, 2021
1 parent 38cdd49 commit fba483f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 57 deletions.
11 changes: 6 additions & 5 deletions client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,12 @@ export class Client extends events.EventEmitter {
setPortrait(file: Buffer | string): Promise<RetCommon>; //图片CQ码中file相同格式
setGroupPortrait(group_id: number, file: Buffer | string): Promise<RetCommon>;

getFile(fileid: string, busid?: string): Promise<RetCommon<FileElem["data"]>>; //用于下载链接失效后重新获取
getHistoryMsgs(message_id: string, num?: number): Promise<RetCommon<PrivateMessageEventData[] | GroupMessageEventData[]>>; //获取msgid往前的num条消息
uploadC2CImages(user_id: number, images: ImgPttElem["data"][]): Promise<RetCommon<ImgPttElem["data"][]>>; //上传好友图以备发送
uploadGroupImages(group_id: number, images: ImgPttElem["data"][]): Promise<RetCommon<ImgPttElem["data"][]>>; //上传群图以备发送
getSummaryCard(user_id): Promise<RetCommon<unknown>>; //查看用户资料
// getFile(fileid: string, busid?: string): Promise<RetCommon<FileElem["data"]>>; //用于下载链接失效后重新获取
// getHistoryMsgs(message_id: string, num?: number): Promise<RetCommon<PrivateMessageEventData[] | GroupMessageEventData[]>>; //获取msgid往前的num条消息
// uploadC2CImages(user_id: number, images: ImgPttElem["data"][]): Promise<RetCommon<ImgPttElem["data"][]>>; //上传好友图以备发送
// uploadGroupImages(group_id: number, images: ImgPttElem["data"][]): Promise<RetCommon<ImgPttElem["data"][]>>; //上传群图以备发送
// getSummaryCard(user_id: number): Promise<RetCommon<unknown>>; //查看用户资料
// getForwardMsg(resid: string): Promise<RetCommon<unknown>>;

getCookies(domain?: string): Promise<RetCommon<{ cookies: string }>>;
getCsrfToken(): Promise<RetCommon<{ token: number }>>;
Expand Down
16 changes: 16 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const os = require("os");
const { exec } = require("child_process");
const { randomBytes } = require("crypto");
const log4js = require("log4js");
const pb = require("./lib/pb");
const { getApkInfo, getDeviceInfo } = require("./device");
const { checkUin, timestamp, md5 } = require("./lib/common");
const core = require("./lib/core");
Expand Down Expand Up @@ -413,6 +414,21 @@ class AndroidClient extends Client {
}
return cnt;
}
buildSyncCookie() {
const time = timestamp();
return pb.encode({
1: time,
2: time,
3: this.const1,
4: this.const2,
5: randomBytes(4).readUInt32BE(),
9: randomBytes(4).readUInt32BE(),
11: randomBytes(4).readUInt32BE(),
12: this.const3,
13: time,
14: 0,
});
}

// 以下是public方法 ----------------------------------------------------------------------------------------------------

Expand Down
3 changes: 1 addition & 2 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Readable = require("stream").Readable;
const common = require("./common");
const pb = require("./pb");
const jce = require("./jce");
const { buildSyncCookie } = require("./message/chat");
const { parsePrivateMsg } = require("./message/recv");
const push = require("./online-push");
const sysmsg = require("./sysmsg");
Expand Down Expand Up @@ -70,7 +69,7 @@ function onPushNotify(blob) {
*/
async function getMsg(sync_flag = 0) {
if (!this.sync_cookie)
this.sync_cookie = buildSyncCookie.call(this);
this.sync_cookie = this.buildSyncCookie();
let body = pb.encode({
1: sync_flag,
2: this.sync_cookie,
Expand Down
20 changes: 2 additions & 18 deletions lib/message/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,6 @@ async function sendMsg(target, message, escape, type) {
return rsp;
}

function buildSyncCookie() {
const time = common.timestamp();
return pb.encode({
1: time,
2: time,
3: this.const1,
4: this.const2,
5: crypto.randomBytes(4).readUInt32BE(),
9: crypto.randomBytes(4).readUInt32BE(),
11: crypto.randomBytes(4).readUInt32BE(),
12: this.const3,
13: time,
14: 0,
});
}

/**
* @this {import("../ref").Client}
* @returns {import("../ref").ProtocolResponse}
Expand Down Expand Up @@ -141,7 +125,7 @@ async function sendPrivateMsg(user_id, rich) {
3: { 1: rich },
4: seq,
5: random,
6: buildSyncCookie.call(this),
6: this.buildSyncCookie(),
8: 1,
});
const blob = await this.sendUNI("MessageSvc.PbSendMsg", body);
Expand Down Expand Up @@ -486,5 +470,5 @@ async function getHistoryMsg(message_id) {
}

module.exports = {
sendMsg, recallMsg, buildSyncCookie, getHistoryMsg
sendMsg, recallMsg, getHistoryMsg
};
2 changes: 1 addition & 1 deletion lib/online-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ const FRAG = new Map;
* Fuck Tencent
* 1.是最后一个分片,返回组装好的消息
* 2.不是最后一个分片,返回空
* @param {import("../ref").Msg} msg
* @param {import("./ref").Msg} msg
*/
async function rebuildFragments(msg) {
const head = msg[1], content = msg[2], body = msg[3];
Expand Down
1 change: 1 addition & 0 deletions lib/ref.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@ export class Client extends oicq.Client {
useProtocol(fn: Function, params: any[]): oicq.RetCommon;
em(name: string, data: object): void;
msgExists(from: number, type: number, seq: number, time: number): boolean;
buildSyncCookie(): Buffer;
}
80 changes: 49 additions & 31 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { randomBytes } = require("crypto");
const fs = require("fs");
const pb = require("./pb");
const jce = require("./jce");
const common = require("./common");
const MAX_UPLOAD_SIZE = 31457280;

function int32ip2str(ip) {
Expand All @@ -26,35 +27,43 @@ function int32ip2str(ip) {
* @this {import("./ref").Client}
* @param {import("./ref").HighwayUploadObject} o
* @param {Number} cmd
* @returns {Buffer}
* @returns {Buffer[]}
*/
function buildHighwayUploadRequestPacket(o, cmd) {
const head = pb.encode({
1: {
1: 1,
2: String(this.uin),
3: "PicUp.DataUp",
4: randomBytes(2).readUInt16BE(),
6: this.apk.subid,
7: 4096,
8: cmd,
10: 2052,
},
2: {
2: o.buf.length,
3: 0,
4: o.buf.length,
6: o.key,
8: o.md5,
9: o.md5,
}
});
const _ = Buffer.allocUnsafe(9);
_.writeUInt8(40);
_.writeUInt32BE(head.length, 1);
_.writeUInt32BE(o.buf.length, 5);
const __ = Buffer.from([41]);
return Buffer.concat([_, head, o.buf, __]);
function buildHighwayUploadRequestPackets(o, cmd, seq = randomBytes(2).readUInt16BE()) {
const packets = [], limit = 3000000, size = o.buf.length;
let chunk, offset = 0;
while (1) {
chunk = o.buf.slice(offset, offset + limit);
if (!chunk.length) break;
const head = pb.encode({
1: {
1: 1,
2: String(this.uin),
3: "PicUp.DataUp",
4: seq++,
6: this.apk.subid,
7: 4096,
8: cmd,
10: 2052,
},
2: {
2: size,
3: offset,
4: chunk.length,
6: o.key,
8: common.md5(chunk),
9: o.md5,
}
});
offset += limit;
const _ = Buffer.allocUnsafe(9);
_.writeUInt8(40);
_.writeUInt32BE(head.length, 1);
_.writeUInt32BE(chunk.length, 5);
const __ = Buffer.from([41]);
packets.push(Buffer.concat([_, head, chunk, __]));
}
return packets;
}

/**
Expand All @@ -70,12 +79,21 @@ async function highwayUpload(ip, port, o, cmd) {
this.logger.trace(`highway ip:${ip} port:${port}`);
return new Promise((resolve) => {
const client = net.connect(port, ip, () => {
client.write(packet, client.end.bind(client));
const pkt = packets.shift();
client.write(pkt);
});
client.on("data", () => {
if (!packets.length) {
resolve();
client.destroy();
} else {
const pkt = packets.shift();
client.write(pkt);
}
});
client.on("end", resolve);
client.on("close", resolve);
client.on("error", resolve);
var packet = buildHighwayUploadRequestPacket.call(this, o, cmd);
var packets = buildHighwayUploadRequestPackets.call(this, o, cmd);
});
}

Expand Down

0 comments on commit fba483f

Please sign in to comment.