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

Commit 6a6c404

Browse files
committed
支持加好友(必须是群友),删好友,邀请好友入群
1 parent d682038 commit 6a6c404

File tree

8 files changed

+180
-15
lines changed

8 files changed

+180
-15
lines changed

client.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,45 @@ class AndroidClient extends Client {
949949
return buildApiRet(100);
950950
}
951951

952+
async addFriend(group_id, user_id, comment = "") {
953+
group_id = parseInt(group_id), user_id = parseInt(user_id);
954+
if (!checkUin(group_id) || !checkUin(user_id))
955+
return buildApiRet(100);
956+
try {
957+
const type = await this.send(outgoing.buildAddSettingRequestPacket(user_id, this));
958+
switch (type) {
959+
case 0:
960+
case 1:
961+
// case 3:
962+
case 4:
963+
var res = await this.send(outgoing.buildAddFriendRequestPacket(type, group_id, user_id, String(comment), this));
964+
return buildApiRet(res ? 0 : 102);
965+
default:
966+
return buildApiRet(102);
967+
}
968+
} catch (e) {
969+
return buildApiRet(103);
970+
}
971+
}
972+
973+
async deleteFriend(user_id, block = true) {
974+
user_id = parseInt(user_id);
975+
if (!checkUin(user_id))
976+
return buildApiRet(100);
977+
this.write(outgoing.buildDelFriendRequestPacket(user_id, block, this));
978+
return buildApiRet(1);
979+
}
980+
981+
async inviteFriend(group_id, user_id) {
982+
group_id = parseInt(group_id), user_id = parseInt(user_id);
983+
if (!checkUin(group_id) || !checkUin(user_id))
984+
return buildApiRet(100);
985+
this.write(outgoing.buildInviteRequestPacket(group_id, user_id, this));
986+
return buildApiRet(1);
987+
}
988+
989+
///////////////////////////////////////////////////
990+
952991
canSendImage() {
953992
return buildApiRet(0, {yes: true});
954993
}

docs/api.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ client.on("system.login", (data)=>{
189189

190190
----
191191

192-
### 获取列表和info
192+
### 获取好友、群、群员列表和info
193193

194194
+ async `client.getFriendList([no_cache])`
195195
+ async `client.getGroupList([no_cache])`
@@ -201,7 +201,7 @@ client.on("system.login", (data)=>{
201201

202202
----
203203

204-
### 消息类
204+
### 发私聊消息、群消息
205205

206206
message可以使用 `Array` 格式或 `String` 格式,支持CQ码
207207

@@ -212,15 +212,15 @@ message可以使用 `Array` 格式或 `String` 格式,支持CQ码
212212

213213
----
214214

215-
### 处理申请
215+
### 处理申请和邀请
216216

217217
+ async `client.setFriendAddRequest(flag[, approve, remark, block])`
218218
+ async `client.setGroupAddRequest(flag[, approve, reason, block])`
219219
+ block字段表示是否拉黑,默认false
220220

221221
----
222222

223-
### 群操作
223+
### 群操作(踢人、禁言、退群、设置等)
224224

225225
+ async `client.setGroupKick(group_id, user_id[, reject_add_request])`
226226
+ async `client.setGroupBan(group_id, user_id[, duration])`
@@ -235,15 +235,22 @@ message可以使用 `Array` 格式或 `String` 格式,支持CQ码
235235

236236
----
237237

238+
## 改状态、加好友删好友、邀请好友入群
239+
240+
+ async `client.changeOnlineStatus(status)`
241+
+ `status` 允许的值:11我在线上 31离开 41隐身 50忙碌 60Q我吧 70请勿打扰
242+
+ async `client.addFriend(group_id, user_id[, comment])`
243+
+ async `client.deleteFriend(user_id[, block])` block(屏蔽)默认是true
244+
+ async `client.inviteFriend(group_id, user_id)`
245+
246+
----
247+
248+
## 其他
249+
238250
+ `client.canSendImage()`
239251
+ `client.canSendRecord()`
240252
+ `client.getStatus()`
241253
+ `client.getVersionInfo()`
242254
+ `client.getLoginInfo()`
243255

244256
----
245-
246-
## 其他
247-
248-
+ async `client.changeOnlineStatus(status)`
249-
+ `status` 允许的值:11我在线上 31离开 41隐身 50忙碌 60Q我吧 70请勿打扰

docs/project.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
|-|-|-|-|-|-|-|
1010
|好友|||||||
1111
|群聊|||||||
12-
|临时会话|||||||
12+
|临时会话|||||||
1313

1414
----
1515

@@ -18,6 +18,8 @@
1818
|好友列表||◯(好友增减)|
1919
|处理申请|||
2020
|撤回消息|||
21+
|加群员好友|||
22+
|删除好友|||
2123

2224
----
2325

@@ -39,6 +41,7 @@
3941
|退群|||
4042
|同意邀请|||
4143
|处理申请|||
44+
|邀请好友入群|||
4245

4346
----
4447

lib/incoming.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,26 @@ function decodeGroupFileUrlResponse(blob, c) {
923923
return pb.decode("D6D6RspBody", pb.decode("OIDBSSOPkg", blob).bodybuffer);
924924
}
925925

926+
function decodeAddSettingResponse(blob, c) {
927+
const nested = jce.decodeWrapper(blob);
928+
const parent = jce.decode(nested);
929+
if (parent[4]) return false;
930+
return parent[2];
931+
}
932+
function decodeAddFriendResponse(blob, c) {
933+
const nested = jce.decodeWrapper(blob);
934+
const parent = jce.decode(nested);
935+
return parent[6] === 0;
936+
}
937+
function decodeDelFriendResponse(blob, c) {
938+
// const nested = jce.decodeWrapper(blob);
939+
// const parent = jce.decode(nested);
940+
// common.log(parent)
941+
}
942+
function decodeInviteResponse(blob, c) {
943+
// common.log(pb.decode("OIDBSSOPkg", blob).bodybuffer)
944+
}
945+
926946
//----------------------------------------------------------------------------------------------------
927947

928948
const CMD = outgoing.CMD;
@@ -940,6 +960,11 @@ const decoders = new Map([
940960
[CMD.MEMBER_LIST, decodeGroupMemberListResponse],
941961
[CMD.GROUP_INFO, decodeGroupInfoResponse],
942962

963+
[CMD.ADD_SETTING, decodeAddSettingResponse],
964+
[CMD.ADD_FRIEND, decodeAddFriendResponse],
965+
[CMD.DEL_FRIEND, decodeDelFriendResponse],
966+
[CMD.GROUP_INVITE, decodeInviteResponse],
967+
943968
[CMD.FRIEND_REQ, decodeNewFriendResponse],
944969
[CMD.FRIEND_REQ_ACT, decodeNewFriendActionResponse],
945970
[CMD.GROUP_REQ, decodeNewGroupResponse],

lib/outgoing.js

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ const CMD = {
2929
GROUP_LIST: "friendlist.GetTroopListReqV2", //send,recv
3030
MEMBER_LIST: "friendlist.GetTroopMemberListReq", //send,recv
3131
GROUP_CARD: "friendlist.ModifyGroupCardReq", //send,recv
32-
ADD_FRIEND: "",
32+
33+
ADD_SETTING: "friendlist.getUserAddFriendSetting", //send,recv
34+
ADD_FRIEND: "friendlist.addFriend", //send,recv
35+
DEL_FRIEND: "friendlist.delFriend", //send,recv
3336

3437
FRIEND_REQ: "ProfileService.Pb.ReqSystemMsgNew.Friend", //send,recv
3538
FRIEND_REQ_ACT: "ProfileService.Pb.ReqSystemMsgAction.Friend", //send,recv
@@ -45,7 +48,7 @@ const CMD = {
4548
GROUP_LEAVE: "ProfileService.GroupMngReq", //send,recv
4649
GROUP_KICK: "OidbSvc.0x8a0_0", //send,recv
4750
GROUP_BAN: "OidbSvc.0x570_8", //send,recv
48-
GROUP_INVITE: "",
51+
GROUP_INVITE: "OidbSvc.oidb_0x758", //send,recv
4952
GROUP_TRANSFER: "",
5053
GROUP_DISMISS: "",
5154
GROUP_ADMIN: "OidbSvc.0x55c_1", //send,recv
@@ -1145,6 +1148,65 @@ function buildGroupFileUrlRequestPacket(group_id, bus_id, file_id, c) {
11451148

11461149
//----------------------------------------------------------------------------------------------------
11471150

1151+
function buildAddSettingRequestPacket(user_id, c) {
1152+
const FS = jce.encodeStruct([
1153+
c.uin,
1154+
user_id, 3004, 0, null, 1
1155+
]);
1156+
const extra = {
1157+
req_id: c.nextSeq(),
1158+
service: "mqq.IMService.FriendListServiceServantObj",
1159+
method: "GetUserAddFriendSettingReq",
1160+
};
1161+
const body = jce.encodeWrapper({FS}, extra);
1162+
return commonUNI(c, CMD.ADD_SETTING, body, BUF0);
1163+
}
1164+
function buildAddFriendRequestPacket(type, group_id, user_id, comment, c) {
1165+
const AF = jce.encodeStruct([
1166+
c.uin,
1167+
user_id, type?1:0, 1, 0, type?15:0, comment, 0, 1, null, 3004,
1168+
11, null, null, pb.encode("AddFrdFromGrp", {groupCode: group_id}), 0, null, null, 0
1169+
]);
1170+
const extra = {
1171+
req_id: c.nextSeq(),
1172+
service: "mqq.IMService.FriendListServiceServantObj",
1173+
method: "AddFriendReq",
1174+
};
1175+
const body = jce.encodeWrapper({AF}, extra);
1176+
return commonUNI(c, CMD.ADD_FRIEND, body, BUF0);
1177+
}
1178+
function buildDelFriendRequestPacket(user_id, block, c) {
1179+
const DF = jce.encodeStruct([
1180+
c.uin,
1181+
user_id, 2, block?1:0
1182+
]);
1183+
const extra = {
1184+
req_id: c.nextSeq(),
1185+
service: "mqq.IMService.FriendListServiceServantObj",
1186+
method: "DelFriendReq",
1187+
};
1188+
const body = jce.encodeWrapper({DF}, extra);
1189+
return commonUNI(c, CMD.DEL_FRIEND, body, BUF0);
1190+
}
1191+
function buildInviteRequestPacket(group_id, user_id, c) {
1192+
c.nextSeq();
1193+
const body = pb.encode("OIDBSSOPkg", {
1194+
command: 1880,
1195+
serviceType: 1,
1196+
result: 0,
1197+
bodybuffer: pb.encode("D758ReqBody", {
1198+
groupCode: group_id,
1199+
toUin: {
1200+
uin: user_id
1201+
}
1202+
}),
1203+
clientVersion: "android 8.2.7"
1204+
});
1205+
return commonUNI(c, CMD.GROUP_INVITE, body);
1206+
}
1207+
1208+
//----------------------------------------------------------------------------------------------------
1209+
11481210
module.exports = {
11491211

11501212
CMD,
@@ -1161,6 +1223,7 @@ module.exports = {
11611223

11621224
// request
11631225
buildGroupRequestRequestPacket, buildFriendRequestRequestPacket, buildNewFriendRequestPacket, buildNewGroupRequestPacket,
1226+
buildAddSettingRequestPacket, buildAddFriendRequestPacket, buildDelFriendRequestPacket, buildInviteRequestPacket,
11641227

11651228
// recall leave
11661229
buildFriendRecallRequestPacket, buildGroupRecallRequestPacket, buildGroupLeaveRequestPacket,

lib/pb.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3944,6 +3944,26 @@ var $root = ($protobuf.roots["default"] || ($protobuf.roots["default"] = new $pr
39443944
}
39453945
}
39463946
},
3947+
D758ReqBody: {
3948+
fields: {
3949+
groupCode: {
3950+
type: "int64",
3951+
id: 1
3952+
},
3953+
toUin: {
3954+
type: "D758Uin",
3955+
id: 2
3956+
},
3957+
}
3958+
},
3959+
D758Uin: {
3960+
fields: {
3961+
uin: {
3962+
type: "int64",
3963+
id: 1
3964+
}
3965+
}
3966+
},
39473967
D88DReqBody: {
39483968
fields: {
39493969
appid: {
@@ -6461,7 +6481,15 @@ var $root = ($protobuf.roots["default"] || ($protobuf.roots["default"] = new $pr
64616481
id: 2
64626482
},
64636483
}
6464-
}
6484+
},
6485+
AddFrdFromGrp: {
6486+
fields: {
6487+
groupCode: {
6488+
type: "int64",
6489+
id: 1
6490+
}
6491+
}
6492+
},
64656493
});
64666494

64676495
/**

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oicq",
3-
"version": "1.4.6",
3+
"version": "1.5.0",
44
"description": "QQ protocol!",
55
"main": "client.js",
66
"scripts": {

0 commit comments

Comments
 (0)