pub struct Link {
pub client: WechatMinappSDK,
}Fields§
§client: WechatMinappSDKImplementations§
Source§impl Link
impl Link
Sourcepub async fn short_link(&self, args: ShortLinkArgs) -> Result<ShortLink>
pub async fn short_link(&self, args: ShortLinkArgs) -> Result<ShortLink>
生成短链接
调用微信小程序短链接生成接口,返回短链接ShortLink。
§参数
args: 短链接生成参数
§返回
成功返回 Ok(ShortLink),失败返回错误信息。
§示例
use wechat_minapp::client::WechatMinapp;
use wechat_minapp::Link::{ShortLinkArgs,Link};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 初始化客户端
let app_id = "your_app_id";
let secret = "your_app_secret";
let client = WechatMinapp::new(app_id, secret);
let link = Link::new(client);
let args = ShortLinkArgs::builder()
.path("pages/index/index")
.build()
.unwrap();
// 生成短链接
let short_link = link.short_link(args).await?;
Ok(())
}§错误
- 网络错误
- 认证错误(access_token 无效)
- 微信 API 返回错误
- 参数序列化错误
Auto Trait Implementations§
impl Freeze for Link
impl !RefUnwindSafe for Link
impl Send for Link
impl Sync for Link
impl Unpin for Link
impl UnsafeUnpin for Link
impl !UnwindSafe for Link
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