xiaoyong931011
2022-08-26 be9208db35144a6939fa338709168cf7549e86c6
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -17,6 +17,7 @@
import cc.mrbird.febs.mall.vo.OrderDetailVo;
import cc.mrbird.febs.mall.vo.OrderListVo;
import cc.mrbird.febs.mall.vo.OrderRefundVo;
import cc.mrbird.febs.pay.model.AgreementPayDto;
import cc.mrbird.febs.pay.model.AgreementSignDto;
import cc.mrbird.febs.pay.model.UnipayDto;
import cc.mrbird.febs.pay.service.IPayService;
@@ -25,6 +26,7 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONObject;
@@ -39,6 +41,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
/**
@@ -206,18 +209,18 @@
        this.baseMapper.updateById(orderInfo);
    }
    public static void main(String[] args) {
        String unipayStr = "{\"r1_MerchantNo\":\"888118000001971\",\"rd_Pic\":\"\",\"r6_FrpCode\":\"ALIPAY_H5\",\"r7_TrxNo\":\"100222082332490699\",\"r0_Version\":\"1.0\",\"r3_Amount\":\"0.01\",\"r4_Cur\":\"1\",\"r2_OrderNo\":\"2022082212510288174\",\"rb_CodeMsg\":\"\",\"hmac\":\"1659BB77DEDDF9956EA4D6DF227C3B14\",\"ra_Code\":100,\"rc_Result\":\"<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><title></title></head><body><script type='text/javascript'>location.href='https://qr.alipay.com/bax019737vbdwoisxcdp00a2';</script></body></html>\"}";
        JSONObject jsonObject = JSONUtil.parseObj(unipayStr);
        String r7_trxNo = (String) jsonObject.get("r7_TrxNo");
        System.out.println(r7_trxNo);
    }
//    public static void main(String[] args) {
//        String unipayStr = "{\"r1_MerchantNo\":\"888118000001971\",\"rd_Pic\":\"\",\"r6_FrpCode\":\"ALIPAY_H5\",\"r7_TrxNo\":\"100222082332490699\",\"r0_Version\":\"1.0\",\"r3_Amount\":\"0.01\",\"r4_Cur\":\"1\",\"r2_OrderNo\":\"2022082212510288174\",\"rb_CodeMsg\":\"\",\"hmac\":\"1659BB77DEDDF9956EA4D6DF227C3B14\",\"ra_Code\":100,\"rc_Result\":\"<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><title></title></head><body><script type='text/javascript'>location.href='https://qr.alipay.com/bax019737vbdwoisxcdp00a2';</script></body></html>\"}";
//        JSONObject jsonObject = JSONUtil.parseObj(unipayStr);
//        String r7_trxNo = (String) jsonObject.get("r7_TrxNo");
//        System.out.println(r7_trxNo);
//    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> payOrder(PayOrderDto payOrderDto) {
        MallMember member = LoginUserUtil.getLoginUser();
        MallOrderInfo orderInfo = this.baseMapper.selectOrderByMemberIdAndId(member.getId(), payOrderDto.getId());
        MallOrderInfo orderInfo = this.baseMapper.selectOrderDetailsById(payOrderDto.getId());
        if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) {
            throw new FebsException("订单不存在");
        }
@@ -257,7 +260,7 @@
                if("fail" == unipayStr){
                    throw new FebsException("支付失败");
                }else{
                    JSONUtil.parseObj(unipayStr);
//                    JSONUtil.parseObj(unipayStr);
                    JSONObject jsonObject = JSONUtil.parseObj(unipayStr);
                    payResultStr = (String) jsonObject.get("r7_TrxNo");
                    rcResult = (String) jsonObject.get("rc_Result");
@@ -333,31 +336,54 @@
            case "5":
                AgreementSignDto agreementSignDto = new AgreementSignDto();
                agreementSignDto.setOrderNo(orderInfo.getOrderNo());
                unipayService.agreementSign(agreementSignDto);
//                UnipayDto unipayDto = new UnipayDto();
////                unipayDto.setAmount(new BigDecimal("0.01"));
//                unipayDto.setAmount(orderInfo.getAmount());
//                unipayDto.setFrpCode("ALIPAY_H5");
//                unipayDto.setTradeMerchantNo("777180800385820");
//                unipayDto.setOrderNo(orderInfo.getOrderNo());
//                List<MallOrderItem> items = orderInfo.getItems();
//                if(CollUtil.isEmpty(items)){
//                    unipayDto.setProductName("商品");
//                }else{
//                    unipayDto.setProductName(items.get(0).getGoodsName());
//                }
//                String agreementSignStr = "";
//                if("fail" == unipayStr){
//                    throw new FebsException("支付失败");
//                }else{
//                    JSONUtil.parseObj(unipayStr);
//                    JSONObject jsonObject = JSONUtil.parseObj(unipayStr);
//                    payResultStr = (String) jsonObject.get("r7_TrxNo");
//                    rcResult = (String) jsonObject.get("rc_Result");
//                }
                orderInfo.setPayOrderNo(payResultStr);
                orderInfo.setPayMethod("支付宝支付");
//                agentProducer.sendOrderReturn(orderInfo.getId());
                agreementSignDto.setSmsCode(payOrderDto.getSmsCode());
                String agreementSignStr = unipayService.agreementSign(agreementSignDto);
                if("fail".equals(agreementSignStr)){
                    throw new FebsException("支付失败");
                }else{
                    JSONObject jsonObject = JSONUtil.parseObj(agreementSignStr);
                    payResultStr = (String) jsonObject.get("biz_code");
                    String signData = (String) jsonObject.get("data");
                    String signBizMsg = (String) jsonObject.get("biz_msg");
                    JSONObject signDatajsonObject = JSONUtil.parseObj(signData);
                    String err_msg = (String) signDatajsonObject.get("err_msg");
                    if(!"JS000000".equals(payResultStr)){
                        throw new FebsException(signBizMsg);
                    }
                    if(ObjectUtil.isNotNull(signDatajsonObject.get("err_code"))){
                        throw new FebsException(err_msg);
                    }
                }
                AgreementPayDto agreementPayDto = new AgreementPayDto();
                agreementPayDto.setOrderNo(orderInfo.getOrderNo());
                BigDecimal value = orderInfo.getAmount().setScale(2, BigDecimal.ROUND_DOWN);
                DecimalFormat decimalFormat = new DecimalFormat("0.00#");
                String strVal = decimalFormat.format(value);
                agreementPayDto.setOrderAmount(new BigDecimal(strVal));
                agreementPayDto.setOrderTime(DateUtil.now());
                List<MallOrderItem> itemsGoods = orderInfo.getItems();
                if(CollUtil.isEmpty(itemsGoods)){
                    agreementPayDto.setOrderDesc("商品");
                }else{
                    agreementPayDto.setOrderDesc(itemsGoods.get(0).getGoodsName());
                }
                agreementPayDto.setBankNo(payOrderDto.getBankNo());
                String agreementPayStr = unipayService.agreementPay(agreementPayDto);
                if("fail".equals(agreementSignStr)){
                    throw new FebsException("支付失败");
                }else{
                    JSONObject jsonObject = JSONUtil.parseObj(agreementPayStr);
                    payResultStr = (String) jsonObject.get("biz_code");
                    String payBizMsg = (String) jsonObject.get("biz_msg");
                    if(!"JS000000".equals(payResultStr)){
                        throw new FebsException(payBizMsg);
                    }
                }
                orderInfo.setPayMethod("快捷协议支付");
                break;
            default:
@@ -373,6 +399,21 @@
        return map;
    }
    public static void main(String[] args) {
        String str = "{\"biz_code\":\"JS000000\",\"biz_msg\":\"成功\",\"data\":\"{\\\"order_status\\\":\\\"P2000\\\",\\\"jp_order_no\\\":\\\"100120220826446740396081496064\\\",\\\"err_msg\\\":\\\"短信验证码不符\\\",\\\"err_code\\\":\\\"CP110026\\\",\\\"sign_no\\\":\\\"\\\",\\\"mch_order_no\\\":\\\"NO_2022082618263952399\\\"}\",\"mch_no\":\"888118000001971\",\"rand_str\":\"an2w7ulf5ru6upkk5bdg441kdi3gnpvu\",\"resp_code\":\"SUCCESS\",\"sec_key\":\"\",\"sign\":\"NiJXRTSIZ9xZMUOwEHiEHdZXmgL2cHUU5WUa1NbMRRzui0DIiuZSW4e31LjnBxwVwmy3uuPMP+tqhY8VLyC8uCFOdGdZI7e72VuRvyvaiW7/sqCrsfgPOBEjiGE/CmSMRoEXv9HmqCyNBF6iHSEhQJql5Yge30dQdyB6xFfqjk0=\",\"sign_type\":\"2\"}";
        JSONObject jsonObject = JSONUtil.parseObj(str);
        String payResultStr = (String) jsonObject.get("biz_code");
        String signBizMsg = (String) jsonObject.get("biz_msg");
        String signData = (String) jsonObject.get("data");
        JSONObject signDatajsonObject = JSONUtil.parseObj(signData);
        String err_msg = (String) signDatajsonObject.get("err_msg");
        if(ObjectUtil.isNotNull(signDatajsonObject.get("err_code"))){
            System.out.println(err_msg);
        }
    }
    private String balancePay(MallOrderInfo orderInfo, String tradePwd, String field) {
        if (StrUtil.isBlank(tradePwd)) {
            throw new FebsException("支付密码错误");