⚡ 简化支付宝回调类. 添加验签方法
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
package com.hccake.starte.pay.ali.domain;
|
package com.hccake.starte.pay.ali.domain;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
||||||
import com.hccake.ballcat.common.util.JsonUtils;
|
import com.hccake.ballcat.common.util.JsonUtils;
|
||||||
|
import com.hccake.starte.pay.ali.AliPay;
|
||||||
import com.hccake.starte.pay.ali.enums.TradeStatus;
|
import com.hccake.starte.pay.ali.enums.TradeStatus;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -9,12 +12,16 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lingting 2021/1/26 13:31
|
* @author lingting 2021/1/26 13:31
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor
|
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
|
||||||
public class AliPayCallback {
|
public class AliPayCallback {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,82 +36,65 @@ public class AliPayCallback {
|
|||||||
map.put("fund_bill_list", JsonUtils.toObj(fundBillListStr, List.class));
|
map.put("fund_bill_list", JsonUtils.toObj(fundBillListStr, List.class));
|
||||||
// 覆盖原值
|
// 覆盖原值
|
||||||
callbackParams.put("fund_bill_list", fundBillListStr);
|
callbackParams.put("fund_bill_list", fundBillListStr);
|
||||||
return JsonUtils.toObj(JsonUtils.toJson(map), AliPayCallback.class);
|
return JsonUtils.toObj(JsonUtils.toJson(map), AliPayCallback.class).setRaw(callbackParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty("gmt_create")
|
@SneakyThrows
|
||||||
|
public boolean checkSign(AliPay aliPay) {
|
||||||
|
return aliPay.checkSignV1(getRaw()) || aliPay.checkSignV2(getRaw());
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private Map<String, String> raw;
|
||||||
|
|
||||||
private String gmtCreate;
|
private String gmtCreate;
|
||||||
|
|
||||||
@JsonProperty("charset")
|
|
||||||
private String charset;
|
private String charset;
|
||||||
|
|
||||||
@JsonProperty("seller_email")
|
|
||||||
private String sellerEmail;
|
private String sellerEmail;
|
||||||
|
|
||||||
@JsonProperty("subject")
|
|
||||||
private String subject;
|
private String subject;
|
||||||
|
|
||||||
@JsonProperty("sign")
|
|
||||||
private String sign;
|
private String sign;
|
||||||
|
|
||||||
@JsonProperty("buyer_id")
|
|
||||||
private String buyerId;
|
private String buyerId;
|
||||||
|
|
||||||
@JsonProperty("invoice_amount")
|
|
||||||
private BigDecimal invoiceAmount;
|
private BigDecimal invoiceAmount;
|
||||||
|
|
||||||
@JsonProperty("notify_id")
|
|
||||||
private String notifyId;
|
private String notifyId;
|
||||||
|
|
||||||
@JsonProperty("fund_bill_list")
|
|
||||||
private List<FundBill> fundBillList;
|
private List<FundBill> fundBillList;
|
||||||
|
|
||||||
@JsonProperty("notify_type")
|
|
||||||
private String notifyType;
|
private String notifyType;
|
||||||
|
|
||||||
@JsonProperty("trade_status")
|
|
||||||
private TradeStatus tradeStatus;
|
private TradeStatus tradeStatus;
|
||||||
|
|
||||||
@JsonProperty("receipt_amount")
|
|
||||||
private BigDecimal receiptAmount;
|
private BigDecimal receiptAmount;
|
||||||
|
|
||||||
@JsonProperty("app_id")
|
|
||||||
private String appId;
|
private String appId;
|
||||||
|
|
||||||
@JsonProperty("buyer_pay_amount")
|
|
||||||
private BigDecimal buyerPayAmount;
|
private BigDecimal buyerPayAmount;
|
||||||
|
|
||||||
@JsonProperty("sign_type")
|
|
||||||
private String signType;
|
private String signType;
|
||||||
|
|
||||||
@JsonProperty("seller_id")
|
|
||||||
private String sellerId;
|
private String sellerId;
|
||||||
|
|
||||||
@JsonProperty("gmt_payment")
|
|
||||||
private String gmtPayment;
|
private String gmtPayment;
|
||||||
|
|
||||||
@JsonProperty("notify_time")
|
|
||||||
private String notifyTime;
|
private String notifyTime;
|
||||||
|
|
||||||
@JsonProperty("version")
|
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
@JsonProperty("out_trade_no")
|
|
||||||
private String outTradeNo;
|
private String outTradeNo;
|
||||||
|
|
||||||
@JsonProperty("total_amount")
|
|
||||||
private BigDecimal totalAmount;
|
private BigDecimal totalAmount;
|
||||||
|
|
||||||
@JsonProperty("trade_no")
|
|
||||||
private String tradeNo;
|
private String tradeNo;
|
||||||
|
|
||||||
@JsonProperty("auth_app_id")
|
|
||||||
private String authAppId;
|
private String authAppId;
|
||||||
|
|
||||||
@JsonProperty("buyer_logon_id")
|
|
||||||
private String buyerLogonId;
|
private String buyerLogonId;
|
||||||
|
|
||||||
@JsonProperty("point_amount")
|
|
||||||
private BigDecimal pointAmount;
|
private BigDecimal pointAmount;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -4,12 +4,16 @@ import cn.hutool.core.lang.Snowflake;
|
|||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.hccake.starte.pay.ali.AliPay;
|
import com.hccake.starte.pay.ali.AliPay;
|
||||||
import com.hccake.starte.pay.ali.domain.AliPayCallback;
|
import com.hccake.starte.pay.ali.domain.AliPayCallback;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lingting 2021/1/25 15:18
|
* @author lingting 2021/1/25 15:18
|
||||||
@@ -21,8 +25,6 @@ public class AliController {
|
|||||||
|
|
||||||
private final AliPay aliPay;
|
private final AliPay aliPay;
|
||||||
|
|
||||||
BigDecimal amount = new BigDecimal("100");
|
|
||||||
|
|
||||||
BigDecimal zero = new BigDecimal("0.01");
|
BigDecimal zero = new BigDecimal("0.01");
|
||||||
|
|
||||||
private static final Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
private static final Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
||||||
@@ -33,10 +35,13 @@ public class AliController {
|
|||||||
* @return java.lang.String
|
* @return java.lang.String
|
||||||
* @author lingting 2021-01-26 15:18
|
* @author lingting 2021-01-26 15:18
|
||||||
*/
|
*/
|
||||||
|
@SneakyThrows
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public String notice(HttpServletRequest request, @RequestParam Map<String, String> callback) {
|
public String notice(HttpServletRequest request, @RequestParam Map<String, String> callback) {
|
||||||
System.out.println("notice");
|
System.out.println("notice");
|
||||||
AliPayCallback of = AliPayCallback.of(callback);
|
AliPayCallback of = AliPayCallback.of(callback);
|
||||||
|
System.out.println(of.checkSign(aliPay));
|
||||||
|
aliPay.checkSignV1(of.getRaw());
|
||||||
return "success";
|
return "success";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user