package com.iplatform.pay.support; import com.iplatform.base.PlatformRuntimeException; import com.iplatform.model.po.S_pay_notify; import com.iplatform.model.po.S_pay_order; import com.iplatform.pay.service.PlatformOrderServiceImpl; import com.iplatform.pay.util.NotifyUtils; import com.iplatform.pay.util.OrderUtils; import com.walker.infrastructure.utils.JsonUtils; import com.walker.pay.NotifyValue; import com.walker.pay.Order; import com.walker.pay.PayStatus; import com.walker.pay.response.ScanOrderResponsePay; import com.walker.pay.support.DefaultOrder; import com.walker.pay.wechat.v2.AppOrderResponsePay; import com.walker.pay.wechat.v2.H5ResponsePay; import com.walker.pay.wechat.v2.NotifyOrder; import com.walker.pay.wechat.v2.WechatV2OrderCallback; /** * 微信v2版本支付订单回调实现。

* 注意:该对象设计不合理,不应该在底层包实现AbstractOrderCallback,后续应该直接在平台继承该对象,不能放到类库中,不利于复用。

* 正确方法参考: {@linkplain AllinpayCloudOrderCallback} * @author 时克英 * @date 2023-03-01 */ public class DefaultWechatV2OrderCallback extends WechatV2OrderCallback { @Override protected void doPrepareOrder(Order platformOrder, AppOrderResponsePay responsePay){ logger.info("默认实现: 执行保存'AppOrderResponsePay'订单操作,order={}", platformOrder); try { String payInfo = JsonUtils.objectToJsonString(responsePay.getAppOrderInfo()); this.savePayOrderPersistent(platformOrder, payInfo); } catch (Exception e) { throw new RuntimeException("保存'微信v2-App'订单错误,无法转成json:" + responsePay.getAppOrderInfo(), e); } } @Override protected void doPrepareOrder(Order platformOrder, ScanOrderResponsePay responsePay){ logger.info("默认实现: 执行保存'ScanOrderResponsePay'订单操作,order={}", platformOrder); this.savePayOrderPersistent(platformOrder, responsePay.getCodeUrl()); } @Override protected void doPrepareOrder(Order platformOrder, H5ResponsePay responsePay){ logger.info("默认实现: 执行保存'H5ResponsePay'订单操作,order={}", platformOrder); try { this.savePayOrderPersistent(platformOrder, JsonUtils.objectToJsonString(responsePay)); } catch (Exception e) { throw new PlatformRuntimeException("H5ResponsePay --> Json 错误:" + e.getMessage(), e); } } @Override protected void doNotifyOrderPay(NotifyValue notifyValue){ logger.info("默认实现: 接收支付通知,notifyValue={}", notifyValue); long orderId = Long.parseLong(notifyValue.getOrderId()); S_pay_notify exist = this.orderService.get(new S_pay_notify(orderId)); if(exist != null && exist.getPay_status().equals(PayStatus.Success.getIndex())){ logger.warn("订单通知已经接收,而且支付成功,不再重复处理,notifyId = {}, orderId = {}", notifyValue.getId(), orderId); 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); } logger.debug("------> 保存新订单通知, orderId = " + orderId); } protected S_pay_notify acquirePayNotify(NotifyValue notifyValue){ S_pay_notify s_pay_notify = NotifyUtils.acquireCombineBaseNotify(notifyValue); if(!notifyValue.isStatus()){ // 通知支付失败 s_pay_notify.setPay_status(PayStatus.Error.getIndex()); } else { s_pay_notify.setPay_status(PayStatus.Success.getIndex()); } NotifyOrder notifyOrder = notifyValue.getData(); if(notifyOrder != null){ s_pay_notify.setNotify_status("暂未获取"); s_pay_notify.setNotify_amount(notifyOrder.getTotalMoney()); s_pay_notify.setNotify_acct(notifyOrder.getOpenId()); try { s_pay_notify.setNotify_source(JsonUtils.objectToJsonString(notifyOrder)); } catch (Exception e) { logger.error("NotifyOrder转json错误:" + e.getMessage(), e); } } return s_pay_notify; } protected void savePayOrderPersistent(Order platformOrder, String thirdPayInfo){ S_pay_order s_pay_order = OrderUtils.acquireDefaultOrder(0 , (DefaultOrder) platformOrder, platformOrder.getTradeNo(), thirdPayInfo); this.orderService.insert(s_pay_order); } public void setOrderService(PlatformOrderServiceImpl orderService) { this.orderService = orderService; } private PlatformOrderServiceImpl orderService; }