|
| 1 | +package me.chanjar.weixin.channel.api.impl; |
| 2 | + |
| 3 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.ADD_SUB_ORDER_URL; |
| 4 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.BATCH_PRINT_ORDER_URL; |
| 5 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CANCEL_ORDER_URL; |
| 6 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CREATE_ORDER_URL; |
| 7 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.CREATE_TEMPLATE_URL; |
| 8 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.DELETE_TEMPLATE_URL; |
| 9 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_ACCOUNT_URL; |
| 10 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_DELIVERY_LIST_URL; |
| 11 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_ORDER_URL; |
| 12 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_PRINT_CONTENT_URL; |
| 13 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_BY_ID_URL; |
| 14 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_CONFIG_URL; |
| 15 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.GET_TEMPLATE_URL; |
| 16 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.PRE_CREATE_ORDER_URL; |
| 17 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.PRINT_ORDER_URL; |
| 18 | +import static me.chanjar.weixin.channel.constant.WxChannelApiUrlConstants.Ewaybill.UPDATE_TEMPLATE_URL; |
| 19 | + |
| 20 | +import java.util.List; |
| 21 | +import me.chanjar.weixin.channel.api.WxChannelEwaybillService; |
| 22 | +import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse; |
| 23 | +import me.chanjar.weixin.channel.bean.ewaybill.AccountInfoResponse; |
| 24 | +import me.chanjar.weixin.channel.bean.ewaybill.AddSubOrderRequest; |
| 25 | +import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderRequest; |
| 26 | +import me.chanjar.weixin.channel.bean.ewaybill.CreateOrderResponse; |
| 27 | +import me.chanjar.weixin.channel.bean.ewaybill.DeliveryListResponse; |
| 28 | +import me.chanjar.weixin.channel.bean.ewaybill.EwaybillOrderIdParam; |
| 29 | +import me.chanjar.weixin.channel.bean.ewaybill.PrintOrderRequest; |
| 30 | +import me.chanjar.weixin.channel.bean.ewaybill.BatchPrintOrderRequest; |
| 31 | +import me.chanjar.weixin.channel.bean.ewaybill.OrderDetailResponse; |
| 32 | +import me.chanjar.weixin.channel.bean.ewaybill.PreCreateRequest; |
| 33 | +import me.chanjar.weixin.channel.bean.ewaybill.PreCreateResponse; |
| 34 | +import me.chanjar.weixin.channel.bean.ewaybill.PrintContentResponse; |
| 35 | +import me.chanjar.weixin.channel.bean.ewaybill.PrintContentParam; |
| 36 | +import me.chanjar.weixin.channel.bean.ewaybill.TemplateCodeParam; |
| 37 | +import me.chanjar.weixin.channel.bean.ewaybill.TemplateConfigResponse; |
| 38 | +import me.chanjar.weixin.channel.bean.ewaybill.TemplateCreateRequest; |
| 39 | +import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdParam; |
| 40 | +import me.chanjar.weixin.channel.bean.ewaybill.TemplateIdResponse; |
| 41 | +import me.chanjar.weixin.channel.bean.ewaybill.TemplateInfoResponse; |
| 42 | +import me.chanjar.weixin.channel.bean.ewaybill.TemplateUpdateRequest; |
| 43 | +import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdParam; |
| 44 | +import me.chanjar.weixin.channel.bean.ewaybill.WaybillIdsParam; |
| 45 | +import me.chanjar.weixin.channel.util.JsonUtils; |
| 46 | +import me.chanjar.weixin.channel.util.ResponseUtils; |
| 47 | +import me.chanjar.weixin.common.error.WxErrorException; |
| 48 | +import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; |
| 49 | + |
| 50 | +/** |
| 51 | + * 视频号小店电子面单服务实现。 |
| 52 | + * |
| 53 | + * @author GitHub Copilot |
| 54 | + */ |
| 55 | +public class WxChannelEwaybillServiceImpl implements WxChannelEwaybillService { |
| 56 | + |
| 57 | + /** 微信商店服务 */ |
| 58 | + private final BaseWxChannelServiceImpl<?, ?> shopService; |
| 59 | + |
| 60 | + public WxChannelEwaybillServiceImpl(BaseWxChannelServiceImpl<?, ?> shopService) { |
| 61 | + this.shopService = shopService; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public TemplateConfigResponse getTemplateConfig() throws WxErrorException { |
| 66 | + String resJson = post(GET_TEMPLATE_CONFIG_URL, "{}"); |
| 67 | + return ResponseUtils.decode(resJson, TemplateConfigResponse.class); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public TemplateIdResponse createTemplate(TemplateCreateRequest req) throws WxErrorException { |
| 72 | + String resJson = post(CREATE_TEMPLATE_URL, req); |
| 73 | + return ResponseUtils.decode(resJson, TemplateIdResponse.class); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public WxChannelBaseResponse deleteTemplate(String templateId) throws WxErrorException { |
| 78 | + String resJson = post(DELETE_TEMPLATE_URL, new TemplateIdParam(templateId)); |
| 79 | + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public WxChannelBaseResponse updateTemplate(TemplateUpdateRequest req) throws WxErrorException { |
| 84 | + String resJson = post(UPDATE_TEMPLATE_URL, req); |
| 85 | + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public TemplateInfoResponse getTemplate(String templateCode) throws WxErrorException { |
| 90 | + String resJson = post(GET_TEMPLATE_URL, new TemplateCodeParam(templateCode)); |
| 91 | + return ResponseUtils.decode(resJson, TemplateInfoResponse.class); |
| 92 | + } |
| 93 | + |
| 94 | + @Override |
| 95 | + public TemplateInfoResponse getTemplateById(String templateId) throws WxErrorException { |
| 96 | + String resJson = post(GET_TEMPLATE_BY_ID_URL, new TemplateIdParam(templateId)); |
| 97 | + return ResponseUtils.decode(resJson, TemplateInfoResponse.class); |
| 98 | + } |
| 99 | + |
| 100 | + @Override |
| 101 | + public AccountInfoResponse getAccount() throws WxErrorException { |
| 102 | + String resJson = post(GET_ACCOUNT_URL, "{}"); |
| 103 | + return ResponseUtils.decode(resJson, AccountInfoResponse.class); |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + public DeliveryListResponse getDeliveryList() throws WxErrorException { |
| 108 | + String resJson = post(GET_DELIVERY_LIST_URL, "{}"); |
| 109 | + return ResponseUtils.decode(resJson, DeliveryListResponse.class); |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public PreCreateResponse preCreateOrder(PreCreateRequest req) throws WxErrorException { |
| 114 | + String resJson = post(PRE_CREATE_ORDER_URL, req); |
| 115 | + return ResponseUtils.decode(resJson, PreCreateResponse.class); |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public CreateOrderResponse createOrder(CreateOrderRequest req) throws WxErrorException { |
| 120 | + String resJson = post(CREATE_ORDER_URL, req); |
| 121 | + return ResponseUtils.decode(resJson, CreateOrderResponse.class); |
| 122 | + } |
| 123 | + |
| 124 | + @Override |
| 125 | + public WxChannelBaseResponse addSubOrder(AddSubOrderRequest req) throws WxErrorException { |
| 126 | + String resJson = post(ADD_SUB_ORDER_URL, req); |
| 127 | + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); |
| 128 | + } |
| 129 | + |
| 130 | + @Override |
| 131 | + public WxChannelBaseResponse cancelOrder(PrintOrderRequest req) throws WxErrorException { |
| 132 | + String resJson = post(CANCEL_ORDER_URL, req); |
| 133 | + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public OrderDetailResponse getOrder(String ewaybillOrderId) throws WxErrorException { |
| 138 | + String resJson = post(GET_ORDER_URL, new EwaybillOrderIdParam(ewaybillOrderId)); |
| 139 | + return ResponseUtils.decode(resJson, OrderDetailResponse.class); |
| 140 | + } |
| 141 | + |
| 142 | + @Override |
| 143 | + public PrintContentResponse getPrintContent(String ewaybillOrderId, String templateId) |
| 144 | + throws WxErrorException { |
| 145 | + String resJson = post(GET_PRINT_CONTENT_URL, new PrintContentParam(ewaybillOrderId, templateId)); |
| 146 | + return ResponseUtils.decode(resJson, PrintContentResponse.class); |
| 147 | + } |
| 148 | + |
| 149 | + @Override |
| 150 | + public WxChannelBaseResponse printOrder(PrintOrderRequest req) throws WxErrorException { |
| 151 | + String resJson = post(PRINT_ORDER_URL, req); |
| 152 | + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); |
| 153 | + } |
| 154 | + |
| 155 | + @Override |
| 156 | + public WxChannelBaseResponse batchPrintOrder(BatchPrintOrderRequest req) throws WxErrorException { |
| 157 | + String resJson = post(BATCH_PRINT_ORDER_URL, req); |
| 158 | + return ResponseUtils.decode(resJson, WxChannelBaseResponse.class); |
| 159 | + } |
| 160 | + |
| 161 | + private String post(String url, Object request) throws WxErrorException { |
| 162 | + return shopService.executeWithoutLog( |
| 163 | + SimplePostRequestExecutor.create(shopService), url, JsonUtils.encode(request)); |
| 164 | + } |
| 165 | +} |
0 commit comments