zhuyifan

fix

package com.infoloop.tianting.model.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import io.swagger.annotations.ApiModel;
import javax.print.DocFlavor.STRING;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.context.annotation.Primary;
@Data
@ApiModel(description = "支付DTO")
......@@ -32,6 +33,7 @@ public class PayDTO {
@ApiModel(description = "支付通知结果dto")
@NoArgsConstructor
@AllArgsConstructor
@JacksonXmlRootElement(localName = "miniPayRequest")
public static class MiniPayRequest {
private String timeStamp;
@JsonProperty("package")
......@@ -48,8 +50,15 @@ public class PayDTO {
@NoArgsConstructor
@AllArgsConstructor
public static class PayResult{
private Boolean TransSN;
@JacksonXmlProperty(localName = "TransSN")
private String TransSN;
@JacksonXmlProperty(localName = "MsgId")
private String MsgId;
@JacksonXmlProperty(localName = "tradeId")
private String tradeId;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JacksonXmlProperty(localName = "miniPayRequest")
private MiniPayRequest miniPayRequest;
}
......@@ -58,9 +67,13 @@ public class PayDTO {
@ApiModel(description = "支付通知响应dto")
@NoArgsConstructor
@AllArgsConstructor
@JacksonXmlRootElement(localName = "JSONObject")
public static class PayResponseDto {
@JacksonXmlProperty(localName = "success")
private Boolean success;
@JacksonXmlProperty(localName = "error")
private String error;
@JacksonXmlProperty(localName = "result")
private PayResult result;
}
......
......@@ -389,7 +389,7 @@ public class OrderServiceRpcClient {
public QueryClientCustomerOrdersByPaginationRpcResponse queryClientCustomerOrdersByPagination(
QueryOrderByPaginationDto queryOrderDto) {
final var request = QueryClientCustomerOrdersByPaginationRpcRequest.newBuilder()
.setKeyword(queryOrderDto.getKeyword())
.setKeyword(queryOrderDto.getKeyword() == null ? "" : queryOrderDto.getKeyword())
.setPageNo(queryOrderDto.getPn())
.setPageSize(queryOrderDto.getPz())
.setStatus(queryOrderDto.getStatus())
......
......@@ -3,6 +3,7 @@ package com.infoloop.tianting.service.client;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.infoloop.tianting.config.BusinessConfig;
import com.infoloop.tianting.model.dto.PayDTO.PayInformRequestDto;
import com.infoloop.tianting.model.dto.PayDTO.PayResponseDto;
......@@ -39,6 +40,8 @@ public class PayServiceClient {
@Value("${payment.client-id:Order0001}")
private String clientId;
private final XmlMapper xmlMapper = new XmlMapper();
public PayResponseDto payInform(PayInformRequestDto payRequestDto) {
String url = businessConfig.getPayUrl();
String requestDate = DateUtil.formatDate(LocalDateTime.now(), DateUtil.YMDHMS);
......@@ -53,7 +56,7 @@ public class PayServiceClient {
}
HttpEntity<String> requestEntity = new HttpEntity<>(jsonDataString, createHeaders());
log.info("payInform request: {}", jsonDataString);
ResponseEntity<PayResponseDto> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, PayResponseDto.class);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
return processResponse(responseEntity);
}
......@@ -79,13 +82,19 @@ public class PayServiceClient {
return headers;
}
private PayResponseDto processResponse(ResponseEntity<PayResponseDto> responseEntity) {
private PayResponseDto processResponse(ResponseEntity<String> responseEntity) {
if (!responseEntity.getStatusCode().is2xxSuccessful() || responseEntity.getBody() == null) {
log.error("payInform failed with response: {}", responseEntity.getBody());
throw new IllegalArgumentException("支付通知失败");
}
log.info("payInform response: {}", responseEntity.getBody());
return responseEntity.getBody();
try {
PayResponseDto responseDto = xmlMapper.readValue(responseEntity.getBody(), PayResponseDto.class);
log.info("payInform response: {}", responseDto);
return responseDto;
} catch (Exception e) {
log.error("Failed to parse XML response", e);
throw new RuntimeException("XML 解析失败", e);
}
}
public void callback(PaymentCallbackDTO payInformRequestDto) {
......