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

Commit

Permalink
fix 手机协议不能正确解析长消息
Browse files Browse the repository at this point in the history
  • Loading branch information
takayama-lily committed Oct 11, 2020
1 parent 5cc2b84 commit d4ee4a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async function getMsg(sync_flag = 0) {
async function getNewFriend() {
this.nextSeq();
const body = pb.encode("ReqSystemMsgNew", {
msgNum: 1,
msgNum: 20,
version: 1000,
checktype: 2,
flag: {
Expand Down Expand Up @@ -205,8 +205,8 @@ async function getNewFriend() {
async function getNewGroup() {
this.nextSeq();
const body = pb.encode("ReqSystemMsgNew", {
msgNum: 1,
version: 100,
msgNum: 20,
version: 1000,
checktype: 3,
flag: {
grpMsgKickAdmin: 1,
Expand Down
40 changes: 20 additions & 20 deletions lib/message/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const zlib = require("zlib");
const net = require("net");
const http = require("http");
const https = require("https");
const crypto = require("crypto");
const querystring = require("querystring");
const tea = require("crypto-tea");
const pb = require("../pb");
Expand All @@ -20,16 +21,14 @@ function int32ip2str(ip) {
}

/**
* @param {Number} uin
* @param {Object} o
* @field {Buffer} buf
* @field {Buffer} md5
* @field {Buffer} key
* @param {Number} cmd
* @returns {Buffer[]}
*/
function buildHighwayUploadRequestPackets(uin, o, cmd, seq = common.rand()) {
uin = uin.toString();
function buildHighwayUploadRequestPackets(o, cmd, seq = crypto.randomBytes(2).readUInt16BE()) {
const packets = [], limit = MAX_UPLOAD_SIZE, size = o.buf.length;
let chunk, offset = 0;
while (1) {
Expand All @@ -38,10 +37,10 @@ function buildHighwayUploadRequestPackets(uin, o, cmd, seq = common.rand()) {
const head = pb.encode("ReqDataHighwayHead", {
msgBasehead: {
version: 1,
uin: uin,
uin: String(this.uin),
command: "PicUp.DataUp",
seq: seq++,
appid: 537064989,
appid: this.sub_appid,
dataflag: 4096,
commandId: cmd,
localeId: 2052,
Expand All @@ -67,8 +66,6 @@ function buildHighwayUploadRequestPackets(uin, o, cmd, seq = common.rand()) {
}

/**
* @async
* @param {Number} uin
* @param {Number} ip Int32ip
* @param {Number} port
* @param {Object} o
Expand All @@ -78,7 +75,7 @@ function buildHighwayUploadRequestPackets(uin, o, cmd, seq = common.rand()) {
* @param {Number} cmd
* @returns {Promise}
*/
async function highwayUpload(uin, ip, port, o, cmd) {
async function highwayUpload(ip, port, o, cmd) {
ip = int32ip2str(ip);
return new Promise((resolve)=>{
const client = net.connect(port, ip, ()=>{
Expand All @@ -95,7 +92,7 @@ async function highwayUpload(uin, ip, port, o, cmd) {
});
client.on("close", resolve);
client.on("error", resolve);
var packets = buildHighwayUploadRequestPackets(uin, o, cmd);
var packets = buildHighwayUploadRequestPackets.call(this, o, cmd);
})
}

Expand All @@ -117,7 +114,7 @@ async function imageStore(group_id, images) {
platformType: 9,
buType: 1,
picType: 1000,
buildVer: "8.2.7.4410",
buildVer: this.apkver,
appPicType: 1006,
fileIndex: BUF0,
transferUrl: BUF0,
Expand Down Expand Up @@ -147,7 +144,7 @@ async function offPicUp(user_id, images) {
buType: 1,
imgOriginal: 1,
imgType: 1000,
buildVer: "8.2.7.4410",
buildVer: this.apkver,
srvUpload: 1,
});
}
Expand All @@ -166,7 +163,7 @@ async function uploadImages(target, images, is_group) {
if (v.boolFileExit || !images[i].buf) continue;
const index = i % v.uint32UpIp.length;
v.md5 = images[i].md5, v.buf = images[i].buf, v.key = v.upUkey;
await highwayUpload(this.uin, v.uint32UpIp[index], v.uint32UpPort[index], v, is_group?2:1);
await highwayUpload.call(this, v.uint32UpIp[index], v.uint32UpPort[index], v, is_group?2:1);
}
return resp;
}
Expand All @@ -184,7 +181,7 @@ async function uploadMultiMessage(target, msg, bu) {
termType: 5,
platformType: 9,
netType: 3,
buildVer: "8.2.0.1296",
buildVer: this.apkver,
buType: bu,
reqChannelType: 0,
multimsgApplyupReq: [{
Expand Down Expand Up @@ -217,7 +214,7 @@ async function uploadMultiMessage(target, msg, bu) {
md5: common.md5(buf),
key: resp.msgSig
}
await highwayUpload(this.uin, resp.uint32UpIp[0], resp.uint32UpPort[0], o, 27);
await highwayUpload.call(this, resp.uint32UpIp[0], resp.uint32UpPort[0], o, 27);
return resp;
}

Expand All @@ -235,7 +232,7 @@ async function uploadPtt(target, ptt) {
platformType: 9,
buType: 4,
innerIp: 0,
buildVer: "6.5.5.663",
buildVer: this.apkver,
voiceLength: 1,
codec: ptt.ext===".amr"?0:1,
voiceType: 1,
Expand All @@ -261,7 +258,7 @@ async function uploadPtt(target, ptt) {
}
const url = `http://${ip}:${port}/?` + querystring.stringify(params);
const headers = {
"User-Agent": "QQ/8.2.0.1296 CFNetwork/1126",
"User-Agent": `QQ/${this.apkver} CFNetwork/1126`,
"Net-Type": "Wifi"
};
await new Promise((resolve)=>{
Expand All @@ -280,7 +277,7 @@ async function downloadMultiMsg(resid, bu) {
termType: 5,
platformType: 9,
netType: 3,
buildVer: "8.2.0.1296",
buildVer: this.apkver,
buType: bu,
reqChannelType: 2,
multimsgApplydownReq: [{
Expand All @@ -292,13 +289,16 @@ async function downloadMultiMsg(resid, bu) {
let resp = pb.decode("MultiRspBody", blob);

resp = resp.multimsgApplydownRsp[0];
const url = `http://${int32ip2str(resp.uint32DownIp[0])}:${resp.uint32DownPort[0]}` + resp.thumbDownPara.toString();
const ip = int32ip2str(resp.uint32DownIp[0]), port = resp.uint32DownPort[0];
let url = port == 443 ? "https://ssl.htdata.qq.com" : `http://${ip}:${port}`;
url += String(resp.thumbDownPara);
const headers = {
"User-Agent": "QQ/8.2.0.1296 CFNetwork/1126",
"User-Agent": `QQ/${this.apkver} CFNetwork/1126`,
"Net-Type": "Wifi"
};
return new Promise((resolve, reject)=>{
http.get(url, {headers}, (res)=>{
const protocol = port == 443 ? https : http;
protocol.get(url, {headers}, (res)=>{
const data = [];
res.on("data", (chunk)=>data.push(chunk));
res.on("end", ()=>{
Expand Down
4 changes: 2 additions & 2 deletions lib/troop.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function setSign(sign = "") {
unknown: {
num: 825110830
},
ver: "8.2.7"
ver: this.apkver.substr(0, 5)
},
body: {
uin: this.uin,
Expand Down Expand Up @@ -426,7 +426,7 @@ async function inviteFriend(group_id, user_id) {
uin: user_id
}
}),
clientVersion: "android 8.2.7"
clientVersion: "android " + this.apkver.substr(0, 5)
});
const blob = await this.sendUNI("OidbSvc.oidb_0x758", body);
const result = pb.decode("OIDBSSOPkg", blob).bodybuffer.length > 6 ? 0 : 1;
Expand Down

0 comments on commit d4ee4a9

Please sign in to comment.