use of com.xatu.gmall.entity.PaymentInfo in project GMall by 18391713434.
the class PaymentController method aliPayCallBackReturn.
@RequestMapping("alipay/callback/return")
@LoginRequired(loginSuccess = true)
public String aliPayCallBackReturn(HttpServletRequest request, ModelMap modelMap) {
// 回到请求中获取支付宝的参数
String sign = request.getParameter("sign");
// 支付宝交易号
String trade_no = request.getParameter("trade_no");
String out_trade_no = request.getParameter("out_trade_no");
String trade_status = request.getParameter("trade_status");
String totalAmount = request.getParameter("totalAmount");
String subject = request.getParameter("subject");
// 回跳内容
String call_back_content = request.getQueryString();
// 通过支付宝的paramMap进行签名验证,(2.0版本的接口将paramMap参数去掉了,导致同步请求没法验签)
if (StringUtils.isNotBlank(sign)) {
// 验签成功
PaymentInfo paymentInfo = new PaymentInfo();
// 支付宝交易凭证号
paymentInfo.setOrderSn(out_trade_no);
paymentInfo.setPaymentStatus("已支付");
// 回调请求字符串
paymentInfo.setCallbackContent(call_back_content);
paymentInfo.setCallbackTime(new Date());
paymentService.updatePaymentInfo(paymentInfo);
// 支付成功后,引起的系统服务,订单服务的更新 --》库存服务 --》物流服务
// 更新用户的支付数据
}
return "finish";
}
use of com.xatu.gmall.entity.PaymentInfo in project GMall by 18391713434.
the class PaymentController method alipay.
@RequestMapping("/alipay/submit")
@LoginRequired(loginSuccess = true)
@ResponseBody
public String alipay(String outTradeNo, BigDecimal totalAmount, HttpServletRequest request, ModelMap modelMap) {
String form = null;
AlipayTradePayRequest alipayTradePayRequest = new AlipayTradePayRequest();
// 回调函数地址
alipayTradePayRequest.setReturnUrl(AlipayConfig.return_payment_url);
alipayTradePayRequest.setNotifyUrl(AlipayConfig.notify_payment_url);
Map<String, Object> map = new HashMap<>();
map.put("out_trade_no", outTradeNo);
map.put("product_code", "FAST_INSTANT_TRADB_PAY");
map.put("total_amount", totalAmount);
map.put("subject", "华为p40徕卡八摄影");
String mapJSONStr = JSON.toJSONString(map);
alipayTradePayRequest.setBizContent(mapJSONStr);
// 获得一个支付宝请求客户端(它并不是一个连接,而是一个封装号的http的表单请求)
try {
form = alipayClient.pageExecute(alipayTradePayRequest).getBody();
} catch (AlipayApiException e) {
e.printStackTrace();
}
// 生成并保存用户的支付信息
OmsOrder omsOrder = orderService.getOrderByOutTradeNo(outTradeNo);
PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setCreateTime(new Date());
paymentInfo.setOrderId(omsOrder.getId().toString());
paymentInfo.setPaymentStatus("未付款");
paymentInfo.setSubject("GMALL商城商品一件");
paymentInfo.setTotalAmount(totalAmount);
paymentService.savePaymentInfo(paymentInfo);
// 向消息中间件发送一个检查支付状态(支付服务消费)的延迟消息队列
paymentService.sendDelayPaymentCheckQueue(outTradeNo, 5);
return form;
}
use of com.xatu.gmall.entity.PaymentInfo in project GMall by 18391713434.
the class PaymentServiceImpl method updatePaymentInfo.
@Override
public void updatePaymentInfo(PaymentInfo paymentInfo) {
// 进行幂等性检查
PaymentInfo paymentInfoResult = paymentMapper.selectOne(new QueryWrapper<PaymentInfo>().eq("alipay_trade_no", paymentInfo.getOrderSn()));
if (StringUtils.isNotBlank(paymentInfoResult.getPaymentStatus()) && paymentInfoResult.getPaymentStatus().equals("已支付")) {
return;
} else {
Connection connection = null;
Session session = null;
try {
connection = activeMQUtil.getConnectionFactory().createConnection();
session = connection.createSession(true, Session.SESSION_TRANSACTED);
} catch (Exception e) {
e.printStackTrace();
}
try {
paymentMapper.update(paymentInfo, new UpdateWrapper<PaymentInfo>().eq("order_sn", paymentInfo.getOrderSn()));
// 支付成功后,引起的系统服务,订单服务的更新 --》库存服务 --》物流服务
// 调用mq发送支付成功的消息
Queue payment_success_quene = session.createQueue("PAYMENT_SUCCESS_QUENE");
MessageProducer producer = session.createProducer(payment_success_quene);
// 字符串文本
TextMessage textMessage = new ActiveMQTextMessage();
// hash结构
MapMessage mapMessage = new ActiveMQMapMessage();
mapMessage.setString("out_trade_no", paymentInfo.getOrderSn());
session.commit();
} catch (Exception e) {
// 消息回滚
try {
session.rollback();
} catch (Exception e1) {
e1.printStackTrace();
}
} finally {
try {
connection.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
}
}
Aggregations