浏览代码

fix:“优化汇付微信扫码支付"

soobin 8 月之前
父节点
当前提交
2d24f36db3

+ 110 - 108
src/main/java/com/szwl/controller/TOrderController.java

@@ -49,6 +49,7 @@ import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -345,7 +346,6 @@ public class TOrderController {
         orderDetails.setCompanyType(companyType);
         orderDetails.setMachineType(equipment.getMachineType());
 
-//        String client6 = clientId.substring(clientId.length() - 6);
         String productName1 = productName + "-" + equipment.getName() + "-" + client6;
         String result = null;
         if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
@@ -353,22 +353,29 @@ public class TOrderController {
             order.setAcctSplitBunch(acctSplitBunch.toString());
             if (frpCode.equals("WEIXIN_NATIVE")) {
                 //添加到汇付临时表
-                THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
-                String[] ignoreProperties = {"id"};
-                String id = HuifuUtils.inithuifuTempId();
-                tHuifuTempOrder.setId(id);
-                BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
-                huifuTempOrderService.save(tHuifuTempOrder);
+//                THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
+//                String[] ignoreProperties = {"id"};
+//                String id = HuifuUtils.inithuifuTempId();
+//                tHuifuTempOrder.setId(id);
+//                BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
+//                huifuTempOrderService.save(tHuifuTempOrder);
+//                if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+//                    result = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+//                } else {
+//                    result = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+//                }
+//                log.info("返回链接:{}", result);
                 if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-                    result = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+                    result = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn;
                 } else {
-                    result = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+                    result = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn;
                 }
-                log.info("返回链接:{}", result);
                 String qrcode = toQrcode(result);
                 JSONObject kindData = new JSONObject();
                 kindData.put("sn", sn);
                 kindData.put("rd_Pic", qrcode);
+                orderService.save(order);
+                orderDetailsService.save(orderDetails);
                 return JsonMessage.success(kindData.toString());
             }
             // 汇付支付
@@ -951,18 +958,30 @@ public class TOrderController {
             order.setAcctSplitBunch(acctSplitBunch.toString());
             order2.setAcctSplitBunch(acctSplitBunch.toString());
             //添加到汇付临时表,微信
-            THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
-            String[] ignoreProperties = {"id"};
-            String id = HuifuUtils.inithuifuTempId();
-            tHuifuTempOrder.setId(id);
-            BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
-            huifuTempOrderService.save(tHuifuTempOrder);
+//            THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
+//            String[] ignoreProperties = {"id"};
+//            String id = HuifuUtils.inithuifuTempId();
+//            tHuifuTempOrder.setId(id);
+//            BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
+//            huifuTempOrderService.save(tHuifuTempOrder);
+//            if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+//                result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+//            } else {
+//                result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+//            }
             String result1 = "";
             if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-                result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+                result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
             } else {
-                result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+                result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
             }
+            // URL编码
+            try {
+                result1 = URLEncoder.encode(result1, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+
             // 支付宝
             try {
                 result = huifuMchService.uniPay(
@@ -978,10 +997,15 @@ public class TOrderController {
             }
             // 汇聚支付支付申请返回支付二维码图片
             String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
+            System.out.println(code1);
             String qrcode = toQrcode(code1);
             JSONObject kindData = new JSONObject();
             kindData.put("sn", sn1 + "-" + sn2);
             kindData.put("rd_Pic", qrcode);
+            orderService.save(order);
+            orderDetails.setOrderSn(sn1);
+            orderDetails.setId(HuifuUtils.initDetailsId());
+            orderDetailsService.save(orderDetails);
             orderDetails.setOrderSn(sn2);
             orderDetails.setId(HuifuUtils.initDetailsId());
             orderDetailsService.save(orderDetails);
@@ -1405,8 +1429,6 @@ public class TOrderController {
         orderDetails.setCompanyType(companyType);
         orderDetails.setRefundStatus("0");
         orderDetails.setMachineType(equipment.getMachineType());
-
-//        String client6 = clientId.substring(clientId.length() - 6);
         String productName1 = "";
         if (productNumber > 1) {
             if (equipment.getMachineType() == null || equipment.getMachineType().equals("0")) {
@@ -1435,17 +1457,27 @@ public class TOrderController {
             order.setAcctSplitBunch(acctSplitBunch.toString());
             order2.setAcctSplitBunch(acctSplitBunch.toString());
             //添加到汇付临时表,微信
-            THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
-            String[] ignoreProperties = {"id"};
-            String id = HuifuUtils.inithuifuTempId();
-            tHuifuTempOrder.setId(id);
-            BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
-            huifuTempOrderService.save(tHuifuTempOrder);
+//            THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
+//            String[] ignoreProperties = {"id"};
+//            String id = HuifuUtils.inithuifuTempId();
+//            tHuifuTempOrder.setId(id);
+//            BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
+//            huifuTempOrderService.save(tHuifuTempOrder);
+//            if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+//                result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+//            } else {
+//                result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+//            }
             String result1 = "";
             if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-                result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+                result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
             } else {
-                result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+                result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
+            }
+            try {
+                result1 = URLEncoder.encode(result1, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
             }
             // 支付宝
             try {
@@ -1466,18 +1498,6 @@ public class TOrderController {
             JSONObject kindData = new JSONObject();
             kindData.put("sn", sn1 + "-" + sn2);
             kindData.put("rd_Pic", qrcode);
-//            for (String key : productMap.keySet()) {
-//                Integer productNum = productMap.get(key);
-//                TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), key));
-//                orderDetails.setId(HuifuUtils.initDetailsId());
-//                orderDetails.setProductNo(product.getNo());
-//                orderDetails.setProductName(key);
-//                orderDetails.setPrice(product.getRmbPrice());
-//                orderDetails.setProductNumber(productNum);
-//                orderDetails.setAmount(product.getRmbPrice().multiply(new BigDecimal(productNum)));
-//                orderDetails.setOrderSn(sn2);
-//                orderDetailsService.save(orderDetails);
-//            }
             for (String key : map.keySet()) {
                 // key:"玫瑰精灵-A01",value:"0.50-1"
                 String value = map.get(key);
@@ -1489,9 +1509,14 @@ public class TOrderController {
                 orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
                 orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
                 orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
+                orderDetails.setId(HuifuUtils.initDetailsId());
+                orderDetails.setOrderSn(sn1);
+                orderDetailsService.save(orderDetails);
+                orderDetails.setId(HuifuUtils.initDetailsId());
                 orderDetails.setOrderSn(sn2);
                 orderDetailsService.save(orderDetails);
             }
+            orderService.save(order);
             orderService.save(order2);
             return JsonMessage.success(kindData.toString());
         } else {
@@ -1530,22 +1555,6 @@ public class TOrderController {
             JSONObject kindData = new JSONObject();
             kindData.put("sn", sn1 + "-" + sn2);
             kindData.put("rd_Pic", rd_Pic);
-            // 添加到订单明细表
-//            for (String key : productMap.keySet()) {
-//                Integer productNum = productMap.get(key);
-//                TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), key));
-//                orderDetails.setProductNo(product.getNo());
-//                orderDetails.setProductName(key);
-//                orderDetails.setPrice(product.getRmbPrice());
-//                orderDetails.setProductNumber(productNum);
-//                orderDetails.setAmount(product.getRmbPrice().multiply(new BigDecimal(productNum)));
-//                orderDetails.setId(HuifuUtils.initDetailsId());
-//                orderDetails.setOrderSn(sn1);
-//                orderDetailsService.save(orderDetails);
-//                orderDetails.setId(HuifuUtils.initDetailsId());
-//                orderDetails.setOrderSn(sn2);
-//                orderDetailsService.save(orderDetails);
-//            }
             for (String key : map.keySet()) {
                 // key:"玫瑰精灵-A01",value:"0.50-1"
                 String value = map.get(key);
@@ -2306,17 +2315,27 @@ public class TOrderController {
             order.setAcctSplitBunch(acctSplitBunch.toString());
             order2.setAcctSplitBunch(acctSplitBunch.toString());
             //添加到汇付临时表,微信
-            THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
-            String[] ignoreProperties = {"id"};
-            String id = HuifuUtils.inithuifuTempId();
-            tHuifuTempOrder.setId(id);
-            BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
-            huifuTempOrderService.save(tHuifuTempOrder);
+//            THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
+//            String[] ignoreProperties = {"id"};
+//            String id = HuifuUtils.inithuifuTempId();
+//            tHuifuTempOrder.setId(id);
+//            BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
+//            huifuTempOrderService.save(tHuifuTempOrder);
+//            if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+//                result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+//            } else {
+//                result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+//            }
             String result1 = "";
             if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-                result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+                result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
             } else {
-                result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+                result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
+            }
+            try {
+                result1 = URLEncoder.encode(result1, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
             }
             // 支付宝
             try {
@@ -2337,6 +2356,10 @@ public class TOrderController {
             JSONObject kindData = new JSONObject();
             kindData.put("sn", sn1 + "-" + sn2);
             kindData.put("rd_Pic", qrcode);
+            orderService.save(order);
+            orderDetails.setOrderSn(sn1);
+            orderDetails.setId(HuifuUtils.initDetailsId());
+            orderDetailsService.save(orderDetails);
             orderDetails.setOrderSn(sn2);
             orderDetails.setId(HuifuUtils.initDetailsId());
             orderDetailsService.save(orderDetails);
@@ -2796,13 +2819,7 @@ public class TOrderController {
         orderDetails.setRefundStatus("0");
         orderDetails.setMachineType(equipment.getMachineType());
 
-//        String client6 = clientId.substring(clientId.length() - 6);
         String productName1 = "雪糕x" + productNumber + "-" + equipment.getName() + "-" + client6;
-//        if(productNumber > 1) {
-//            productName1 = "雪糕-" + equipment.getName() + "-" + client6;
-//        } else {
-//            productName1 = productName + "-" + equipment.getName() + "-" + client6;
-//        }
 
         Map<String, String> map = new HashMap<>();
         String[] products = order.getNote().split(",");
@@ -2821,17 +2838,27 @@ public class TOrderController {
             order.setAcctSplitBunch(acctSplitBunch.toString());
             order2.setAcctSplitBunch(acctSplitBunch.toString());
             //添加到汇付临时表,微信
-            THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
-            String[] ignoreProperties = {"id"};
-            String id = HuifuUtils.inithuifuTempId();
-            tHuifuTempOrder.setId(id);
-            BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
-            huifuTempOrderService.save(tHuifuTempOrder);
+//            THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
+//            String[] ignoreProperties = {"id"};
+//            String id = HuifuUtils.inithuifuTempId();
+//            tHuifuTempOrder.setId(id);
+//            BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
+//            huifuTempOrderService.save(tHuifuTempOrder);
+//            if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
+//                result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+//            } else {
+//                result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+//            }
             String result1 = "";
             if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-                result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
+                result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
             } else {
-                result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
+                result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
+            }
+            try {
+                result1 = URLEncoder.encode(result1, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
             }
             // 支付宝
             try {
@@ -2852,21 +2879,7 @@ public class TOrderController {
             JSONObject kindData = new JSONObject();
             kindData.put("sn", sn1 + "-" + sn2);
             kindData.put("rd_Pic", qrcode);
-//            for (String key : productMap.keySet()) {
-//                Integer productNum = productMap.get(key);
-//                String[] split = key.split("-");
-//                BigDecimal unitPrice = new BigDecimal(split[1]);
-//                orderDetails.setId(HuifuUtils.initDetailsId());
-//                orderDetails.setProductNo(productNo);
-//                orderDetails.setProductName(split[0]);
-//                orderDetails.setPrice(unitPrice);
-//                orderDetails.setProductNumber(productNum);
-//                orderDetails.setAmount(unitPrice.multiply(new BigDecimal(productNum)));
-//                orderDetails.setOrderSn(sn2);
-//                orderDetailsService.save(orderDetails);
-//            }
             for (String key : map.keySet()) {
-                // key:"玫瑰精灵-A01",value:"0.50-1"
                 String value = map.get(key);
                 String[] GoodsInfo = key.split("-");
                 String[] GoodsValue = value.split("-");
@@ -2876,9 +2889,14 @@ public class TOrderController {
                 orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
                 orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
                 orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
+                orderDetails.setId(HuifuUtils.initDetailsId());
+                orderDetails.setOrderSn(sn1);
+                orderDetailsService.save(orderDetails);
+                orderDetails.setId(HuifuUtils.initDetailsId());
                 orderDetails.setOrderSn(sn2);
                 orderDetailsService.save(orderDetails);
             }
+            orderService.save(order);
             orderService.save(order2);
             return JsonMessage.success(kindData.toString());
         } else {
@@ -2918,22 +2936,6 @@ public class TOrderController {
             kindData.put("sn", sn1 + "-" + sn2);
             kindData.put("rd_Pic", rd_Pic);
             // 添加到订单明细表
-//            for (String key : productMap.keySet()) {
-//                Integer productNum = productMap.get(key);
-//                String[] split = key.split("-");
-//                BigDecimal unitPrice = new BigDecimal(split[1]);
-//                orderDetails.setProductNo(productNo);
-//                orderDetails.setProductName(split[0]);
-//                orderDetails.setPrice(unitPrice);
-//                orderDetails.setProductNumber(productNum);
-//                orderDetails.setAmount(unitPrice.multiply(new BigDecimal(productNum)));
-//                orderDetails.setId(HuifuUtils.initDetailsId());
-//                orderDetails.setOrderSn(sn1);
-//                orderDetailsService.save(orderDetails);
-//                orderDetails.setId(HuifuUtils.initDetailsId());
-//                orderDetails.setOrderSn(sn2);
-//                orderDetailsService.save(orderDetails);
-//            }
             for (String key : map.keySet()) {
                 // key:"玫瑰精灵-A01",value:"0.50-1"
                 String value = map.get(key);

+ 0 - 42
src/main/java/com/szwl/controller/WechatPayInfoController.java

@@ -1,42 +0,0 @@
-package com.szwl.controller;
-
-
-import com.szwl.constant.ResponseCodesEnum;
-import com.szwl.model.bo.R;
-import com.szwl.model.bo.ResponseModel;
-import com.szwl.model.entity.WechatPayInfo;
-import com.szwl.service.WechatPayInfoService;
-import io.swagger.annotations.ApiOperation;
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * <p>
- *  前端控制器
- * </p>
- *
- * @author wuhs
- * @since 2024-07-24
- */
-@RestController
-@RequestMapping("/wechatPayInfo")
-public class WechatPayInfoController {
-
-    @Autowired
-    private WechatPayInfoService wechatPayInfoService;
-
-    @ApiOperation("查询微信支付参数")
-    @GetMapping("/getWechatPayInfo")
-    public ResponseModel<?> getWechatPayInfo(String sn) {
-        if(StringUtils.isEmpty(sn)) {
-            return R.fail(ResponseCodesEnum.A0001, "订单号为空");
-        }
-        WechatPayInfo wechatPayInfo = wechatPayInfoService.getById(sn);
-        return R.ok(wechatPayInfo);
-    }
-}
-

+ 0 - 1
src/main/java/com/szwl/feign/bean/SzwlFeign.java

@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.szwl.model.bo.ResponseModel;
 import com.szwl.model.entity.*;
 import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;

+ 0 - 1
src/main/java/com/szwl/service/impl/TOrderServiceImpl.java

@@ -1325,7 +1325,6 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
             // 汇付分账参数
             order.setAcctSplitBunch(acctSplitBunch.toString());
             if (frpCode.equals(ConfigConsts.WECHAT_NATIVE)) {
-                //添加到汇付临时表
                 if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
                     result = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn;
                 } else {