This commit is contained in:
HH 2022-04-01 10:19:58 +08:00
parent c509323b3f
commit 855f141777
6 changed files with 179 additions and 5 deletions

View File

@ -1,16 +1,20 @@
package com.ghy.common.adapay;
import com.ghy.common.adapay.callback.DrawCashCallback;
import com.ghy.common.adapay.callback.PayCallback;
import com.ghy.common.adapay.callback.RefundCallback;
import com.ghy.common.adapay.callback.mapping.DrawCashMapping;
import com.ghy.common.adapay.callback.mapping.PayReplyMapping;
import com.ghy.common.adapay.callback.mapping.RefundReplyMapping;
import com.ghy.common.adapay.callback.model.Expend;
import com.ghy.common.adapay.callback.model.WxLiteExpend;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.huifu.adapay.model.Drawcash;
import com.huifu.adapay.model.Payment;
import com.huifu.adapay.model.Refund;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map;
@ -24,17 +28,51 @@ public class AdapayService {
AdapayProperties adapayProperties;
/**
* 对指定商户或者商户下用户的结算账户可用余额发起主动取现操作金额从账户中提到绑定的结算银行卡中
*
* @param callback [必填项]处理提现结果的接口
* @param orderNo [必填项]请求订单号只能为英文数字或者下划线的一种或多种组合保证在app_id下唯一
* @param cashType [必填项]取现类型T1-T+1取现D1-D+1取现D0-即时取现
* @param cashAmt [必填项]取现金额必须大于0人民币为元保留两位小数点"0.10""100.05"
* @param memberId [必填项]用户对象的member_id若是商户本身取现时请传入0
* @param remark 备注
* @param feeMode 手续费收取模式O-商户手续费账户扣取手续费I-交易金额中扣取手续费值为空时默认值为I
* @return https://docs.adapay.tech/api/wallet.html#cash-response
*/
public Map<String, Object> drawCash(DrawCashCallback callback, String orderNo, String cashType, String cashAmt,
String memberId, String remark, String feeMode) throws BaseAdaPayException {
Assert.notNull(callback, "callback is null!");
Assert.hasText(orderNo, "orderNo is blank!");
Assert.hasText(cashType, "cashType is blank!");
Assert.hasText(cashAmt, "cashAmt is blank!");
Assert.hasText(memberId, "memberId is blank!");
Map<String, Object> cashParam = new HashMap<>(5);
cashParam.put("order_no", orderNo);
cashParam.put("app_id", adapayProperties.getAppId());
cashParam.put("cash_type", cashType);
cashParam.put("cash_amt", cashAmt);
cashParam.put("member_id", memberId);
cashParam.put("notify_url", adapayProperties.getNotifyUrl());
cashParam.put("remark", remark);
cashParam.put("fee_mode", feeMode);
DrawCashMapping.putCallback(orderNo, callback);
return Drawcash.create(cashParam);
}
/**
* 支付宝正扫支付
*/
public Map<String, Object> alipayQrPay(PayCallback callback, WxLiteExpend expend, String orderNo, String payAmt, String goodsTittle, String goodsDesc, String description) throws BaseAdaPayException {
public Map<String, Object> alipayQrPay(PayCallback callback, WxLiteExpend expend, String orderNo, String payAmt,
String goodsTittle, String goodsDesc, String description) throws BaseAdaPayException {
return pay(callback, PayChannelEnum.ALIPAY_QR.getCode(), expend, orderNo, payAmt, goodsTittle, goodsDesc, description);
}
/**
* 微信小程序支付
*/
public Map<String, Object> wxLitePay(PayCallback callback, WxLiteExpend expend, String orderNo, String payAmt, String goodsTittle, String goodsDesc, String description) throws BaseAdaPayException {
public Map<String, Object> wxLitePay(PayCallback callback, WxLiteExpend expend, String orderNo, String payAmt,
String goodsTittle, String goodsDesc, String description) throws BaseAdaPayException {
return pay(callback, PayChannelEnum.WX_LITE.getCode(), expend, orderNo, payAmt, goodsTittle, goodsDesc, description);
}
@ -49,7 +87,14 @@ public class AdapayService {
* @param description 订单附加说明
* @return 同步返回一个 支付对象详见 https://docs.adapay.tech/api/trade.html#id2
*/
public Map<String, Object> pay(PayCallback callback, String payChannel, Expend expend, String orderNo, String payAmt, String goodsTittle, String goodsDesc, String description) throws BaseAdaPayException {
public Map<String, Object> pay(PayCallback callback, String payChannel, Expend expend, String orderNo, String payAmt,
String goodsTittle, String goodsDesc, String description) throws BaseAdaPayException {
Assert.notNull(callback, "callback is null!");
Assert.hasText(orderNo, "orderNo is blank!");
Assert.hasText(payAmt, "payAmt is blank!");
Assert.hasText(goodsTittle, "goodsTittle is blank!");
Assert.hasText(goodsDesc, "goodsDesc is blank!");
Assert.hasText(payChannel, "payChannel is blank!");
Map<String, Object> paymentParams = new HashMap<>(16);
paymentParams.put("app_id", adapayProperties.getAppId());
paymentParams.put("notify_url", adapayProperties.getNotifyUrl());
@ -79,6 +124,10 @@ public class AdapayService {
* @return 同步返回一个 退款对象 https://docs.adapay.tech/api/trade.html#create-refund-params
*/
public Map<String, Object> refund(RefundCallback callback, String paymentId, String refundOrderNo, String refundAmt) throws BaseAdaPayException {
Assert.notNull(callback, "callback is null!");
Assert.hasText(paymentId, "paymentId is blank!");
Assert.hasText(refundOrderNo, "refundOrderNo is blank!");
Assert.hasText(refundAmt, "refundAmt is blank!");
Map<String, Object> refundParams = new HashMap<>(4);
refundParams.put("refund_amt", refundAmt);
refundParams.put("refund_order_no", refundOrderNo);
@ -101,6 +150,7 @@ public class AdapayService {
* @return 关单的结果将通过一个 JSON 同步返回 https://docs.adapay.tech/api/trade.html#close-payment-response
*/
public Map<String, Object> close(String paymentId, String reason, String expend) throws BaseAdaPayException {
Assert.hasText(paymentId, "paymentId is blank!");
Map<String, Object> paymentParams = new HashMap<>(4);
paymentParams.put("payment_id", paymentId);
paymentParams.put("reason", reason);

View File

@ -0,0 +1,13 @@
package com.ghy.common.adapay.callback;
import com.ghy.common.adapay.callback.model.DrawCashReply;
/**
* 处理提现结果的接口
*
* @author HH 2022/4/1
*/
public interface DrawCashCallback {
void onReply(DrawCashReply reply);
}

View File

@ -0,0 +1,40 @@
package com.ghy.common.adapay.callback.mapping;
import com.alibaba.fastjson.JSON;
import com.ghy.common.adapay.callback.DrawCashCallback;
import com.ghy.common.adapay.callback.Event;
import com.ghy.common.adapay.callback.model.DrawCashReply;
import org.springframework.util.Assert;
import java.util.concurrent.ConcurrentHashMap;
/**
* 提现结果匹配
*
* @author HH 2022/4/1
*/
public class DrawCashMapping {
/**
* 临时保存支付结果
* key: orderNo
* value: 处理支付结果的回调接口
*/
private final static ConcurrentHashMap<String, DrawCashCallback> PAY_RESULT_CALLBACK_MAP = new ConcurrentHashMap<>(1024);
public static void putReply(Event event) {
String data = event.getData();
DrawCashReply reply = JSON.parseObject(data, DrawCashReply.class);
Assert.hasText(reply.getOrderNo(), "orderNo is blank !!!");
DrawCashCallback callback = PAY_RESULT_CALLBACK_MAP.remove(reply.getOrderNo());
if (callback != null) {
callback.onReply(reply);
}
}
public static void putCallback(String orderNo, DrawCashCallback callback) {
Assert.hasText(orderNo, "orderNo is blank !!!");
Assert.notNull(callback, "PayCallback is null !!!");
PAY_RESULT_CALLBACK_MAP.put(orderNo, callback);
}
}

View File

@ -9,7 +9,7 @@ import org.springframework.util.Assert;
import java.util.concurrent.ConcurrentHashMap;
/**
* 支付结果匹配
* 支付结果匹配
*
* @author HH 2022/3/25
*/

View File

@ -9,12 +9,14 @@ import org.springframework.util.Assert;
import java.util.concurrent.ConcurrentHashMap;
/**
* 退款结果匹配
*
* @author HH 2022/3/29
*/
public class RefundReplyMapping {
/**
* 临时保存支付结果
* 临时保存退款结果
* key: orderNo
* value: 处理支付结果的回调接口
*/

View File

@ -0,0 +1,69 @@
package com.ghy.common.adapay.callback.model;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
/**
* 提现后Adapay回调接口传过来的数据
*
* @author HH 2022/4/1
*/
@Data
public class DrawCashReply {
/**
* 订单号
*/
@JSONField(name = "order_no")
private String orderNo;
/**
* 控制台 主页面应用的app_id
*/
@JSONField(name = "app_id")
private String appId;
/**
* 取现金额必须大于0保留两位小数点"0.10""100.05"
*/
@JSONField(name = "cash_amt")
private String cashAmt;
/**
* 取现类型T1-T+1取现D1-D+1取现D0-即时取现
*/
@JSONField(name = "cash_type")
private String cashType;
/**
* 取现对象创建时的 10 位时间戳
*/
@JSONField(name = "created_time")
private String createdTime;
/**
* 取现手续费金额
*/
@JSONField(name = "fee_amt")
private String feeAmt;
/**
* 由Adapay生成的取现对象 id
*/
private String id;
/**
* 取现对象cash
*/
private String object;
/**
* 取现成功后的到账金额值为取现金额 - 取现手续费金额
*/
@JSONField(name = "real_amt")
private String realAmt;
/**
* 状态
* pending 交易处理中
* succeeded 交易成功
* failed 交易失败
*/
private String status;
/**
* 是否 prod模式true prod模式false mock模式
*/
@JSONField(name = "prod_mode")
private String prodMode;
}