Impl GetUserInfo

This commit is contained in:
Changhua 2023-04-11 23:26:38 +08:00
parent 5800bba855
commit b39ab1e5e4
6 changed files with 77 additions and 8 deletions

View File

@ -238,6 +238,15 @@ class Wcf():
return tables
def get_user_info(self) -> dict:
"""获取个人信息"""
req = wcf_pb2.Request()
req.func = wcf_pb2.FUNC_GET_USER_INFO # FUNC_GET_USER_INFO
rsp = self._send_request(req)
ui = json_format.MessageToDict(rsp.ui)
return ui
def send_text(self, msg: str, receiver: str, aters: Optional[str] = "") -> int:
"""发送文本消息"""
req = wcf_pb2.Request()

View File

@ -46,3 +46,10 @@ typedef struct {
string thumb;
string extra;
} WxMsg_t;
typedef struct {
string wxid;
string name;
string mobile;
string home;
} UserInfo_t;

View File

@ -11,6 +11,7 @@ enum Functions {
FUNC_GET_CONTACTS = 0x12;
FUNC_GET_DB_NAMES = 0x13;
FUNC_GET_DB_TABLES = 0x14;
FUNC_GET_USER_INFO = 0x15;
FUNC_SEND_TXT = 0x20;
FUNC_SEND_IMG = 0x21;
FUNC_SEND_FILE = 0x22;
@ -44,14 +45,15 @@ message Response
Functions func = 1;
oneof msg
{
int32 status = 2;
string str = 3;
WxMsg wxmsg = 4;
MsgTypes types = 5;
RpcContacts contacts = 6;
DbNames dbs = 7;
DbTables tables = 8;
DbRows rows = 9;
int32 status = 2; // Int
string str = 3; //
WxMsg wxmsg = 4; //
MsgTypes types = 5; //
RpcContacts contacts = 6; //
DbNames dbs = 7; //
DbTables tables = 8; //
DbRows rows = 9; //
UserInfo ui = 10; //
};
}
@ -141,3 +143,11 @@ message AddMembers
string roomid = 1; // ID
string wxids = 2; //
}
message UserInfo
{
string wxid = 1; // ID
string name = 2; //
string mobile = 3; //
string home = 4; // /
}

View File

@ -163,6 +163,28 @@ bool func_get_db_tables(char *db, uint8_t *out, size_t *len)
return true;
}
bool func_get_user_info(uint8_t *out, size_t *len)
{
Response rsp = Response_init_default;
rsp.func = Functions_FUNC_GET_USER_INFO;
rsp.which_msg = Response_ui_tag;
UserInfo_t ui = GetUserInfo();
rsp.msg.ui.wxid = (char *)ui.wxid.c_str();
rsp.msg.ui.name = (char *)ui.name.c_str();
rsp.msg.ui.mobile = (char *)ui.mobile.c_str();
rsp.msg.ui.home = (char *)ui.home.c_str();
pb_ostream_t stream = pb_ostream_from_buffer(out, *len);
if (!pb_encode(&stream, Response_fields, &rsp)) {
LOG_ERROR("Encoding failed: {}", PB_GET_ERROR(&stream));
return false;
}
*len = stream.bytes_written;
return true;
}
bool func_send_txt(TextMsg txt, uint8_t *out, size_t *len)
{
Response rsp = Response_init_default;
@ -506,6 +528,11 @@ static bool dispatcher(uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len
ret = func_get_db_tables(req.msg.str, out, out_len);
break;
}
case Functions_FUNC_GET_USER_INFO: {
LOG_DEBUG("[Functions_FUNC_GET_USER_INFO]");
ret = func_get_user_info(out, out_len);
break;
}
case Functions_FUNC_SEND_TXT: {
LOG_DEBUG("[Functions_FUNC_SEND_TXT]");
ret = func_send_txt(req.msg.txt, out, out_len);

View File

@ -25,3 +25,15 @@ string GetSelfWxid()
return "empty_wxid";
}
}
UserInfo_t GetUserInfo()
{
UserInfo_t ui;
ui.wxid = GetSelfWxid();
ui.name = GET_STRING_FROM_P(g_WeChatWinDllAddr + g_WxCalls.ui.nickName);
ui.mobile = GET_STRING_FROM_P(g_WeChatWinDllAddr + g_WxCalls.ui.mobile);
ui.home = GET_STRING(g_WeChatWinDllAddr + g_WxCalls.ui.home);
return ui;
}

View File

@ -2,7 +2,11 @@
#include <string>
#include "pb_types.h"
using namespace std;
string GetHomePath();
string GetSelfWxid();
UserInfo_t GetUserInfo();