增加请求微信多开的功能

master
孙羽 2023-12-20 21:09:00 +08:00
parent 728537bb21
commit 1f75b0030e
5 changed files with 1030 additions and 3 deletions

974
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,3 +10,4 @@ fltk = { version = "^1.4" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
machine-info = "1.0.6"
reqwest = { version = "0.11", features = ["blocking"] }

View File

@ -1,2 +1,3 @@
pub mod open_program;
pub mod public_request;
pub mod open_multi_wechat;

View File

@ -0,0 +1,37 @@
use serde_json::Value;
use crate::network::public_request::{read_config, Request, send_request};
//发送微信多开请求
pub fn send_open_multi_wechat(current_dir:String,os:String,os_version:String)->String{
//如果不能正确读取信息则禁止打开
let request:Request=match read_config(String::from("xxx"), current_dir, os, os_version){
Ok(request)=>request,
Err(_)=>return "配置文件损坏".to_string()
};
//如果不能将读到的信息序列化则允许打开
let json:String=match serde_json::to_string(&request){
Ok(json)=>json,
Err(_)=>return "ok".to_string()
};
//发送请求,若发送失败允许打开
let res:String=match send_request(json){
Ok(res)=>res,
Err(_)=>return "ok".to_string()
};
//反序列化json,反序列化失败允许打开
let res:Value=match serde_json::from_str(res.as_str()) {
Ok(res)=>res,
Err(_)=>return "ok".to_string()
};
//返回msg字段的值找不到允许打开
if let Some(msg)=res.get("msg").and_then(Value::as_str){
return msg.to_string();
}else{
return "ok".to_string();
}
}

View File

@ -3,6 +3,8 @@ use std::io::Read;
use std::str::FromStr;
use crate::consts::{DEVICE_FILE, key};
use std::time::{SystemTime, UNIX_EPOCH};
use reqwest;
use serde_json::Value::String;
pub struct Request{
product:String,
@ -25,7 +27,7 @@ struct Config{
release:String,
}
fn read_config(request_id:String, current_dir:String,os:String,os_version:String) -> Result<Request,Err>{
pub fn read_config(request_id:String, current_dir:String,os:String,os_version:String) -> Result<Request,Err>{
let path:String=current_dir+DEVICE_FILE;
@ -59,3 +61,15 @@ fn read_config(request_id:String, current_dir:String,os:String,os_version:String
return Result::Ok(request);
}
//统一发送网络请求
pub fn send_request(request:String)->Result<String,Err>{
let client = reqwest::blocking::Client::new();
match client.post("http://example.com")
.header("Content-Type", "application/json")
.body(request)
.send(){
Ok(res)=>return Result::Ok(String::from(res)),
Err(error)=>return Result::Err(error)
};
}