Skip to content

Commit a04b142

Browse files
authored
Merge pull request #13 from Chisonline/master
修复了无法反序列化qr_code url的问题,修正了json_get函数对于'}'']'的错误处理,以及修复了当响应缺少部分可选字段时导致的serde_json解析错误
2 parents 1a47cca + cdd2eec commit a04b142

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

src/pay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl Payer for PayClient {
204204
return Err(Error::new(
205205
ErrorKind::Other,
206206
format!(
207-
"trede_query failed: {} code:{}",
207+
"trade_query failed: {} code:{}",
208208
res.response.sub_msg.unwrap().as_str(),
209209
res.response.sub_code.unwrap().as_str()
210210
),
@@ -484,7 +484,7 @@ impl PayClient {
484484
.set_biz_content(biz_content)
485485
.set_method(biz_content.method().as_str());
486486
let res = self.execute(&mut request)?;
487-
dbg!(String::from_utf8(res.to_vec()));
487+
// dbg!(String::from_utf8(res.to_vec()));
488488
let is_pass = sync_verigy_sign(&res)?;
489489
if !is_pass {
490490
return Err(Error::new(ErrorKind::Other, "syncVerifySign no passed!"));

src/response.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pub struct PayResponse {
3838
pub point_amount: Option<String>,
3939
pub invoice_amount: Option<String>,
4040
pub gmt_payment: Option<String>,
41-
pub fund_bill_list: Vec<FundBill>,
41+
pub fund_bill_list: Option<Vec<FundBill>>,
4242
pub card_balance: Option<String>,
4343
pub store_name: Option<String>,
4444
pub buyer_user_id: Option<String>,
4545
pub discount_goods_detail: Option<String>,
46-
pub voucher_detail_list: Vec<VoucherDetail>,
46+
pub voucher_detail_list: Option<Vec<VoucherDetail>>,
4747
pub advance_amount: Option<String>,
4848
pub auth_trade_pay_mode: Option<String>,
4949
pub charge_amount: Option<String>,
@@ -117,13 +117,13 @@ pub struct QueryResponse {
117117
pub receipt_amount: Option<String>,
118118
pub store_id: Option<String>,
119119
pub terminal_id: Option<String>,
120-
pub fund_bill_list: FundBill,
120+
pub fund_bill_list: Option<Vec<FundBill>>,
121121
pub store_name: Option<String>,
122122
pub buyer_user_id: Option<String>,
123123
pub charge_amount: Option<String>,
124124
pub charge_flags: Option<String>,
125125
pub settlement_id: Option<String>,
126-
pub trade_settle_info: Vec<TradeSettleInfo>,
126+
pub trade_settle_info: Option<Vec<TradeSettleInfo>>,
127127
pub auth_trade_pay_mode: Option<String>,
128128
pub buyer_user_type: Option<String>,
129129
pub mdiscount_amount: Option<String>,
@@ -235,8 +235,8 @@ pub struct SystemOauthTokenResponse {
235235
struct OauthTokenInfo {
236236
access_token: Option<String>,
237237
alipay_user_id: Option<String>,
238-
expires_in: i32,
239-
re_expires_in: i32,
238+
expires_in: Option<i32>,
239+
re_expires_in: Option<i32>,
240240
refresh_token: Option<String>,
241241
user_id: Option<String>,
242242
}
@@ -295,10 +295,10 @@ pub struct RefundResponse {
295295
pub refund_fee: Option<String>,
296296
pub refund_currency: Option<String>,
297297
pub gmt_refund_pay: Option<String>,
298-
pub refund_detail_item_list: Vec<TradeFundBill>,
298+
pub refund_detail_item_list: Option<Vec<TradeFundBill>>,
299299
pub store_name: Option<String>,
300300
pub buyer_user_id: Option<String>,
301-
pub refund_preset_paytool_list: Vec<RefundPresetPaytool>,
301+
pub refund_preset_paytool_list: Option<Vec<RefundPresetPaytool>>,
302302
pub refund_settlement_id: Option<String>,
303303
pub present_refund_buyer_amount: Option<String>,
304304
pub present_refund_discount_amount: Option<String>,
@@ -308,7 +308,7 @@ pub struct RefundResponse {
308308
#[skip_serializing_none]
309309
#[derive(Serialize, Deserialize)]
310310
pub struct RefundPresetPaytool {
311-
pub amount: Vec<String>,
311+
pub amount: Option<Vec<String>>,
312312
pub assert_type_code: Option<String>,
313313
}
314314

@@ -345,9 +345,9 @@ pub struct RefundQueryResponse {
345345
pub refund_reason: Option<String>,
346346
pub total_amount: Option<String>,
347347
pub refund_amount: Option<String>,
348-
pub refund_royaltys: Vec<RefundRoyalty>,
348+
pub refund_royaltys: Option<Vec<RefundRoyalty>>,
349349
pub gmt_refund_pay: Option<String>,
350-
pub refund_detail_item_list: Vec<TradeFundBill>,
350+
pub refund_detail_item_list: Option<Vec<TradeFundBill>>,
351351
pub send_back_fee: Option<String>,
352352
pub refund_settlement_id: Option<String>,
353353
pub present_refund_buyer_amount: Option<String>,
@@ -404,7 +404,7 @@ pub struct PrecreateResponse {
404404
pub sub_code: Option<String>,
405405
pub sub_msg: Option<String>,
406406
pub out_trade_no: Option<String>,
407-
pub qrcode: Option<String>,
407+
pub qr_code: Option<String>,
408408
}
409409

410410
//===================================================
@@ -496,7 +496,7 @@ struct AuthTokenAppResponse {
496496
app_refresh_token: Option<String>,
497497
expires_in: Option<i32>,
498498
re_expires_in: Option<i32>,
499-
tokens: Vec<Token>,
499+
tokens: Option<Vec<Token>>,
500500
}
501501

502502
#[skip_serializing_none]
@@ -565,7 +565,7 @@ struct AlipayUserCertifyOpenQueryResponse {
565565
msg: Option<String>,
566566
sub_code: Option<String>,
567567
sub_msg: Option<String>,
568-
passed: Vec<String>,
568+
passed: Option<Vec<String>>,
569569
identity_info: Option<String>,
570570
material_info: Option<String>,
571571
}

src/util.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,19 @@ pub fn json_get(result: &str, key: &str) -> String {
8585
current = result.as_bytes()[index];
8686
let mut left_brackets = 0_usize;
8787
if current == b'{' || current == b'[' {
88-
while current != b'}' && current != b']' {
88+
loop {
8989
index += 1;
9090
current = result.as_bytes()[index];
9191
if current == b'{' || current == b'[' {
9292
left_brackets += 1;
9393
}
94+
95+
if (current == b']' || current == b'}') && left_brackets == 0 {
96+
break;
97+
}
9498

9599
if (current == b']' || current == b'}') && left_brackets > 0 {
96-
index += 1;
97100
left_brackets -= 1;
98-
current = result.as_bytes()[index];
99101
}
100102
}
101103
end = index + 1;

0 commit comments

Comments
 (0)