Skip to content

Commit 8ca53fb

Browse files
committed
refactor: 优化代码格式,调整函数参数和输出格式
1 parent 55ca606 commit 8ca53fb

14 files changed

Lines changed: 84 additions & 57 deletions

examples/integration_test.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ async fn main() {
9797
print!("[6/8] Get Material Count... ");
9898
match client.get_material_count().await {
9999
Ok(count) => {
100-
println!("OK (image: {}, voice: {}, video: {}, news: {})",
101-
count.image_count, count.voice_count, count.video_count, count.news_count);
100+
println!(
101+
"OK (image: {}, voice: {}, video: {}, news: {})",
102+
count.image_count, count.voice_count, count.video_count, count.news_count
103+
);
102104
passed += 1;
103105
}
104106
Err(e) => {

examples/message_handler.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use wechat_oa_sdk::Config;
88
use wechat_oa_sdk::WeChatClient;
99
use wechat_oa_sdk::api::message::IncomingMessage;
10-
use wechat_oa_sdk::models::reply::{TextReply, NewsReply, NewsArticle, empty_reply};
10+
use wechat_oa_sdk::models::reply::{NewsArticle, NewsReply, TextReply, empty_reply};
1111

1212
fn main() {
1313
// Create client with token for signature verification
@@ -76,14 +76,12 @@ fn handle_message(msg: IncomingMessage) -> String {
7676
}
7777
IncomingMessage::Image(img) => {
7878
// Reply with news article
79-
let articles = vec![
80-
NewsArticle {
81-
title: "Thanks for the image!".to_string(),
82-
description: "We received your image.".to_string(),
83-
pic_url: img.pic_url.clone(),
84-
url: "https://example.com".to_string(),
85-
}
86-
];
79+
let articles = vec![NewsArticle {
80+
title: "Thanks for the image!".to_string(),
81+
description: "We received your image.".to_string(),
82+
pic_url: img.pic_url.clone(),
83+
url: "https://example.com".to_string(),
84+
}];
8785
let reply = NewsReply::new(&img.from_user_name, &img.to_user_name, articles);
8886
reply.to_xml()
8987
}

examples/publish_article.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
99
use std::env;
1010
use std::fs;
11-
use wechat_oa_sdk::{Config, WeChatClient};
1211
use wechat_oa_sdk::models::material::MaterialType;
1312
use wechat_oa_sdk::models::publish::Article;
13+
use wechat_oa_sdk::{Config, WeChatClient};
1414

1515
#[tokio::main]
1616
async fn main() -> Result<(), Box<dyn std::error::Error>> {

src/api/customer_service.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ struct SendResponse {
108108

109109
impl WeChatClient {
110110
/// Send a customer service message.
111-
pub async fn send_customer_service_message(&self, message: &CustomerServiceMessage) -> Result<()> {
111+
pub async fn send_customer_service_message(
112+
&self,
113+
message: &CustomerServiceMessage,
114+
) -> Result<()> {
112115
let _: SendResponse = self.post_json("/message/custom/send", message).await?;
113116
Ok(())
114117
}

src/api/message.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use quick_xml::de::from_str;
33
use crate::client::WeChatClient;
44
use crate::crypto::check_signature;
55
use crate::error::Result;
6-
use crate::models::message::*;
76
use crate::models::event::*;
7+
use crate::models::message::*;
88

99
/// Incoming message/event from WeChat.
1010
#[derive(Debug, Clone)]
@@ -71,7 +71,9 @@ impl WeChatClient {
7171
"LOCATION" => IncomingMessage::LocationEvent(from_str(xml_body)?),
7272
"CLICK" => IncomingMessage::MenuClickEvent(from_str(xml_body)?),
7373
"VIEW" => IncomingMessage::MenuViewEvent(from_str(xml_body)?),
74-
"TEMPLATESENDJOBFINISH" => IncomingMessage::TemplateSendJobFinishEvent(from_str(xml_body)?),
74+
"TEMPLATESENDJOBFINISH" => {
75+
IncomingMessage::TemplateSendJobFinishEvent(from_str(xml_body)?)
76+
}
7577
_ => IncomingMessage::Unknown(xml_body.to_string()),
7678
};
7779

src/api/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
pub mod message;
21
pub mod customer_service;
3-
pub mod template;
42
pub mod material;
5-
pub mod user;
63
pub mod menu;
7-
pub mod stats;
4+
pub mod message;
85
pub mod publish;
96
pub mod qrcode;
7+
pub mod stats;
8+
pub mod template;
9+
pub mod user;

src/api/publish.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,13 @@ impl WeChatClient {
230230
/// Returns the URL of the uploaded image (can be used in article HTML).
231231
/// This is different from material upload - these images are specifically
232232
/// for embedding in article content.
233-
pub async fn upload_article_image(&self, file_name: &str, file_data: Vec<u8>) -> Result<String> {
233+
pub async fn upload_article_image(
234+
&self,
235+
file_name: &str,
236+
file_data: Vec<u8>,
237+
) -> Result<String> {
234238
let token = self.access_token().await?;
235-
let url = format!(
236-
"{}/media/uploadimg?access_token={}",
237-
WECHAT_API_BASE, token
238-
);
239+
let url = format!("{}/media/uploadimg?access_token={}", WECHAT_API_BASE, token);
239240

240241
let part = Part::bytes(file_data).file_name(file_name.to_string());
241242
let form = Form::new().part("media", part);

src/api/stats.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ impl WeChatClient {
172172

173173
/// Get upstream message hour statistics (single day only).
174174
pub async fn get_upstream_msg_hour(&self, range: &DateRange) -> Result<Vec<UpstreamMsgItem>> {
175-
let resp: ListResponse<UpstreamMsgItem> =
176-
self.post_json("/datacube/getupstreammsghour", range).await?;
175+
let resp: ListResponse<UpstreamMsgItem> = self
176+
.post_json("/datacube/getupstreammsghour", range)
177+
.await?;
177178
Ok(resp.list)
178179
}
179180

@@ -184,8 +185,9 @@ impl WeChatClient {
184185
&self,
185186
range: &DateRange,
186187
) -> Result<Vec<InterfaceSummaryItem>> {
187-
let resp: ListResponse<InterfaceSummaryItem> =
188-
self.post_json("/datacube/getinterfacesummary", range).await?;
188+
let resp: ListResponse<InterfaceSummaryItem> = self
189+
.post_json("/datacube/getinterfacesummary", range)
190+
.await?;
189191
Ok(resp.list)
190192
}
191193

src/api/template.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ impl WeChatClient {
6262
let body = serde_json::json!({
6363
"template_id": template_id
6464
});
65-
let _: DeleteResponse = self.post_json("/template/del_private_template", &body).await?;
65+
let _: DeleteResponse = self
66+
.post_json("/template/del_private_template", &body)
67+
.await?;
6668
Ok(())
6769
}
6870
}

src/api/user.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ impl WeChatClient {
131131
"openid_list": openids,
132132
"tagid": tag_id
133133
});
134-
let _: ApiResponse = self.post_json("/tags/members/batchuntagging", &body).await?;
134+
let _: ApiResponse = self
135+
.post_json("/tags/members/batchuntagging", &body)
136+
.await?;
135137
Ok(())
136138
}
137139

0 commit comments

Comments
 (0)