朋友圈

This commit is contained in:
super_wang 2023-07-17 23:32:19 +08:00
parent 535bc1ceaa
commit 7275e1facf
3 changed files with 76 additions and 29 deletions

View File

@ -22,6 +22,7 @@ enum Functions {
FUNC_EXEC_DB_QUERY = 0x50;
FUNC_ACCEPT_FRIEND = 0x51;
FUNC_RECV_TRANSFER = 0x52;
FUNC_REFRESH_PYQ = 0x53;
FUNC_DECRYPT_IMAGE = 0x60;
FUNC_ADD_ROOM_MEMBERS = 0x70;
FUNC_DEL_ROOM_MEMBERS = 0x71;
@ -42,6 +43,8 @@ message Request
XmlMsg xml = 9;
DecPath dec = 10;
Transfer tf = 11;
uint64 ui64 = 12; // 64
bool flag = 13;
}
}
@ -68,14 +71,16 @@ message WxMsg
{
bool is_self = 1; //
bool is_group = 2; //
int32 type = 3; //
string id = 4; // id
string xml = 5; // xml
string sender = 6; //
string roomid = 7; // id
string content = 8; //
string thumb = 9; //
string extra = 10; //
uint64 id = 3; // id
uint32 type = 4; //
uint32 ts = 5; //
string roomid = 6; // id
string content = 7; //
string sender = 8; //
string sign = 9; // Sign
string thumb = 10; //
string extra = 11; //
string xml = 12; // xml
}
message TextMsg
@ -170,4 +175,4 @@ message Transfer
string wxid = 1; //
string tfid = 2; // id transferid
string taid = 3; // Transaction id
}
}

View File

@ -3,7 +3,7 @@
pub struct Request {
#[prost(enumeration = "Functions", tag = "1")]
pub func: i32,
#[prost(oneof = "request::Msg", tags = "2, 3, 4, 5, 6, 7, 8, 9, 10, 11")]
#[prost(oneof = "request::Msg", tags = "2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13")]
pub msg: ::core::option::Option<request::Msg>,
}
/// Nested message and enum types in `Request`.
@ -31,6 +31,11 @@ pub mod request {
Dec(super::DecPath),
#[prost(message, tag = "11")]
Tf(super::Transfer),
/// 64 位整数,通用
#[prost(uint64, tag = "12")]
Ui64(u64),
#[prost(bool, tag = "13")]
Flag(bool),
}
}
#[allow(clippy::derive_partial_eq_without_eq)]
@ -87,30 +92,36 @@ pub struct WxMsg {
/// 是否群消息
#[prost(bool, tag = "2")]
pub is_group: bool,
/// 消息类型
#[prost(int32, tag = "3")]
pub r#type: i32,
/// 消息 id
#[prost(string, tag = "4")]
pub id: ::prost::alloc::string::String,
/// 消息 xml
#[prost(string, tag = "5")]
pub xml: ::prost::alloc::string::String,
/// 消息发送者
#[prost(string, tag = "6")]
pub sender: ::prost::alloc::string::String,
#[prost(uint64, tag = "3")]
pub id: u64,
/// 消息类型
#[prost(uint32, tag = "4")]
pub r#type: u32,
/// 消息类型
#[prost(uint32, tag = "5")]
pub ts: u32,
/// 群 id如果是群消息的话
#[prost(string, tag = "7")]
#[prost(string, tag = "6")]
pub roomid: ::prost::alloc::string::String,
/// 消息内容
#[prost(string, tag = "8")]
#[prost(string, tag = "7")]
pub content: ::prost::alloc::string::String,
/// 缩略图
/// 消息发送者
#[prost(string, tag = "8")]
pub sender: ::prost::alloc::string::String,
/// Sign
#[prost(string, tag = "9")]
pub sign: ::prost::alloc::string::String,
/// 缩略图
#[prost(string, tag = "10")]
pub thumb: ::prost::alloc::string::String,
/// 附加内容
#[prost(string, tag = "10")]
#[prost(string, tag = "11")]
pub extra: ::prost::alloc::string::String,
/// 消息 xml
#[prost(string, tag = "12")]
pub xml: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
@ -331,6 +342,7 @@ pub enum Functions {
FuncExecDbQuery = 80,
FuncAcceptFriend = 81,
FuncRecvTransfer = 82,
FuncRefreshPyq = 83,
FuncDecryptImage = 96,
FuncAddRoomMembers = 112,
FuncDelRoomMembers = 113,
@ -360,6 +372,7 @@ impl Functions {
Functions::FuncExecDbQuery => "FUNC_EXEC_DB_QUERY",
Functions::FuncAcceptFriend => "FUNC_ACCEPT_FRIEND",
Functions::FuncRecvTransfer => "FUNC_RECV_TRANSFER",
Functions::FuncRefreshPyq => "FUNC_REFRESH_PYQ",
Functions::FuncDecryptImage => "FUNC_DECRYPT_IMAGE",
Functions::FuncAddRoomMembers => "FUNC_ADD_ROOM_MEMBERS",
Functions::FuncDelRoomMembers => "FUNC_DEL_ROOM_MEMBERS",
@ -386,6 +399,7 @@ impl Functions {
"FUNC_EXEC_DB_QUERY" => Some(Self::FuncExecDbQuery),
"FUNC_ACCEPT_FRIEND" => Some(Self::FuncAcceptFriend),
"FUNC_RECV_TRANSFER" => Some(Self::FuncRecvTransfer),
"FUNC_REFRESH_PYQ" => Some(Self::FuncRefreshPyq),
"FUNC_DECRYPT_IMAGE" => Some(Self::FuncDecryptImage),
"FUNC_ADD_ROOM_MEMBERS" => Some(Self::FuncAddRoomMembers),
"FUNC_DEL_ROOM_MEMBERS" => Some(Self::FuncDelRoomMembers),

View File

@ -544,7 +544,7 @@ pub fn enable_listen(wechat: &mut WeChat) -> Result<nng::Socket, Box<dyn std::er
}
let req = wcf::Request {
func: wcf::Functions::FuncEnableRecvTxt.into(),
msg: None,
msg: Some(wcf::request::Msg::Flag(true)),
};
let response = match send_cmd(wechat, req) {
Ok(res) => res,
@ -770,8 +770,8 @@ pub fn recv_transfer(
func: wcf::Functions::FuncRecvTransfer.into(),
msg: Some(wcf::request::Msg::Tf(wcf::Transfer {
wxid: wxid,
taid: transferid,
tfid: transcationid,
tfid: transferid,
taid: transcationid,
})),
};
let response = match send_cmd(wechat, req) {
@ -794,6 +794,32 @@ pub fn recv_transfer(
};
}
/** 刷新朋友圈 */
pub fn refresh_pyq(id: u64, wechat: &mut WeChat) -> Result<bool, Box<dyn std::error::Error>> {
let req = wcf::Request {
func: wcf::Functions::FuncRefreshPyq.into(),
msg: Some(wcf::request::Msg::Ui64(id)),
};
let response = match send_cmd(wechat, req) {
Ok(res) => res,
Err(e) => {
error!("命令发送失败: {}", e);
return Err("接收转账失败".into());
}
};
if response.is_none() {
return Ok(false);
}
match response.unwrap() {
wcf::response::Msg::Status(status) => {
return Ok(status != -1);
}
_ => {
return Ok(false);
}
};
}
mod test {
#[test]
@ -858,9 +884,11 @@ mod test {
fn test_recv_msg() {
let mut wechat = crate::wechat::WeChat::default();
let mut socket = crate::wechat::enable_listen(&mut wechat).unwrap();
for _ in 1..5 {
for _index in 0..5 {
let _ = crate::wechat::refresh_pyq(0, &mut wechat);
let msg = crate::wechat::recv_msg(&mut socket).unwrap();
println!("WxMsg: {:?}", msg);
println!("--------------------------------------------------");
}
let _ = crate::wechat::disable_listen(&mut wechat);
}