pub struct MinappSecurity {
pub client: WechatMinappSDK,
}Fields§
§client: WechatMinappSDKImplementations§
Source§impl MinappSecurity
impl MinappSecurity
Sourcepub async fn msg_sec_check(&self, args: &Args) -> Result<MsgSecCheckResult>
pub async fn msg_sec_check(&self, args: &Args) -> Result<MsgSecCheckResult>
内容安全检测
对文本内容进行安全检测,识别违规内容。
§参数
args: 内容安全检测参数
§返回
成功返回 Ok(MsgSecCheckResult),包含检测结果
§错误
- 参数验证错误
- 网络错误
- 微信 API 返回错误
§示例
use wechat_minapp::client::WechatMinappSDK;
use wechat_minapp::minapp_security::{Args, Scene,MinappSecurity};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WechatMinappSDK::new("app_id", "secret");
let security = MinappSecurity::new(client);
let args = Args::builder()
.content("需要检测的文本内容")
.scene(Scene::Comment)
.openid("user_openid")
.build()?;
let result = security.msg_sec_check(&args).await?;
match (result.is_pass(), result.needs_review(), result.is_risky()) {
(true, _, _) => println!("内容安全,可以发布"),
(_, true, _) => println!("内容需要人工审核"),
(_, _, true) => println!("内容有风险,建议修改"),
_ => println!("未知状态"),
}
Ok(())
}§API 文档
Source§impl MinappSecurity
impl MinappSecurity
pub fn new(client: WechatMinappSDK) -> Self
Auto Trait Implementations§
impl Freeze for MinappSecurity
impl !RefUnwindSafe for MinappSecurity
impl Send for MinappSecurity
impl Sync for MinappSecurity
impl Unpin for MinappSecurity
impl UnsafeUnpin for MinappSecurity
impl !UnwindSafe for MinappSecurity
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more