|
@@ -10,7 +10,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.llisoft.common.exception.MtaException;
|
|
|
import com.llisoft.common.util.CodeUtil;
|
|
|
+import com.llisoft.common.util.HttpUtil;
|
|
|
+import com.llisoft.common.util.JsonUtil;
|
|
|
import com.llisoft.pay.dao.ItemDao;
|
|
|
+import com.llisoft.pay.dao.OrderDao;
|
|
|
import com.llisoft.pay.entity.Item;
|
|
|
import com.llisoft.pay.entity.Order;
|
|
|
|
|
@@ -42,9 +45,13 @@ public class PayService {
|
|
|
@Autowired
|
|
|
private ItemDao payDao;
|
|
|
@Autowired
|
|
|
- private OrderService orderService;
|
|
|
+ private OrderDao orderDao;
|
|
|
@Autowired
|
|
|
private AliPayService aliPayService;
|
|
|
+ @Autowired
|
|
|
+ private WxPayService wxPayService;
|
|
|
+ @Autowired
|
|
|
+ private AppService appService;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -91,13 +98,12 @@ public class PayService {
|
|
|
if (Objects.isNull(item)) {
|
|
|
throw new MtaException("支付记录不存在: " + payNum);
|
|
|
}
|
|
|
- Order order = orderService.get(item.getOrderId());
|
|
|
+ Order order = orderDao.select(item.getOrderId());
|
|
|
if (item.getPayType() == TYPE_ALI) { // 支付宝
|
|
|
return isMobile ? aliPayService.paym(payNum, order.getOrderMoney(), order.getOrderTitle()) :
|
|
|
aliPayService.pay(payNum, order.getOrderMoney(), order.getOrderTitle());
|
|
|
}else if (item.getPayType() == TYPE_WX) { // 微信
|
|
|
- return isMobile ? aliPayService.paym(payNum, order.getOrderMoney(), order.getOrderTitle()) :
|
|
|
- aliPayService.pay(payNum, order.getOrderMoney(), order.getOrderTitle());
|
|
|
+ return wxPayService.pay(payNum, order.getOrderMoney(), order.getOrderTitle());
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -115,15 +121,24 @@ public class PayService {
|
|
|
@Transactional
|
|
|
public boolean finish(String payNum, String tradeNum, int money, byte flag) throws Exception{
|
|
|
Item item = this.get(payNum);
|
|
|
- Order order = orderService.get(item.getOrderId());
|
|
|
+ Order order = orderDao.select(item.getOrderId());
|
|
|
if (order.getOrderMoney() != money) { // 核对金额
|
|
|
throw new MtaException("支付金额异常: " + money);
|
|
|
}
|
|
|
// 更新支付状态
|
|
|
payDao.updatePay(item.getPayId(), tradeNum, STATUS_PAYED, flag);
|
|
|
logger.info("支付处理成功, 状态更新为已支付: {}", payNum);
|
|
|
- // 更新订单
|
|
|
- return orderService.finish(item.getOrderId());
|
|
|
+ // 更新订单状态
|
|
|
+ orderDao.updatePay(order.getOrderId(), STATUS_PAYED);
|
|
|
+ // 发送支付成功异步通知
|
|
|
+ String notifyUrl = appService.getNotifyUrl(order.getAppId(), order.getOrderNum());
|
|
|
+ if(Objects.nonNull(notifyUrl)) {
|
|
|
+ logger.info("订单完成: 异步通知业务地址: {}, 参数: {}", notifyUrl, JsonUtil.toJson(order));
|
|
|
+ String result = HttpUtil.postJson(notifyUrl, JsonUtil.toJson(order));
|
|
|
+ logger.info("订单完成: 业务端返回信息: {}", result);
|
|
|
+ return "success".equals(result);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|