⚡ 包装查询结果, 简化信息
This commit is contained in:
@@ -15,9 +15,9 @@ import com.alipay.api.request.AlipayTradeRefundRequest;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import com.alipay.api.response.AlipayTradeAppPayResponse;
|
||||
import com.alipay.api.response.AlipayTradePayResponse;
|
||||
import com.alipay.api.response.AlipayTradeQueryResponse;
|
||||
import com.alipay.api.response.AlipayTradeRefundResponse;
|
||||
import com.alipay.api.response.AlipayTradeWapPayResponse;
|
||||
import com.hccake.starte.pay.ali.domain.AliPayQuery;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import lombok.Data;
|
||||
@@ -286,7 +286,7 @@ public class AliPay {
|
||||
* @return com.alipay.api.response.AlipayTradeQueryResponse
|
||||
* @author lingting 2021-01-25 11:12
|
||||
*/
|
||||
public AlipayTradeQueryResponse query(String sn) throws AlipayApiException {
|
||||
public AliPayQuery query(String sn) throws AlipayApiException {
|
||||
return query(sn, null);
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ public class AliPay {
|
||||
* @return com.alipay.api.response.AlipayTradeQueryResponse
|
||||
* @author lingting 2021-01-25 11:12
|
||||
*/
|
||||
public AlipayTradeQueryResponse query(String sn, String tradeNo) throws AlipayApiException {
|
||||
public AliPayQuery query(String sn, String tradeNo) throws AlipayApiException {
|
||||
AlipayTradeQueryModel model = new AlipayTradeQueryModel();
|
||||
model.setOutTradeNo(sn);
|
||||
model.setTradeNo(tradeNo);
|
||||
@@ -309,10 +309,10 @@ public class AliPay {
|
||||
* @return com.alipay.api.response.AlipayTradeQueryResponse
|
||||
* @author lingting 2021-01-25 11:12
|
||||
*/
|
||||
public AlipayTradeQueryResponse query(AlipayTradeQueryModel model) throws AlipayApiException {
|
||||
public AliPayQuery query(AlipayTradeQueryModel model) throws AlipayApiException {
|
||||
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
||||
request.setBizModel(model);
|
||||
return client.execute(request);
|
||||
return AliPayQuery.of(client.execute(request));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,4 +22,9 @@ public class AliPayConstant {
|
||||
*/
|
||||
public static final String SERVER_URL_DEV = "https://openapi.alipaydev.com/gateway.do";
|
||||
|
||||
/**
|
||||
* 查询支付成功返回code
|
||||
*/
|
||||
public static final String CODE_SUCCESS = "10000";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.hccake.starte.pay.ali.domain;
|
||||
|
||||
import static com.hccake.starte.pay.ali.constants.AliPayConstant.CODE_SUCCESS;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alipay.api.response.AlipayTradeQueryResponse;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 简化查询结果
|
||||
*
|
||||
* @author lingting 2021/1/26 10:34
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Setter(AccessLevel.PRIVATE)
|
||||
public class AliPayQuery {
|
||||
|
||||
public static AliPayQuery of(AlipayTradeQueryResponse raw) {
|
||||
AliPayQuery query = new AliPayQuery();
|
||||
if (raw == null) {
|
||||
return query;
|
||||
}
|
||||
// 状态处理
|
||||
if (CODE_SUCCESS.equals(raw.getCode())) {
|
||||
// 成功
|
||||
query.setStatus(Status.of(raw.getTradeStatus()));
|
||||
}
|
||||
// 异常
|
||||
else {
|
||||
query.setStatus(Status.ERROR);
|
||||
}
|
||||
|
||||
// 金额
|
||||
if (StrUtil.isBlank(raw.getTotalAmount())) {
|
||||
query.setAmount(BigDecimal.ZERO);
|
||||
}
|
||||
else {
|
||||
query.setAmount(new BigDecimal(raw.getTotalAmount()));
|
||||
}
|
||||
|
||||
// 信息
|
||||
query.setCode(raw.getCode()).setMsg(raw.getMsg()).setSubCode(raw.getSubCode()).setSubMsg(raw.getSubMsg());
|
||||
|
||||
// 基础数据
|
||||
return query.setTradeNo(raw.getTradeNo()).setSn(raw.getOutTradeNo()).setId(raw.getBuyerLogonId())
|
||||
.setUserId(raw.getBuyerUserId()).setUserName(raw.getBuyerUserName())
|
||||
.setUserType(raw.getBuyerUserType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 原始数据
|
||||
*/
|
||||
private AlipayTradeQueryResponse raw;
|
||||
|
||||
/**
|
||||
* 订单状态
|
||||
*/
|
||||
private Status status;
|
||||
|
||||
private String code;
|
||||
|
||||
private String msg;
|
||||
|
||||
private String subCode;
|
||||
|
||||
private String subMsg;
|
||||
|
||||
/**
|
||||
* 金额(单位: 元)
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 平台订单号
|
||||
*/
|
||||
private String sn;
|
||||
|
||||
/**
|
||||
* 支付宝订单号
|
||||
*/
|
||||
private String tradeNo;
|
||||
|
||||
/**
|
||||
* 支付用户支付宝账号信息
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 支付用户id
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 交易状态
|
||||
*/
|
||||
public enum Status {
|
||||
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
SUCCESS,
|
||||
/**
|
||||
* 未支付
|
||||
*/
|
||||
WAIT,
|
||||
/**
|
||||
* 未付款交易超时关闭,或支付完成后全额退款
|
||||
*/
|
||||
CLOSED,
|
||||
/**
|
||||
* 交易结束,不可退款
|
||||
*/
|
||||
FINISHED,
|
||||
/**
|
||||
* 异常. 具体信息查询 subCode和subMsg
|
||||
*/
|
||||
ERROR,
|
||||
|
||||
;
|
||||
|
||||
public static Status of(String status) {
|
||||
switch (status) {
|
||||
case "WAIT_BUYER_PAY":
|
||||
return WAIT;
|
||||
case "TRADE_CLOSED":
|
||||
return CLOSED;
|
||||
case "TRADE_SUCCESS":
|
||||
return SUCCESS;
|
||||
case "TRADE_FINISHED":
|
||||
return FINISHED;
|
||||
default:
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user