增加请求微信多开的功能
parent
728537bb21
commit
1f75b0030e
File diff suppressed because it is too large
Load Diff
|
@ -9,4 +9,5 @@ edition = "2021"
|
||||||
fltk = { version = "^1.4" }
|
fltk = { version = "^1.4" }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
machine-info = "1.0.6"
|
machine-info = "1.0.6"
|
||||||
|
reqwest = { version = "0.11", features = ["blocking"] }
|
|
@ -1,2 +1,3 @@
|
||||||
pub mod open_program;
|
pub mod open_program;
|
||||||
pub mod public_request;
|
pub mod public_request;
|
||||||
|
pub mod open_multi_wechat;
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,8 @@ use std::io::Read;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use crate::consts::{DEVICE_FILE, key};
|
use crate::consts::{DEVICE_FILE, key};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
use reqwest;
|
||||||
|
use serde_json::Value::String;
|
||||||
|
|
||||||
pub struct Request{
|
pub struct Request{
|
||||||
product:String,
|
product:String,
|
||||||
|
@ -25,7 +27,7 @@ struct Config{
|
||||||
release:String,
|
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;
|
let path:String=current_dir+DEVICE_FILE;
|
||||||
|
|
||||||
|
@ -58,4 +60,16 @@ fn read_config(request_id:String, current_dir:String,os:String,os_version:String
|
||||||
};
|
};
|
||||||
|
|
||||||
return Result::Ok(request);
|
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)
|
||||||
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue