Showing
3 changed files
with
30 additions
and
8 deletions
| 1 | package com.infoloop.tianting.model.dto; | 1 | package com.infoloop.tianting.model.dto; |
| 2 | 2 | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; | ||
| 3 | import com.fasterxml.jackson.annotation.JsonProperty; | 4 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 5 | +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
| 6 | +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
| 4 | import io.swagger.annotations.ApiModel; | 7 | import io.swagger.annotations.ApiModel; |
| 5 | -import javax.print.DocFlavor.STRING; | ||
| 6 | import lombok.AllArgsConstructor; | 8 | import lombok.AllArgsConstructor; |
| 7 | import lombok.Builder; | 9 | import lombok.Builder; |
| 8 | import lombok.Data; | 10 | import lombok.Data; |
| 9 | import lombok.NoArgsConstructor; | 11 | import lombok.NoArgsConstructor; |
| 10 | -import org.springframework.context.annotation.Primary; | ||
| 11 | 12 | ||
| 12 | @Data | 13 | @Data |
| 13 | @ApiModel(description = "支付DTO") | 14 | @ApiModel(description = "支付DTO") |
| ... | @@ -32,6 +33,7 @@ public class PayDTO { | ... | @@ -32,6 +33,7 @@ public class PayDTO { |
| 32 | @ApiModel(description = "支付通知结果dto") | 33 | @ApiModel(description = "支付通知结果dto") |
| 33 | @NoArgsConstructor | 34 | @NoArgsConstructor |
| 34 | @AllArgsConstructor | 35 | @AllArgsConstructor |
| 36 | + @JacksonXmlRootElement(localName = "miniPayRequest") | ||
| 35 | public static class MiniPayRequest { | 37 | public static class MiniPayRequest { |
| 36 | private String timeStamp; | 38 | private String timeStamp; |
| 37 | @JsonProperty("package") | 39 | @JsonProperty("package") |
| ... | @@ -48,8 +50,15 @@ public class PayDTO { | ... | @@ -48,8 +50,15 @@ public class PayDTO { |
| 48 | @NoArgsConstructor | 50 | @NoArgsConstructor |
| 49 | @AllArgsConstructor | 51 | @AllArgsConstructor |
| 50 | public static class PayResult{ | 52 | public static class PayResult{ |
| 51 | - private Boolean TransSN; | 53 | + @JacksonXmlProperty(localName = "TransSN") |
| 54 | + private String TransSN; | ||
| 55 | + @JacksonXmlProperty(localName = "MsgId") | ||
| 52 | private String MsgId; | 56 | private String MsgId; |
| 57 | + @JacksonXmlProperty(localName = "tradeId") | ||
| 58 | + private String tradeId; | ||
| 59 | + | ||
| 60 | + @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| 61 | + @JacksonXmlProperty(localName = "miniPayRequest") | ||
| 53 | private MiniPayRequest miniPayRequest; | 62 | private MiniPayRequest miniPayRequest; |
| 54 | } | 63 | } |
| 55 | 64 | ||
| ... | @@ -58,9 +67,13 @@ public class PayDTO { | ... | @@ -58,9 +67,13 @@ public class PayDTO { |
| 58 | @ApiModel(description = "支付通知响应dto") | 67 | @ApiModel(description = "支付通知响应dto") |
| 59 | @NoArgsConstructor | 68 | @NoArgsConstructor |
| 60 | @AllArgsConstructor | 69 | @AllArgsConstructor |
| 70 | + @JacksonXmlRootElement(localName = "JSONObject") | ||
| 61 | public static class PayResponseDto { | 71 | public static class PayResponseDto { |
| 72 | + @JacksonXmlProperty(localName = "success") | ||
| 62 | private Boolean success; | 73 | private Boolean success; |
| 74 | + @JacksonXmlProperty(localName = "error") | ||
| 63 | private String error; | 75 | private String error; |
| 76 | + @JacksonXmlProperty(localName = "result") | ||
| 64 | private PayResult result; | 77 | private PayResult result; |
| 65 | } | 78 | } |
| 66 | 79 | ... | ... |
| ... | @@ -389,7 +389,7 @@ public class OrderServiceRpcClient { | ... | @@ -389,7 +389,7 @@ public class OrderServiceRpcClient { |
| 389 | public QueryClientCustomerOrdersByPaginationRpcResponse queryClientCustomerOrdersByPagination( | 389 | public QueryClientCustomerOrdersByPaginationRpcResponse queryClientCustomerOrdersByPagination( |
| 390 | QueryOrderByPaginationDto queryOrderDto) { | 390 | QueryOrderByPaginationDto queryOrderDto) { |
| 391 | final var request = QueryClientCustomerOrdersByPaginationRpcRequest.newBuilder() | 391 | final var request = QueryClientCustomerOrdersByPaginationRpcRequest.newBuilder() |
| 392 | - .setKeyword(queryOrderDto.getKeyword()) | 392 | + .setKeyword(queryOrderDto.getKeyword() == null ? "" : queryOrderDto.getKeyword()) |
| 393 | .setPageNo(queryOrderDto.getPn()) | 393 | .setPageNo(queryOrderDto.getPn()) |
| 394 | .setPageSize(queryOrderDto.getPz()) | 394 | .setPageSize(queryOrderDto.getPz()) |
| 395 | .setStatus(queryOrderDto.getStatus()) | 395 | .setStatus(queryOrderDto.getStatus()) | ... | ... |
| ... | @@ -3,6 +3,7 @@ package com.infoloop.tianting.service.client; | ... | @@ -3,6 +3,7 @@ package com.infoloop.tianting.service.client; |
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | 3 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 4 | import com.fasterxml.jackson.databind.ObjectMapper; | 4 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 5 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | 5 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; |
| 6 | +import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
| 6 | import com.infoloop.tianting.config.BusinessConfig; | 7 | import com.infoloop.tianting.config.BusinessConfig; |
| 7 | import com.infoloop.tianting.model.dto.PayDTO.PayInformRequestDto; | 8 | import com.infoloop.tianting.model.dto.PayDTO.PayInformRequestDto; |
| 8 | import com.infoloop.tianting.model.dto.PayDTO.PayResponseDto; | 9 | import com.infoloop.tianting.model.dto.PayDTO.PayResponseDto; |
| ... | @@ -39,6 +40,8 @@ public class PayServiceClient { | ... | @@ -39,6 +40,8 @@ public class PayServiceClient { |
| 39 | @Value("${payment.client-id:Order0001}") | 40 | @Value("${payment.client-id:Order0001}") |
| 40 | private String clientId; | 41 | private String clientId; |
| 41 | 42 | ||
| 43 | + private final XmlMapper xmlMapper = new XmlMapper(); | ||
| 44 | + | ||
| 42 | public PayResponseDto payInform(PayInformRequestDto payRequestDto) { | 45 | public PayResponseDto payInform(PayInformRequestDto payRequestDto) { |
| 43 | String url = businessConfig.getPayUrl(); | 46 | String url = businessConfig.getPayUrl(); |
| 44 | String requestDate = DateUtil.formatDate(LocalDateTime.now(), DateUtil.YMDHMS); | 47 | String requestDate = DateUtil.formatDate(LocalDateTime.now(), DateUtil.YMDHMS); |
| ... | @@ -53,7 +56,7 @@ public class PayServiceClient { | ... | @@ -53,7 +56,7 @@ public class PayServiceClient { |
| 53 | } | 56 | } |
| 54 | HttpEntity<String> requestEntity = new HttpEntity<>(jsonDataString, createHeaders()); | 57 | HttpEntity<String> requestEntity = new HttpEntity<>(jsonDataString, createHeaders()); |
| 55 | log.info("payInform request: {}", jsonDataString); | 58 | log.info("payInform request: {}", jsonDataString); |
| 56 | - ResponseEntity<PayResponseDto> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, PayResponseDto.class); | 59 | + ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); |
| 57 | return processResponse(responseEntity); | 60 | return processResponse(responseEntity); |
| 58 | } | 61 | } |
| 59 | 62 | ||
| ... | @@ -79,13 +82,19 @@ public class PayServiceClient { | ... | @@ -79,13 +82,19 @@ public class PayServiceClient { |
| 79 | return headers; | 82 | return headers; |
| 80 | } | 83 | } |
| 81 | 84 | ||
| 82 | - private PayResponseDto processResponse(ResponseEntity<PayResponseDto> responseEntity) { | 85 | + private PayResponseDto processResponse(ResponseEntity<String> responseEntity) { |
| 83 | if (!responseEntity.getStatusCode().is2xxSuccessful() || responseEntity.getBody() == null) { | 86 | if (!responseEntity.getStatusCode().is2xxSuccessful() || responseEntity.getBody() == null) { |
| 84 | log.error("payInform failed with response: {}", responseEntity.getBody()); | 87 | log.error("payInform failed with response: {}", responseEntity.getBody()); |
| 85 | throw new IllegalArgumentException("支付通知失败"); | 88 | throw new IllegalArgumentException("支付通知失败"); |
| 86 | } | 89 | } |
| 87 | - log.info("payInform response: {}", responseEntity.getBody()); | 90 | + try { |
| 88 | - return responseEntity.getBody(); | 91 | + PayResponseDto responseDto = xmlMapper.readValue(responseEntity.getBody(), PayResponseDto.class); |
| 92 | + log.info("payInform response: {}", responseDto); | ||
| 93 | + return responseDto; | ||
| 94 | + } catch (Exception e) { | ||
| 95 | + log.error("Failed to parse XML response", e); | ||
| 96 | + throw new RuntimeException("XML 解析失败", e); | ||
| 97 | + } | ||
| 89 | } | 98 | } |
| 90 | 99 | ||
| 91 | public void callback(PaymentCallbackDTO payInformRequestDto) { | 100 | public void callback(PaymentCallbackDTO payInformRequestDto) { | ... | ... |
-
Please register or login to post a comment