-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
40 lines (31 loc) · 1.26 KB
/
main.c
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
#include "core\api.h"
int main()
{
system("chcp 65001");
int ws = WsInit("ws://127.0.0.1:6700/ws");
WsRecv(&ws); // 忽略心跳事件
cJSON *msg;
char *msgText,*nickName;
long long userId,groupId;
while (1)
{
msg = WsRecv(&ws);
if (strcmp(parseJson(msg, "message_type")->valuestring, "private") == 0)
{
userId = parseJson(msg, "sender.user_id")->valuedouble;
nickName = parseJson(msg, "sender.nickname")->valuestring;
msgText = parseJson(msg, "message")->valuestring;
printf("收到用户 %s(%u) 的消息: %s\n", nickName, userId, msgText);
Api_SendPrivateMsg(&ws, userId, msgText);
}else if (strcmp(parseJson(msg, "message_type")->valuestring, "group") == 0)
{
userId = parseJson(msg, "sender.user_id")->valuedouble;
nickName = parseJson(msg, "sender.nickname")->valuestring;
groupId = parseJson(msg, "group_id")->valuedouble;
msgText = parseJson(msg, "message")->valuestring;
printf("收到 群(%u)内用户 %s(%u) 的消息: %s\n", groupId, nickName, userId, msgText);
Api_SendGroupMsg(&ws, groupId, msgText);
}
}
return 0;
}