Bläddra i källkod

fix:“优化汇付支付“

soobin 1 år sedan
förälder
incheckning
9be684bff8

+ 10 - 0
src/main/java/com/szwl/constant/HuifuConstant.java

@@ -63,6 +63,16 @@ public class HuifuConstant {
     public static final String SC_WX_APP_SECRET = "f131c85c06a80e466bd7e366cd477b93";
 
     /**
+     * 申泽商户公众账号ID
+     */
+    public static final String SZ_OPEN_ID = "ooT-O55AXUeDIlNruSaIBhRvLPZw";
+
+    /**
+     * 七云商户公众账号ID
+     */
+    public static final String SC_OPEN_ID = "o-vRh6a1NpOnxHlyY_OTVIPuRjNM";
+
+    /**
      * 申泽分账商户号
      */
     public static final String SZ_DIV_HUIFU_ID = "6666000136120737";

+ 3 - 89
src/main/java/com/szwl/controller/TOrderController.java

@@ -4860,8 +4860,8 @@ public class TOrderController {
     @ApiOperation("收钱吧反扫购物车支付")
     @PostMapping("/sqbCardPay")
     @ResponseBody
-    public Object sqbCardPay(String authCode, String frpCode, String clientId, String ip, @RequestBody Map<String, String> productNameMap, HttpServletRequest request) {
-        return orderService.sqbCardPay(authCode, frpCode, clientId, ip, productNameMap, request);
+    public Object sqbCardPay(String authCode, String frpCode, String clientId, String ip, @RequestBody Map<String, String> productNameMap) {
+        return orderService.sqbCardPay(authCode, frpCode, clientId, ip, productNameMap);
     }
 
     @ApiOperation("收钱吧发起退款")
@@ -4881,94 +4881,8 @@ public class TOrderController {
      */
     @ApiOperation(value = "优化汇付支付")
     @GetMapping("/testUniPay")
-    public Object testUniPay(String code, String clientId, String productName, String frpCode, String pri) {
+    public Object testUniPay(String code, String clientId, String productName, String frpCode, String pri) throws Exception {
         return orderService.scanpay(code, clientId, productName, frpCode, pri);
     }
-
-    @ApiOperation(value = "汇付:获取code回调跳转到支付页面,用于微信扫码支付")
-    @GetMapping("/callBack")
-    public void callBack(HttpServletRequest request, HttpServletResponse response) throws IOException {
-        // 获取code
-        String code = request.getParameter("code");
-        String sn = request.getParameter("state");
-        LambdaQueryWrapper<TOrder> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(TOrder::getSn, sn);
-        TOrder order = orderService.getOne(wrapper);
-        // 从临时表中获取订单信息
-        String result = null;
-        if (order != null) {
-            String companyType = order.getCompanyType();
-            if (order.getStatus() == 1) {
-                if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-                    result = HuifuConstant.SC_JUMP_URL + "/#/popPayment?status=1";
-                } else {
-                    result = HuifuConstant.SZ_JUMP_URL + "/#/popPayment?status=1";
-                }
-            } else {
-                // 查询是否有支付参数
-                WechatPayInfo wechatPayInfo = wechatPayInfoService.getById(sn);
-                if (wechatPayInfo != null) {
-                    String timeStamp = wechatPayInfo.getTimeStamp();
-                    String nonceStr = wechatPayInfo.getNonceStr();
-                    String packageValue = wechatPayInfo.getPackageValue();
-                    String paySign = wechatPayInfo.getPaySign();
-                    if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-                        result = HuifuConstant.SC_JUMP_URL + "/#/popPayment?" +
-                                "sn=" + sn +
-                                "&timeStamp=" + timeStamp +
-                                "&nonceStr=" + nonceStr +
-                                "&package=" + packageValue +
-                                "&paySign=" + paySign;
-                    } else {
-                        result = HuifuConstant.SZ_JUMP_URL + "/#/popPayment?" +
-                                "sn=" + sn +
-                                "&timeStamp=" + timeStamp +
-                                "&nonceStr=" + nonceStr +
-                                "&package=" + packageValue +
-                                "&paySign=" + paySign;
-                    }
-                    log.info("微信支付链接:{}", result);
-                } else {
-                    String openid;
-                    if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-                        // 获取openid
-                        try {
-                            String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
-                                    "appid=" + HuifuConstant.SC_WX_SUB_APP_ID +
-                                    "&secret=" + HuifuConstant.SC_WX_APP_SECRET +
-                                    "&code=" + code +
-                                    "&grant_type=authorization_code";
-                            log.info("获取openID:{}", openUrl);
-                            org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
-                            log.info("获取openID结果:{}", jsonObject);
-                            openid = jsonObject.getString("openid");
-                            result = huifuMchService.payWechat(order, openid);
-                        } catch (Exception e) {
-                            e.printStackTrace();
-                        }
-                    } else {
-                        // 获取openid
-                        try {
-                            String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
-                                    "appid=" + HuifuConstant.SZ_WX_SUB_APP_ID +
-                                    "&secret=" + HuifuConstant.SZ_WX_APP_SECRET +
-                                    "&code=" + code +
-                                    "&grant_type=authorization_code";
-                            log.info("获取openID:{}", openUrl);
-                            org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
-                            log.info("获取openID结果:{}", jsonObject);
-                            openid = jsonObject.getString("openid");
-                            result = huifuMchService.payWechat(order, openid);
-                        } catch (Exception e) {
-                            e.printStackTrace();
-                        }
-                    }
-                }
-            }
-        }
-        log.info("支付链接:{}", result);
-        response.sendRedirect(result);
-    }
-
 }
 

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

@@ -0,0 +1,42 @@
+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);
+    }
+}
+

+ 1 - 2
src/main/java/com/szwl/service/THuifuMchService.java

@@ -62,8 +62,7 @@ public interface THuifuMchService extends IService<THuifuMch> {
     /**
      * 汇付微信正扫支付
      * @param order
-     * @param openid
      * @return
      */
-    String payWechat(TOrder order, String openid) throws Exception;
+    String payWechat(TOrder order) throws Exception;
 }

+ 2 - 3
src/main/java/com/szwl/service/TOrderService.java

@@ -108,10 +108,9 @@ public interface TOrderService extends IService<TOrder> {
      * @param clientId
      * @param ip
      * @param productNameMap
-     * @param request
      * @return
      */
-    JsonMessage sqbCardPay(String authCode, String frpCode, String clientId, String ip, Map<String, String> productNameMap, HttpServletRequest request);
+    JsonMessage sqbCardPay(String authCode, String frpCode, String clientId, String ip, Map<String, String> productNameMap);
 
     /**
      * 收钱吧发起退款
@@ -129,5 +128,5 @@ public interface TOrderService extends IService<TOrder> {
      * @param pri
      * @return
      */
-    JsonMessage scanpay(String code, String clientId, String productName, String frpCode, String pri);
+    JsonMessage scanpay(String code, String clientId, String productName, String frpCode, String pri) throws Exception;
 }

+ 6 - 22
src/main/java/com/szwl/service/impl/THuifuMchServiceImpl.java

@@ -304,7 +304,7 @@ public class THuifuMchServiceImpl extends ServiceImpl<THuifuMchMapper, THuifuMch
     }
 
     @Override
-    public String payWechat(TOrder order, String openid) throws Exception {
+    public String payWechat(TOrder order) throws Exception {
         String url = "https://api.huifu.com/v2/trade/payment/jspay";
         HuifuBaseCommon.doInit(OppsMerchantConfig.getMerchantConfig());
         JSONObject request = new JSONObject();
@@ -341,10 +341,11 @@ public class THuifuMchServiceImpl extends ServiceImpl<THuifuMchMapper, THuifuMch
         JSONObject wxData = new JSONObject();
         if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
             wxData.put("sub_appid", HuifuConstant.SC_WX_SUB_APP_ID);
+            wxData.put("open_id", HuifuConstant.SC_OPEN_ID);
         } else {
             wxData.put("sub_appid", HuifuConstant.SZ_WX_SUB_APP_ID);
+            wxData.put("open_id", HuifuConstant.SZ_OPEN_ID);
         }
-        wxData.put("open_id", openid);
         request.put("wx_data", wxData);
         // 签名:sign
         String s = JSON.toJSONString(request);
@@ -356,11 +357,11 @@ public class THuifuMchServiceImpl extends ServiceImpl<THuifuMchMapper, THuifuMch
         requestData.put("product_id", HuifuConstant.PRODUCT_ID);
         requestData.put("sign", sign);
         requestData.put("data", request);
-        System.out.println("请求体:" + requestData);
+        log.info("汇付微信扫码下单:" + requestData);
         String success = OkHttpClientTools.httpPost(url, requestData.toString(), HuifuConstant.PRODUCT_ID);
         // 拿到返回参数
         JSONObject result = JSONObject.parseObject(success);
-        log.info("汇付返回参数:{}", result);
+        log.info("汇付微信扫码下单返回参数:{}", result);
         JSONObject data = result.getJSONObject("data");
         String payInfo = data.getString("pay_info");
         JSONObject payInfoJson = JSONObject.parseObject(payInfo);
@@ -382,23 +383,6 @@ public class THuifuMchServiceImpl extends ServiceImpl<THuifuMchMapper, THuifuMch
         wechatPayInfo.setPaySign(paySign);
         wechatPayInfoService.save(wechatPayInfo);
 
-        String resultUrl = "";
-        if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-            resultUrl = HuifuConstant.SC_JUMP_URL + "/#/popPayment?" +
-                    "sn=" + sn +
-                    "&timeStamp=" + timeStamp +
-                    "&nonceStr=" + nonceStr +
-                    "&package=" + packageValue +
-                    "&paySign=" + paySign;
-        } else {
-            resultUrl = HuifuConstant.SZ_JUMP_URL + "/#/popPayment?" +
-                    "sn=" + sn +
-                    "&timeStamp=" + timeStamp +
-                    "&nonceStr=" + nonceStr +
-                    "&package=" + packageValue +
-                    "&paySign=" + paySign;
-        }
-        log.info("微信支付链接:{}", resultUrl);
-        return resultUrl;
+        return sn;
     }
 }

+ 14 - 4
src/main/java/com/szwl/service/impl/TOrderServiceImpl.java

@@ -700,7 +700,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
     }
 
     @Override
-    public JsonMessage sqbCardPay(String authCode, String frpCode, String clientId, String ip, Map<String, String> productNameMap, HttpServletRequest request) {
+    public JsonMessage sqbCardPay(String authCode, String frpCode, String clientId, String ip, Map<String, String> productNameMap) {
         if (productNameMap == null) {
             return JsonMessage.error("数据出错");
         }
@@ -1100,7 +1100,7 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
     }
 
     @Override
-    public JsonMessage scanpay(String code, String clientId, String productName, String frpCode, String pri) {
+    public JsonMessage scanpay(String code, String clientId, String productName, String frpCode, String pri) throws Exception {
         TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
         if (equipment == null || equipment.getId() == null) {
             return JsonMessage.error("找不到设备");
@@ -1267,11 +1267,21 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
             // 汇付分账参数
             order.setAcctSplitBunch(acctSplitBunch.toString());
             if (frpCode.equals(ConfigConsts.WECHAT_NATIVE)) {
+                String resultSn = "";
+                try {
+                    resultSn = huifuMchService.payWechat(order);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    return JsonMessage.error("申请支付失败");
+                }
+                if (StrUtil.isEmpty(resultSn)) {
+                    return JsonMessage.error("找不到支付图片");
+                }
                 //添加到汇付临时表
                 if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
-                    result = HuifuConstant.SC_JUMP_URL + "/#/payWechat?sn=" + sn;
+                    result = HuifuConstant.SC_JUMP_URL + "/#/payWechat?sn=" + resultSn;
                 } else {
-                    result = HuifuConstant.SZ_JUMP_URL + "/#/payWechat?sn=" + sn;
+                    result = HuifuConstant.SZ_JUMP_URL + "/#/payWechat?sn=" + resultSn;
                 }
                 log.info("返回链接:{}", result);
                 String qrcode = CodeUtil.toQrcode(result);