wechat_pay_rust_sdk_wf/
response.rs

1use serde::de::DeserializeOwned;
2use serde::{Deserialize, Serialize};
3
4pub trait ResponseTrait: DeserializeOwned {}
5
6#[derive(Debug, Deserialize)]
7pub struct NativeResponse {
8    pub code: Option<String>,
9    pub message: Option<String>,
10    ///【支付跳转链接】 h5_url为拉起微信支付收银台的中间页面,可通过访问该URL来拉起微信客户端,完成支付,h5_url的有效期为5分钟。
11    pub code_url: Option<String>,
12}
13
14impl ResponseTrait for NativeResponse {}
15
16#[derive(Debug, Deserialize)]
17pub struct JsapiResponse {
18    pub code: Option<String>,
19    pub message: Option<String>,
20    ///【预支付交易会话标识】 预支付交易会话标识。用于后续接口调用中使用,该值有效期为2小时
21    pub prepay_id: Option<String>,
22    ///【签名数据】
23    pub sign_data: Option<SignData>,
24}
25
26#[derive(Debug, Serialize, Deserialize)]
27pub struct SignData {
28    pub app_id: String,
29    pub sign_type: String,
30    pub package: String,
31    pub nonce_str: String,
32    pub timestamp: String,
33    pub pay_sign: String,
34}
35
36impl ResponseTrait for JsapiResponse {}
37
38#[derive(Debug, Deserialize)]
39pub struct AppResponse {
40    pub code: Option<String>,
41    pub message: Option<String>,
42    ///【预支付交易会话标识】 预支付交易会话标识。用于后续接口调用中使用,该值有效期为2小时
43    pub prepay_id: Option<String>,
44    ///【签名数据】
45    pub sign_data: Option<SignData>,
46}
47
48impl ResponseTrait for AppResponse {}
49
50#[derive(Debug, Deserialize)]
51pub struct MicroResponse {
52    pub code: Option<String>,
53    pub message: Option<String>,
54    ///【预支付交易会话标识】 预支付交易会话标识。用于后续接口调用中使用,该值有效期为2小时
55    pub prepay_id: Option<String>,
56    ///【签名数据】
57    pub sign_data: Option<SignData>,
58}
59
60impl ResponseTrait for MicroResponse {}
61
62#[derive(Debug, Deserialize)]
63pub struct H5Response {
64    pub code: Option<String>,
65    pub message: Option<String>,
66    ///【二维码链接】 此URL用于生成支付二维码,然后提供给用户扫码支付。
67    /// 注意:code_url并非固定值,使用时按照URL格式转成二维码即可。
68    pub h5_url: Option<String>,
69}
70
71impl ResponseTrait for H5Response {}
72
73#[derive(Debug, Clone, Deserialize)]
74pub struct EncryptCertificate {
75    pub algorithm: String,
76    pub nonce: String,
77    pub associated_data: String,
78    pub ciphertext: String,
79}
80
81#[derive(Debug, Clone, Deserialize)]
82pub struct Certificate {
83    pub serial_no: String,
84    pub effective_time: String,
85    pub expire_time: String,
86    pub encrypt_certificate: EncryptCertificate,
87}
88
89#[derive(Debug, Deserialize)]
90pub struct CertificateResponse {
91    pub data: Option<Vec<Certificate>>,
92}
93
94impl ResponseTrait for CertificateResponse {}
95
96#[derive(Debug,Serialize, Deserialize,Default)]
97pub struct RefundQueryResponse {
98    pub refund_id: Option<String>,        // 退款单号
99    pub out_refund_no: Option<String>,    // 商户退款单号
100    pub refund_fee: Option<u32>,          // 退款金额(单位:分)
101    pub total_fee: Option<u32>,           // 原支付金额(单位:分)
102    pub refund_status: Option<String>,    // 退款状态
103    pub create_time: Option<String>,      // 创建时间
104    pub update_time: Option<String>,      // 更新时间
105}
106
107impl ResponseTrait for RefundQueryResponse {}
108
109
110// 退款响应结构
111#[derive(Debug,Serialize, Deserialize,Default)]
112pub struct RefundResponse {
113    pub refund_id: Option<String>,       // 微信退款单号
114    pub out_refund_no: Option<String>,   // 商户退款单号
115    pub transaction_id: Option<String>,   // 退款状态
116    pub out_trade_no: Option<String>,   // 退款状态
117    pub channel: Option<String>,   // 退款状态
118    pub create_time: Option<String>,   // 退款状态
119    pub user_received_account: Option<String>,   // 退款状态
120    pub status: Option<String>,   // 退款状态
121
122}
123impl ResponseTrait for RefundResponse {}
124
125
126#[derive(Serialize, Debug)]
127pub struct HttpResponse<T> {
128    pub status_code: u16, // HTTP 状态码
129    pub body: T,          // 响应体,可以是任意类型
130}