Skip to main content

WechatHttpTransport

Trait WechatHttpTransport 

Source
pub trait WechatHttpTransport: Send + Sync {
    // Required methods
    fn get(&self, url: &str) -> Result<String, WechatError>;
    fn post_json(&self, url: &str, body: &str) -> Result<String, WechatError>;
    fn post_form(&self, url: &str, body: &str) -> Result<String, WechatError>;
}
Expand description

微信 HTTP 传输 trait — 用于解耦 SDK 与具体 HTTP 库

微信 SDK 需要 GET 和 POST(JSON / Form)调用并返回响应体字符串, 以便 SDK 解析 JSON 响应。业务方实现此 trait 注入 reqwest / hyper / etc.。

§线程安全

实现者必须保证 Send + Sync,因为 WechatSdk 通常作为单例在多线程下使用。

Required Methods§

Source

fn get(&self, url: &str) -> Result<String, WechatError>

GET 请求

§参数
  • url: 目标 URL
§返回

成功返回响应体字符串,失败返回 WechatError

Source

fn post_json(&self, url: &str, body: &str) -> Result<String, WechatError>

POST JSON 请求

§参数
  • url: 目标 URL
  • body: 请求体(JSON 字符串)
§返回

成功返回响应体字符串,失败返回 WechatError

Source

fn post_form(&self, url: &str, body: &str) -> Result<String, WechatError>

POST Form 请求

§参数
  • url: 目标 URL
  • body: 请求体(Form 字符串)
§返回

成功返回响应体字符串,失败返回 WechatError

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§