1
1
package cn .binarywang .wx .miniapp .api .impl ;
2
2
3
- import static cn .binarywang .wx .miniapp .constant .WxMaApiUrlConstants .Shop .Order .ORDER_ADD ;
4
- import static cn .binarywang .wx .miniapp .constant .WxMaApiUrlConstants .Shop .Order .ORDER_CHECK_SCENE ;
5
- import static cn .binarywang .wx .miniapp .constant .WxMaApiUrlConstants .Shop .Order .ORDER_GET ;
6
- import static cn .binarywang .wx .miniapp .constant .WxMaApiUrlConstants .Shop .Order .ORDER_PAY ;
7
-
8
3
import cn .binarywang .wx .miniapp .api .WxMaService ;
9
4
import cn .binarywang .wx .miniapp .api .WxMaShopOrderService ;
10
5
import cn .binarywang .wx .miniapp .bean .shop .WxMaShopOrderInfo ;
11
6
import cn .binarywang .wx .miniapp .bean .shop .request .WxMaShopOrderPayRequest ;
12
- import cn .binarywang .wx .miniapp .bean .shop .response .WxMaShopAddOrderResponse ;
13
- import cn .binarywang .wx .miniapp .bean .shop .response .WxMaShopBaseResponse ;
14
- import cn .binarywang .wx .miniapp .bean .shop .response .WxMaShopGetOrderResponse ;
7
+ import cn .binarywang .wx .miniapp .bean .shop .response .*;
15
8
import cn .binarywang .wx .miniapp .json .WxMaGsonBuilder ;
16
9
import com .google .gson .JsonObject ;
17
10
import lombok .RequiredArgsConstructor ;
21
14
import me .chanjar .weixin .common .error .WxErrorException ;
22
15
import me .chanjar .weixin .common .util .json .GsonHelper ;
23
16
import me .chanjar .weixin .common .util .json .GsonParser ;
17
+ import org .apache .commons .lang3 .time .FastDateFormat ;
18
+
19
+ import java .text .Format ;
20
+ import java .util .Date ;
21
+
22
+ import static cn .binarywang .wx .miniapp .constant .WxMaApiUrlConstants .Shop .Order .*;
24
23
25
24
/**
26
25
* @author boris
27
26
*/
28
27
@ RequiredArgsConstructor
29
28
@ Slf4j
30
29
public class WxMaShopOrderServiceImpl implements WxMaShopOrderService {
30
+
31
+ private final Format dateFormat = FastDateFormat .getInstance ("yyyy-MM-dd HH:mm:ss" );
32
+
31
33
private static final String ERR_CODE = "errcode" ;
32
34
private static final String MATCH_KEY = "is_matched" ;
33
35
private final WxMaService wxMaService ;
@@ -45,34 +47,49 @@ public Boolean checkScene(Integer scene) throws WxErrorException {
45
47
46
48
@ Override
47
49
public WxMaShopAddOrderResponse addOrder (WxMaShopOrderInfo orderInfo ) throws WxErrorException {
48
- String responseContent = this .wxMaService .post (ORDER_ADD , orderInfo );
49
- JsonObject jsonObject = GsonParser .parse (responseContent );
50
- if (jsonObject .get (ERR_CODE ).getAsInt () != 0 ) {
51
- throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
52
- }
53
- return WxMaGsonBuilder .create ().fromJson (responseContent , WxMaShopAddOrderResponse .class );
50
+ return this .post (ORDER_ADD ,orderInfo , WxMaShopAddOrderResponse .class );
54
51
}
55
52
56
53
@ Override
57
54
public WxMaShopBaseResponse orderPay (WxMaShopOrderPayRequest request ) throws WxErrorException {
58
- String responseContent = this .wxMaService .post (ORDER_PAY , request );
59
- JsonObject jsonObject = GsonParser .parse (responseContent );
60
- if (jsonObject .get (ERR_CODE ).getAsInt () != 0 ) {
61
- throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
55
+ return this .post (ORDER_PAY ,request , WxMaShopBaseResponse .class );
56
+ }
57
+
58
+ @ Override
59
+ public WxMaShopGetOrderResponse getOrder (Integer orderId , String outOrderId , String openid ) throws WxErrorException {
60
+ return this .post (ORDER_GET , GsonHelper .buildJsonObject ("order_id" , orderId , "out_order_id" , outOrderId ,
61
+ "openid" , openid ), WxMaShopGetOrderResponse .class );
62
+ }
63
+
64
+ @ Override
65
+ public WxMaShopGetOrderListResponse getOrderList (Integer page , Integer pageSize , Boolean desc , Date startCreateTime , Date endCreateTime ) throws WxErrorException {
66
+ JsonObject object = new JsonObject ();
67
+ object .addProperty ("page" , page == null ? 1 : page );
68
+ object .addProperty ("page_size" , pageSize == null ? 10 : pageSize );
69
+ object .addProperty ("desc" , desc ? 1 : 2 );
70
+ if (startCreateTime != null ) {
71
+ object .addProperty ("start_create_time" , this .dateFormat .format (startCreateTime ));
72
+ }
73
+ if (endCreateTime != null ) {
74
+ object .addProperty ("end_create_time" , this .dateFormat .format (endCreateTime ));
62
75
}
63
- return WxMaGsonBuilder . create (). fromJson ( responseContent , WxMaShopBaseResponse .class );
76
+ return this . post ( ORDER_GET_LIST , object , WxMaShopGetOrderListResponse .class );
64
77
}
65
78
66
79
@ Override
67
- public WxMaShopGetOrderResponse getOrder (Integer orderId , String outOrderId , String openid )
68
- throws WxErrorException {
69
- String responseContent = this .wx
10000
MaService .post (ORDER_GET ,
80
+ public WxMaShopGetPaymentParamsResponse getPaymentParams (String orderId , String outOrderId , String openid ) throws WxErrorException {
81
+ return this .post (ORDER_GET_PAYMENT_PARAMS ,
70
82
GsonHelper .buildJsonObject ("order_id" , orderId , "out_order_id" , outOrderId ,
71
- "openid" , openid ));
83
+ "openid" , openid ), WxMaShopGetPaymentParamsResponse .class );
84
+ }
85
+
86
+
87
+ private <T > T post (String url , Object params , Class <T > classOfT ) throws WxErrorException {
88
+ String responseContent = this .wxMaService .post (url , params );
72
89
JsonObject jsonObject = GsonParser .parse (responseContent );
73
90
if (jsonObject .get (ERR_CODE ).getAsInt () != 0 ) {
74
91
throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
75
92
}
76
- return WxMaGsonBuilder .create ().fromJson (responseContent , WxMaShopGetOrderResponse . class );
93
+ return WxMaGsonBuilder .create ().fromJson (responseContent , classOfT );
77
94
}
78
95
}
0 commit comments