Skip to main content

wechat_mp_trade/
lib.rs

1//! 微信小程序发货信息管理 / 交易管理服务
2//!
3//! 文档:
4//! - [发货信息管理服务](https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order-shipping/order-shipping.html)
5//! - [交易管理服务接口列表](https://developers.weixin.qq.com/miniprogram/dev/server/API/order_shipping/)
6
7mod manage;
8mod models;
9mod notify;
10mod order;
11mod shipping;
12
13pub use manage::{
14    is_trade_managed, is_trade_management_confirmation_completed, op_special_order,
15    IsTradeManagedResponse, IsTradeManagementConfirmationCompletedResponse, OpSpecialOrderRequest,
16    SpecialOrderType,
17};
18pub use models::{
19    now_upload_time, Contact, DeliveryMode, LogisticsType, Order, OrderKey, OrderNumberType,
20    OrderState, Payer, ShippingInfo, ShippingItem, ShippingListItemView,
21};
22pub use notify::{
23    notify_confirm_receive, set_msg_jump_path, NotifyConfirmReceiveRequest, SetMsgJumpPathRequest,
24};
25pub use order::{
26    get_order, get_order_list, GetOrderListRequest, GetOrderListResponse, GetOrderRequest,
27    GetOrderResponse, PayTimeRange,
28};
29pub use shipping::{
30    upload_combined_shipping_info, upload_shipping_info, CombinedSubOrder,
31    UploadCombinedShippingInfoRequest, UploadShippingInfoRequest,
32};
33
34use wechat_mp_core::MpClient;
35
36/// 发货 / 交易管理 API 门面
37#[derive(Clone)]
38pub struct TradeApi {
39    client: MpClient,
40}
41
42impl TradeApi {
43    /// 基于已有客户端创建
44    pub fn new(client: MpClient) -> Self {
45        Self { client }
46    }
47
48    /// 内部客户端
49    pub fn client(&self) -> &MpClient {
50        &self.client
51    }
52
53    /// 发货信息录入
54    pub async fn upload_shipping_info(
55        &self,
56        req: &UploadShippingInfoRequest,
57    ) -> wechat_mp_core::Result<()> {
58        upload_shipping_info(&self.client, req).await
59    }
60
61    /// 发货信息合单录入
62    pub async fn upload_combined_shipping_info(
63        &self,
64        req: &UploadCombinedShippingInfoRequest,
65    ) -> wechat_mp_core::Result<()> {
66        upload_combined_shipping_info(&self.client, req).await
67    }
68
69    /// 查询订单发货状态
70    pub async fn get_order(
71        &self,
72        req: &GetOrderRequest,
73    ) -> wechat_mp_core::Result<GetOrderResponse> {
74        get_order(&self.client, req).await
75    }
76
77    /// 查询订单列表
78    pub async fn get_order_list(
79        &self,
80        req: &GetOrderListRequest,
81    ) -> wechat_mp_core::Result<GetOrderListResponse> {
82        get_order_list(&self.client, req).await
83    }
84
85    /// 确认收货提醒
86    pub async fn notify_confirm_receive(
87        &self,
88        req: &NotifyConfirmReceiveRequest,
89    ) -> wechat_mp_core::Result<()> {
90        notify_confirm_receive(&self.client, req).await
91    }
92
93    /// 消息跳转路径设置
94    pub async fn set_msg_jump_path(&self, path: &str) -> wechat_mp_core::Result<()> {
95        set_msg_jump_path(&self.client, path).await
96    }
97
98    /// 是否已开通发货信息管理服务
99    pub async fn is_trade_managed(&self, appid: &str) -> wechat_mp_core::Result<bool> {
100        is_trade_managed(&self.client, appid).await
101    }
102
103    /// 是否已完成交易结算管理确认
104    pub async fn is_trade_management_confirmation_completed(
105        &self,
106        appid: &str,
107    ) -> wechat_mp_core::Result<bool> {
108        is_trade_management_confirmation_completed(&self.client, appid).await
109    }
110
111    /// 特殊发货报备
112    pub async fn op_special_order(
113        &self,
114        req: &OpSpecialOrderRequest,
115    ) -> wechat_mp_core::Result<()> {
116        op_special_order(&self.client, req).await
117    }
118}