Search in sources :

Example 1 with PaymentInfo

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";
}
Also used : PaymentInfo(com.xatu.gmall.entity.PaymentInfo) Date(java.util.Date) LoginRequired(com.xatu.gmall.annotations.LoginRequired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PaymentInfo

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;
}
Also used : PaymentInfo(com.xatu.gmall.entity.PaymentInfo) HashMap(java.util.HashMap) OmsOrder(com.xatu.gmall.entity.OmsOrder) AlipayApiException(com.alipay.api.AlipayApiException) AlipayTradePayRequest(com.alipay.api.request.AlipayTradePayRequest) Date(java.util.Date) LoginRequired(com.xatu.gmall.annotations.LoginRequired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with PaymentInfo

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();
            }
        }
    }
}
Also used : PaymentInfo(com.xatu.gmall.entity.PaymentInfo) ActiveMQMapMessage(org.apache.activemq.command.ActiveMQMapMessage) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ActiveMQMapMessage(org.apache.activemq.command.ActiveMQMapMessage) AlipayApiException(com.alipay.api.AlipayApiException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Aggregations

PaymentInfo (com.xatu.gmall.entity.PaymentInfo)3 AlipayApiException (com.alipay.api.AlipayApiException)2 LoginRequired (com.xatu.gmall.annotations.LoginRequired)2 Date (java.util.Date)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AlipayTradePayRequest (com.alipay.api.request.AlipayTradePayRequest)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)1 OmsOrder (com.xatu.gmall.entity.OmsOrder)1 HashMap (java.util.HashMap)1 ActiveMQMapMessage (org.apache.activemq.command.ActiveMQMapMessage)1 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1