package com.iplatform.pay.support;
|
|
import com.iplatform.model.po.S_pay_notify;
|
import com.iplatform.model.po.S_pay_order;
|
import com.iplatform.pay.PlatformOrderCallback;
|
import com.iplatform.pay.util.NotifyUtils;
|
import com.iplatform.pay.util.OrderUtils;
|
import com.walker.infrastructure.utils.JsonUtils;
|
import com.walker.infrastructure.utils.StringUtils;
|
import com.walker.pay.CallBackException;
|
import com.walker.pay.NotifyValue;
|
import com.walker.pay.Order;
|
import com.walker.pay.PayStatus;
|
import com.walker.pay.ResponsePay;
|
import com.walker.pay.allinpaycloud.Constants;
|
import com.walker.pay.allinpaycloud.NotifyOrder;
|
import com.walker.pay.allinpaycloud.generator.OrderResponsePay;
|
import com.walker.pay.support.BankCardOrder;
|
import com.walker.pay.support.allinpaycloud.WechatJsOrder;
|
import com.walker.pay.support.allinpaycloud.WechatMiniProgramOrder;
|
|
/**
|
* 通商云订单回调业务实现。
|
* @author 时克英
|
* @date 2023-02-26
|
*/
|
public class AllinpayCloudOrderCallback extends PlatformOrderCallback {
|
|
@Override
|
public void onOrderPrepare(Order platformOrder, ResponsePay responsePay) {
|
OrderResponsePay orderResponsePay = (OrderResponsePay) responsePay;
|
logger.debug("保存'通商云订单':{}", orderResponsePay);
|
|
S_pay_order s_pay_order = null;
|
//
|
// String tradeNo = orderResponsePay.getTradeNo();
|
String tradeNo = orderResponsePay.getOrderNo();
|
String thirdPayInfo = orderResponsePay.getPayInfo();
|
/**
|
* {
|
* "orderNo":"1632077606083895296",
|
* "tradeNo":"{\"sign\":\"\",\"tphtrxcrtime\":\"\",\"tphtrxid\":0,\"trxflag\":\"trx\",\"trxsn\":\"\"}",
|
* "validationType":1,
|
* "extendInfo":"test",
|
* "bizUserId":"shikeying",
|
* "bizOrderNo":"8400705969744373"}
|
* 返回的通联订单号不是'tradeNo',而是'orderNo'
|
*/
|
if(platformOrder instanceof BankCardOrder){
|
BankCardOrder bankCardOrder = (BankCardOrder) platformOrder;
|
// s_pay_order = OrderUtils.acquireBankCardOrder(0, bankCardOrder, orderResponsePay);
|
s_pay_order = OrderUtils.acquireBankCardOrder(0, bankCardOrder, tradeNo, thirdPayInfo);
|
} else if(platformOrder instanceof WechatJsOrder){
|
WechatJsOrder wechatJsOrder = (WechatJsOrder) platformOrder;
|
s_pay_order = OrderUtils.acquireWechatJsOrder(0, wechatJsOrder, tradeNo, thirdPayInfo);
|
} else if(platformOrder instanceof WechatMiniProgramOrder){
|
WechatMiniProgramOrder wechatMiniProgramOrder = (WechatMiniProgramOrder) platformOrder;
|
s_pay_order = OrderUtils.acquireWechatJsOrder(0, wechatMiniProgramOrder, tradeNo, thirdPayInfo);
|
} else {
|
throw new UnsupportedOperationException("未实现保存该类型订单代码: " + platformOrder.getClass().getName());
|
}
|
this.orderService.insert(s_pay_order);
|
}
|
|
@Override
|
public void onOrderNotify(NotifyValue<?> notifyValue) throws CallBackException {
|
if(!(notifyValue.getData() instanceof NotifyOrder)){
|
throw new IllegalArgumentException("notifyValue.getData()必须是 NotifyOrder 对象!");
|
}
|
this.doNotifyOrderPay((NotifyValue<NotifyOrder>)notifyValue);
|
}
|
|
protected void doNotifyOrderPay(NotifyValue<NotifyOrder> notifyValue){
|
// logger.info("默认实现: 接收支付通知,notifyValue={}", notifyValue);
|
if(StringUtils.isEmpty(notifyValue.getOrderId())){
|
throw new IllegalArgumentException("接收订单通知,系统订单'orderId'为空");
|
}
|
long orderId = Long.parseLong(notifyValue.getOrderId());
|
// S_pay_notify exist = this.orderService.get(new S_pay_notify(orderId));
|
// if(exist != null){
|
// logger.warn("订单通知已经接收,不再重复处理,notifyId = {}", notifyValue.getId());
|
// return;
|
// }
|
S_pay_notify exist = this.getExistNotifyRecord(orderId);
|
if(this.isAlreadySuccessNotify(exist)){
|
return;
|
}
|
S_pay_notify s_pay_notify = this.acquirePayNotify(notifyValue);
|
if(exist != null){
|
// 更新通知,更新订单状态
|
this.orderService.execInsertOrderNotify(s_pay_notify, false);
|
} else {
|
// 写入通知,更新订单状态
|
this.orderService.execInsertOrderNotify(s_pay_notify, true);
|
}
|
// this.orderService.execInsertOrderNotify(s_pay_notify);
|
logger.debug("------> 保存新订单通知, orderId = " + orderId);
|
}
|
|
private S_pay_notify acquirePayNotify(NotifyValue<NotifyOrder> notifyValue){
|
// S_pay_notify s_pay_notify = new S_pay_notify();
|
// s_pay_notify.setOrder_id(Long.parseLong(notifyValue.getOrderId()));
|
// s_pay_notify.setNotify_id(notifyValue.getId());
|
// s_pay_notify.setCreate_time(DateUtils.getDateTimeNumber(System.currentTimeMillis()));
|
// s_pay_notify.setNotify_type(notifyValue.getDataType());
|
// s_pay_notify.setTrade_no(notifyValue.getTradeNo());
|
|
S_pay_notify s_pay_notify = NotifyUtils.acquireCombineBaseNotify(notifyValue);
|
|
NotifyOrder notifyOrder = notifyValue.getData();
|
if(notifyOrder != null){
|
if(notifyOrder.getStatus().equals(Constants.SUB_CODE_OK)){
|
s_pay_notify.setPay_status(PayStatus.Success.getIndex());
|
} else {
|
s_pay_notify.setPay_status(PayStatus.Error.getIndex());
|
}
|
s_pay_notify.setNotify_status(notifyOrder.getStatus());
|
s_pay_notify.setNotify_amount(notifyOrder.getAmount());
|
s_pay_notify.setNotify_acct(notifyOrder.getAcct());
|
|
try {
|
s_pay_notify.setNotify_source(JsonUtils.objectToJsonString(notifyOrder));
|
} catch (Exception e) {
|
logger.error("NotifyOrder转json错误:" + e.getMessage(), e);
|
}
|
}
|
return s_pay_notify;
|
}
|
|
// public void setOrderService(OrderServiceImpl orderService) {
|
// this.orderService = orderService;
|
// }
|
// private OrderServiceImpl orderService;
|
}
|