wx_applet 0.0.2

微信小程序的rust接口封装
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
use build_builder::Builder;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

#[derive(Clone, Debug, Serialize, Builder)]
pub struct BindAccountReq {
    r#type: BindType,
    biz_id: String,
    delivery_id: String,
    password: Option<String>,
    remark_content: Option<String>,
}

#[derive(Clone, Debug, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum BindType {
    #[default]
    Bind,
    Unbind,
}

#[derive(Clone, Debug, Deserialize)]
pub struct BindAccountRes;

#[derive(Clone, Debug, Deserialize)]
pub struct AllAccountRes {
    pub count: u32,
    pub list: Vec<Account>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct Account {
    pub biz_id: String,
    pub delivery_id: String,
    pub create_time: u32,
    pub update_time: u32,
    pub status_code: u32,
    pub alias: String,
    pub remark_wrong_msg: String,
    pub remark_content: String,
    pub quota_num: u32,
    pub quota_update_time: u32,
    pub service_type: Vec<ServiceType>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct ServiceType {
    pub service_type: u32,
    pub service_name: String,
}

#[derive(Clone, Debug, Deserialize)]
pub struct AllDeliveryRes {
    pub count: u32,
    pub data: Delivery,
}

#[derive(Clone, Debug, Deserialize)]
pub struct Delivery {
    pub delivery_id: String,
    pub delivery_name: String,
    pub can_use_cash: u32,
    pub can_get_quota: u32,
    pub service_type: ServiceType,
    pub cash_biz_id: String,
}

#[derive(Clone, Debug, Serialize)]
pub struct OrderReq {
    openid: String,
    delivery_id: Option<String>,
    waybill_id: Option<String>,
    order_id: Option<String>,
}

#[derive(Clone, Debug, Serialize, Default)]
pub struct OrderReqBuilder {
    openid: String,
    delivery_id: Option<String>,
    waybill_id: Option<String>,
    order_id: Option<String>,
}

impl OrderReq {
    pub fn builder() -> OrderReqBuilder {
        OrderReqBuilder::default()
    }
}

impl OrderReqBuilder {
    pub fn openid<T>(mut self, openid: T) -> Self
    where
        T: AsRef<str>,
    {
        self.openid = openid.as_ref().to_owned();
        self
    }

    pub fn delivery_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.delivery_id = Some(id.as_ref().to_owned());
        self
    }

    pub fn waybill_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.waybill_id = Some(id.as_ref().to_owned());
        self
    }

    pub fn order_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.waybill_id = Some(id.as_ref().to_owned());
        self
    }

    pub fn build(self) -> OrderReq {
        OrderReq {
            openid: self.openid,
            delivery_id: self.delivery_id,
            waybill_id: self.waybill_id,
            order_id: self.order_id,
        }
    }
}

#[derive(Clone, Debug, Deserialize)]
pub struct OrderRes {
    pub delivery_resultcode: u32,
    pub delivery_resultmsg: String,
}

#[derive(Clone, Debug, Deserialize)]
pub struct UpdatePrinterRes;

#[derive(Clone, Debug, Serialize)]
pub struct UpdatePrinterReq {
    openid: String,
    update_type: BindType,
    tagid_list: Option<String>,
}

impl UpdatePrinterReq {
    pub fn new<T>(openid: T, update_type: BindType, list: Option<T>) -> Self
    where
        T: AsRef<str>,
    {
        Self {
            openid: openid.as_ref().to_owned(),
            update_type,
            tagid_list: list.map(|l| l.as_ref().to_owned()),
        }
    }
}

#[derive(Clone, Debug, Serialize)]
pub struct QuotaReq {
    delivery_id: String,
    biz_id: String,
}

impl QuotaReq {
    pub fn new<T>(delivery_id: T, biz_id: T) -> Self
    where
        T: AsRef<str>,
    {
        Self {
            delivery_id: delivery_id.as_ref().to_owned(),
            biz_id: biz_id.as_ref().to_owned(),
        }
    }
}

#[derive(Clone, Debug, Deserialize)]
pub struct QuotaRes {
    pub quota_num: u32,
}

#[derive(Clone, Debug, Serialize, Default)]
pub struct GetOrderReq {
    order_id: String,
    openid: Option<String>,
    delivery_id: String,
    waybill_id: Option<String>,
    print_type: Option<u32>,
    custom_remark: Option<String>,
}

impl GetOrderReq {
    pub fn new<T>(order_id: T, delivery_id: T) -> Self
    where
        T: AsRef<str>,
    {
        Self {
            order_id: order_id.as_ref().to_owned(),
            delivery_id: delivery_id.as_ref().to_owned(),
            ..Default::default()
        }
    }
}

#[derive(Clone, Debug, Serialize, Default)]
pub struct GetOrderReqBuilder {
    order_id: String,
    openid: Option<String>,
    delivery_id: String,
    waybill_id: Option<String>,
    print_type: Option<u32>,
    custom_remark: Option<String>,
}

impl GetOrderReqBuilder {
    pub fn order_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.order_id = id.as_ref().to_owned();
        self
    }

    pub fn delivery_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.delivery_id = id.as_ref().to_owned();
        self
    }

    pub fn openid<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.openid = Some(id.as_ref().to_owned());
        self
    }

    pub fn waybill_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.waybill_id = Some(id.as_ref().to_owned());
        self
    }

    pub fn print_type(mut self, print_type: u32) -> Self {
        self.print_type = Some(print_type);
        self
    }

    pub fn custom_remark<T>(mut self, remark: T) -> Self
    where
        T: AsRef<str>,
    {
        self.custom_remark = Some(remark.as_ref().to_owned());
        self
    }

    pub fn build(self) -> GetOrderReq {
        GetOrderReq {
            order_id: self.order_id,
            openid: self.openid,
            delivery_id: self.delivery_id,
            waybill_id: self.waybill_id,
            print_type: self.print_type,
            custom_remark: self.custom_remark,
        }
    }
}

#[derive(Clone, Debug, Deserialize)]
pub struct GetOrderRes {
    pub print_html: String,
    pub order_id: String,
    pub delivery_id: String,
    pub waybill_id: String,
    pub order_status: OrderStatus,
    pub waybill_data: WaybillData,
}

#[derive(Clone, Debug, Deserialize)]
pub struct WaybillData {
    pub key: String,
    pub value: String,
}

#[derive(Clone, Debug, Deserialize_repr)]
#[repr(u8)]
pub enum OrderStatus {
    Normal = 0,
    Cancel = 1,
}

#[derive(Clone, Debug, Serialize)]
pub struct TestUpdateOrderReq {
    biz_id: String,
    order_id: String,
    delivery_id: String,
    waybill_id: String,
    action_time: u32,
    action_type: u32,
    action_msg: String,
}

impl TestUpdateOrderReq {
    pub fn builder() -> TestUpdateOrderReqBuilder {
        TestUpdateOrderReqBuilder::default()
    }
}

#[derive(Clone, Debug, Serialize, Default)]
pub struct TestUpdateOrderReqBuilder {
    biz_id: String,
    order_id: String,
    delivery_id: String,
    waybill_id: String,
    action_time: u32,
    action_type: u32,
    action_msg: String,
}

impl TestUpdateOrderReqBuilder {
    pub fn biz_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.biz_id = id.as_ref().to_owned();
        self
    }

    pub fn order_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.order_id = id.as_ref().to_owned();
        self
    }

    pub fn delivery_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.delivery_id = id.as_ref().to_owned();
        self
    }

    pub fn waybill_id<T>(mut self, id: T) -> Self
    where
        T: AsRef<str>,
    {
        self.waybill_id = id.as_ref().to_owned();
        self
    }

    pub fn action_time(mut self, time: u32) -> Self {
        self.action_time = time;
        self
    }

    pub fn action_type(mut self, action_type: u32) -> Self {
        self.action_type = action_type;
        self
    }

    pub fn action_msg<T>(mut self, msg: T) -> Self
    where
        T: AsRef<str>,
    {
        self.action_msg = msg.as_ref().to_owned();
        self
    }

    pub fn build(self) -> TestUpdateOrderReq {
        TestUpdateOrderReq {
            biz_id: self.biz_id,
            order_id: self.order_id,
            delivery_id: self.delivery_id,
            waybill_id: self.waybill_id,
            action_time: self.action_time,
            action_type: self.action_type,
            action_msg: self.action_msg,
        }
    }
}

#[derive(Clone, Debug, Deserialize)]
pub struct TestUpdateOrderRes;

#[derive(Clone, Debug, Deserialize)]
pub struct Printer {
    pub count: u32,
    pub openid: Vec<String>,
    pub tagid_list: Vec<String>,
}

#[derive(Clone, Debug, Serialize)]
pub struct OrderPathReq {
    openid: Option<String>,
    delivery_id: String,
    waybill_id: String,
}

impl OrderPathReq {
    pub fn new<T, U, S>(delivery_id: T, waybill_id: U, openid: Option<S>) -> Self
    where
        T: AsRef<str>,
        U: AsRef<str>,
        S: AsRef<str>,
    {
        Self {
            openid: openid.map(|o| o.as_ref().to_owned()),
            delivery_id: delivery_id.as_ref().to_owned(),
            waybill_id: waybill_id.as_ref().to_owned(),
        }
    }
}

#[derive(Clone, Debug, Deserialize)]
pub struct OrderPathRes {
    pub openid: String,
    pub delivery_id: String,
    pub waybill_id: String,
    pub path_item_num: u32,
    pub path_item_list: Vec<PathItem>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct PathItem {
    pub action_time: u32,
    pub action_type: u32,
    pub action_msg: String,
}

#[derive(Clone, Debug, Serialize)]
pub struct BatchGetOrderReq {
    order_list: Vec<OrderItem>,
}

impl BatchGetOrderReq {
    pub fn new(list: &[OrderItem]) -> Self {
        Self {
            order_list: list.to_owned(),
        }
    }
}

#[derive(Clone, Debug, Serialize)]
pub struct OrderItem {
    order_id: String,
    delivery_id: String,
    waybill_id: Option<String>,
}

impl OrderItem {
    pub fn new<T, U, S>(order_id: T, deliver_id: U, waybill_id: Option<S>) -> Self
    where
        T: AsRef<str>,
        U: AsRef<str>,
        S: AsRef<str>,
    {
        Self {
            order_id: order_id.as_ref().to_owned(),
            delivery_id: deliver_id.as_ref().to_owned(),
            waybill_id: waybill_id.map(|w| w.as_ref().to_owned()),
        }
    }
}

#[derive(Clone, Debug, Deserialize)]
pub struct BatchGetOrderRes {
    pub order_list: Vec<BatchOrderItem>,
}
#[derive(Clone, Debug, Deserialize)]
pub struct BatchOrderItem {
    pub errcode: u32,
    pub errmsg: String,
    pub print_html: String,
    pub order_id: String,
    pub delivery_id: String,
    pub waybill_id: String,
    pub order_status: OrderStatus,
    pub waybill_data: WaybillData,
}

#[derive(Clone, Debug, Serialize, Builder)]
pub struct AddOrderReq {
    order_id: String,
    openid: String,
    delivery_id: String,
    biz_id: String,
    custom_remark: Option<String>,
    tagid: Option<u32>,
    add_source: u32,
    wx_appid: Option<String>,
    expect_time: Option<u32>,
    take_mode: Option<u32>,
    sender: Sender,
    receiver: Receiver,
    cargo: Cargo,
    shop: Shop,
    insured: Insured,
    service: Service,
}

#[derive(Clone, Debug, Serialize, Deserialize, Builder)]
pub struct Sender {
    name: String,
    tel: String,
    mobile: String,
    company: String,
    post_code: String,
    country: String,
    provice: String,
    city: String,
    area: String,
    address: String,
}

#[derive(Clone, Debug, Serialize, Deserialize, Builder)]
pub struct Receiver {
    name: String,
    tel: String,
    mobile: String,
    company: String,
    post_code: String,
    country: String,
    provice: String,
    city: String,
    area: String,
    address: String,
}

#[derive(Clone, Debug, Serialize, Builder)]
pub struct Cargo {
    count: u32,
    weight: u32,
    space_x: u32,
    space_y: u32,
    space_z: u32,
}

#[derive(Clone, Debug, Serialize)]
pub struct Shop {
    wxa_path: Option<String>,
    img_url: Option<String>,
    goods_name: Option<String>,
    goods_count: Option<u32>,
    // TODO: 更新detail_list
    detail_list: Vec<String>,
}

#[derive(Clone, Debug, Serialize, Builder)]
pub struct Insured {
    use_insured: UseInsured,
    insured_value: Option<u32>,
}

#[derive(Clone, Debug, Serialize_repr)]
#[repr(u8)]
pub enum UseInsured {
    No = 0,
    Yes = 1,
}

#[derive(Clone, Debug, Serialize, Builder)]
pub struct Service {
    service_type: u32,
    service_name: String,
}

#[derive(Clone, Debug, Deserialize)]
pub struct AddOrderRes {
    pub order_id: String,
    pub waybill_id: String,
    pub delivery_resultcode: u32,
    pub delivery_resultmsg: String,
    pub waybill_data: Vec<WaybillData>,
}

#[derive(Clone, Debug, Serialize)]
pub struct UpdateBusinessReq {
    shop_app_id: String,
    biz_id: String,
    result_code: u32,
    result_msg: String,
}

#[derive(Clone, Debug, Deserialize)]
pub struct UpdateBusinessRes {}

#[derive(Clone, Debug, Serialize, Builder)]
pub struct UpdatePathReq {
    token: String,
    waybill_id: String,
    action_time: u32,
    action_type: u32,
    action_msg: String,
}

#[derive(Clone, Debug, Deserialize)]
pub struct UpdatePathRes {}

#[derive(Clone, Debug, Serialize, Builder)]
pub struct PreviewTemplateReq {
    waybill_id: String,
    waybill_template: String,
    waybill_data: String,
    custom: CustomTemplate,
}

#[derive(Clone, Debug, Serialize, Builder)]
pub struct CustomTemplate {
    order_id: String,
    openid: String,
    delivery_id: String,
    biz_id: String,
    custom_remark: Option<String>,
    tagid: Option<u32>,
    add_source: u32,
    wx_appid: Option<String>,
    sender: Sender,
    receiver: Receiver,
    cargo: Cargo,
    shop: Shop,
    insured: Insured,
    service: Service,
    expect_time: Option<u32>,
    take_mode: Option<u32>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct PreviewTemplateRes {
    pub waybill_id: String,
    pub rendered_waybill_template: String,
}

#[derive(Clone, Debug, Serialize)]
pub struct ContractReq {
    token: String,
    waybill_id: String,
}

impl ContractReq {
    pub fn new<T, U>(token: T, waybill_id: U) -> Self
    where
        T: AsRef<str>,
        U: AsRef<str>,
    {
        Self {
            token: token.as_ref().to_owned(),
            waybill_id: waybill_id.as_ref().to_owned(),
        }
    }
}

#[derive(Clone, Debug, Deserialize)]
pub struct ContractRes {
    pub waybill_id: String,
    pub sender: Sender,
    pub receiver: Receiver,
}