电脑网站支付成功后可通过支付宝接口主动查询订单结果
更多精彩
- 更多技术博客,请移步 asing1elife's blog
前置条件
- 该方法基于 Java 支付宝扫码支付 (新) 实现
调用查询接口进行订单查询
public class AliQueryServiceImpl extends AliCoreServiceImpl {
public Boolean getPayResult(Long orderId) {
AlipayTradeQueryRequest queryRequest = new AlipayTradeQueryRequest();
queryRequest.setBizModel(generateOrderInfo(orderId));
AlipayTradeQueryResponse response = null;
try {
response = alipayClient.execute(queryRequest);
} catch (AlipayApiException e) {
logger.error("支付宝查询订单" + orderId + "失败!", e);
}
if (response == null) {
logger.error("支付宝未获取订单" + orderId + "详情!");
return false;
}
if (response.isSuccess()) {
if (response.getTradeStatus().equals(TRADE_STATUS_SUCCESS) || response.getTradeStatus().equals(TRADE_STATUS_FINISHED)) {
// 更新订单状态
updateOrderInfo(response.getOutTradeNo(), OrderPay.aliPay.getCode());
return true;
}
logger.error("支付宝订单" + orderId + "交易失败,交易状态:" + response.getTradeStatus());
return false;
} else {
logger.error("支付宝订单" + orderId + "查询失败!");
return false;
}
}
private AlipayTradeQueryModel generateOrderInfo(Long orderId) {
OrderDTO order = orderManageService.getOrder(orderId);
AlipayTradeQueryModel model = new AlipayTradeQueryModel();
model.setOutTradeNo(order.getCode());
return model;
}
}
网友评论