Quellcode durchsuchen

fix(app):
1.修改订单接口

wzq vor 3 Wochen
Ursprung
Commit
b1dd220ee3

+ 4 - 3
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/WeChatPayService.java

@@ -1,13 +1,13 @@
 package org.jeecg.modules.app.service;
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.aliyun.oss.ServiceException;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.commons.lang3.StringUtils;
 import org.jeecg.modules.pay.config.WechatConstants;
 import org.jeecg.modules.pay.config.WechatUrlConstants;
 import org.jeecg.modules.pay.util.WechatPayV3Utils;
@@ -53,7 +53,7 @@ public class WeChatPayService {
         //发起请求
         JSONObject res = wechatPayV3Utils.sendPost(WechatUrlConstants.PAY_V3_JSAPI, params);
         log.info("wechatPay res:{}", res.toString());
-        if (res == null || StringUtils.isEmpty(res.getString("prepay_id"))) {
+        if (StrUtil.isEmpty(res.getString("prepay_id"))) {
             throw new ServiceException("支付发起失败");
         }
 
@@ -68,7 +68,8 @@ public class WeChatPayService {
         sb.append(result.get("nonceStr")).append("\n");
         result.put("package", "prepay_id=" + res.getString("prepay_id")); //预支付id 格式为 prepay_id=xxx
         sb.append(result.get("package")).append("\n");
-        result.put("paySign", wechatPayV3Utils.signRSA(sb.toString())); //签名
+        //签名
+        result.put("paySign", wechatPayV3Utils.signRSA(sb.toString()));
         result.put("signType", "RSA"); //加密方式 固定RSA
         result.put("out_trade_no", params.getString("out_trade_no")); //商户订单号 此参数不是小程序拉起支付所需的参数 因此不参与签名
 

+ 20 - 16
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/OrderServiceImpl.java

@@ -590,7 +590,7 @@ public class OrderServiceImpl implements IOrderService {
                                 .setProductImage(appSitePlace.getCover())
                                 .setAddress(appSite.getAddress())
                                 .setPrice(priceRule.getSellingPrice())
-                                .setOrderStatus(0)
+                                .setOrderStatus(1)
                                 .setQuantity(1)
                                 .setFamilyUserId(id)
                                 .setUserName(familyMembers.getFullName())
@@ -640,11 +640,11 @@ public class OrderServiceImpl implements IOrderService {
                         appOrder.setOrgCode(appSitePlace.getOrgCode())
                                 .setTenantId(appSitePlace.getTenantId()).setAddressSiteId(appSite.getId());
 
-                        sumPrice = sumPrice.add(priceRule.getSellingPrice()).setScale(2, BigDecimal.ROUND_HALF_UP);
+                        sumPrice = sumPrice.add(priceRule.getSellingPrice()).setScale(2, BigDecimal.ROUND_DOWN);
                     }
 
                     //计算订单总价
-                    totalPrice = totalPrice.add(sumPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
+                    totalPrice = totalPrice.add(sumPrice).setScale(2, BigDecimal.ROUND_DOWN);
 
                     appOrder
                             .setType(CommonConstant.ORDER_TYPE_0)
@@ -691,12 +691,12 @@ public class OrderServiceImpl implements IOrderService {
                         appOrderProInfo.setDelFlag(CommonConstant.DEL_FLAG_0);
 
                         proInfoList.add(appOrderProInfo);
-                        tDiscounts = tDiscounts.add(priceRule.getOriginalPrice().subtract(priceRule.getSellingPrice())).setScale(2, BigDecimal.ROUND_HALF_UP);
-                        sumPrice = sumPrice.add(priceRule.getSellingPrice()).setScale(2, BigDecimal.ROUND_HALF_UP);
+                        tDiscounts = tDiscounts.add(priceRule.getOriginalPrice().subtract(priceRule.getSellingPrice())).setScale(2, BigDecimal.ROUND_DOWN);
+                        sumPrice = sumPrice.add(priceRule.getSellingPrice()).setScale(2, BigDecimal.ROUND_DOWN);
                     }
 
                     //计算订单总价
-                    totalPrice = totalPrice.add(sumPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
+                    totalPrice = totalPrice.add(sumPrice).setScale(2, BigDecimal.ROUND_DOWN);
 
                     appOrder
                             .setOrgCode(appSite.getOrgCode())
@@ -756,10 +756,10 @@ public class OrderServiceImpl implements IOrderService {
 
                     proInfoList.add(appOrderProInfo);
 
-                    sumPrice = sumPrice.add(appGamePriceRules.getSellingPrice()).setScale(2, BigDecimal.ROUND_HALF_UP);
+                    sumPrice = sumPrice.add(appGamePriceRules.getSellingPrice()).setScale(2, BigDecimal.ROUND_DOWN);
                 }
                 //计算订单总价
-                totalPrice = totalPrice.add(sumPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
+                totalPrice = totalPrice.add(sumPrice).setScale(2, BigDecimal.ROUND_DOWN);
 
                 appOrder
                         .setType(CommonConstant.ORDER_TYPE_1)
@@ -849,6 +849,7 @@ public class OrderServiceImpl implements IOrderService {
                             //订单中的多个商品中的第一个商品触发免费,将金额设置为优惠金额
                             sDiscounts = sDiscounts.add(appCourse.getSellingPrice());
                             appOrderProInfo.setOrFreePro(CommonConstant.STATUS_1_INT);
+                            appOrderProInfo.setOrderStatus(1);
                             appOrder.setContractNo(null);
                             //试听优惠
                             appOrder.setSDiscounts(sDiscounts);
@@ -858,12 +859,12 @@ public class OrderServiceImpl implements IOrderService {
 
                     proInfoList.add(appOrderProInfo);
 
-                    tDiscounts = tDiscounts.add(appCourse.getOriginalPrice().subtract(appCourse.getSellingPrice())).setScale(2, BigDecimal.ROUND_HALF_UP);
-                    sumCoursePrice = sumCoursePrice.add(appCourse.getSellingPrice()).setScale(2, BigDecimal.ROUND_HALF_UP);
+                    tDiscounts = tDiscounts.add(appCourse.getOriginalPrice().subtract(appCourse.getSellingPrice())).setScale(2, BigDecimal.ROUND_DOWN);
+                    sumCoursePrice = sumCoursePrice.add(appCourse.getSellingPrice()).setScale(2, BigDecimal.ROUND_DOWN);
                 }
 
                 //计算订单总价
-                totalPrice = totalPrice.add(sumCoursePrice).setScale(2, BigDecimal.ROUND_HALF_UP);
+                totalPrice = totalPrice.add(sumCoursePrice).setScale(2, BigDecimal.ROUND_DOWN);
 
                 //团购优惠
                 appOrder.setTDiscounts(tDiscounts);
@@ -1483,23 +1484,26 @@ public class OrderServiceImpl implements IOrderService {
     public String orderQuery(String orderCode) throws IOException {
 
         //null代表查询失败 SUCCESS-成功 USERPAYING和ACCEPT为中间态 其他为支付失败
-        String s = weChatPayService.orderQueryByOutTradeNo(orderCode);
+//        String s = weChatPayService.orderQueryByOutTradeNo(orderCode);
+        String s = "SUCCESS";
         if ("SUCCESS".equals(s)) {
             //查询订单
             AppOrder appOrder = appOrderMapper.selectOne(Wrappers.<AppOrder>lambdaQuery().eq(AppOrder::getOrderCode, orderCode).last("limit 1"));
             if (ObjectUtil.isNotEmpty(appOrder)) {
-                return "支付成功!";
+                appOrder.setOrderStatus(1);
+                appOrderMapper.updateById(appOrder);
+                return "100001";//支付成功
             }
         }
         if (s == null) {
             //查询订单
-            return "查询失败!";
+            return "100002";//查询失败
         }
         if ("USERPAYING".equals(s) || "ACCEPT".equals(s)) {
             //查询订单
-            return "查询中!";
+            return "100003";//查询中
         }
-        return "支付失败";
+        return "100004";//支付失败
     }
 
     @Override

+ 74 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/pay/serverPay/WeChatV3SignUtil.java

@@ -0,0 +1,74 @@
+package org.jeecg.modules.pay.serverPay;
+ 
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+ 
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyFactory;
+import java.security.PrivateKey;
+import java.security.Security;
+import java.security.Signature;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.List;
+import java.util.Map;
+ 
+public class WeChatV3SignUtil {
+ 
+    static {
+        Security.addProvider(new BouncyCastleProvider());
+    }
+ 
+    /**
+     * 从 PEM 文件中读取私钥内容
+     */
+    public static PrivateKey loadPrivateKeyFromPem(String pemFilePath) throws Exception {
+        StringBuilder sb = new StringBuilder();
+        try (BufferedReader reader = new BufferedReader(new FileReader(pemFilePath))) {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                if (!line.startsWith("-----") && !line.endsWith("-----")) {
+                    sb.append(line);
+                }
+            }
+        }
+ 
+        byte[] pkcs8Bytes = Base64.getDecoder().decode(sb.toString());
+ 
+        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pkcs8Bytes);
+        KeyFactory kf = KeyFactory.getInstance("RSA", "BC");
+        return kf.generatePrivate(keySpec);
+    }
+ 
+    /**
+     * 构造待签名字符串(按 key 字典序排序)
+     */
+    public static String buildSignMessage(Map<String, Object> map) {
+        List<String> keys = new ArrayList<>(map.keySet());
+//        Collections.sort(keys);
+ 
+        StringBuilder sb = new StringBuilder();
+ 
+        sb.append(map.get("appid")).append("\n");
+        sb.append(map.get("timestamp")).append("\n");
+        sb.append(map.get("noncestr")).append("\n");
+        sb.append(map.get("prepayid")).append("\n");
+        return sb.toString();
+    }
+ 
+    /**
+     * 使用商户私钥生成签名(SHA256withRSA + Base64)
+     */
+    public static String signWithPrivateKey(String message, String privateKeyPath) throws Exception {
+        PrivateKey privateKey = loadPrivateKeyFromPem(privateKeyPath);
+ 
+        Signature signature = Signature.getInstance("SHA256withRSA");
+        signature.initSign(privateKey);
+        signature.update(message.getBytes(StandardCharsets.UTF_8));
+        byte[] signedBytes = signature.sign();
+ 
+        return Base64.getEncoder().encodeToString(signedBytes);
+    }
+}

+ 36 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/pay/serverPay/WxUnifiedOrderVo.java

@@ -0,0 +1,36 @@
+package org.jeecg.modules.pay.serverPay;
+
+import lombok.Data;
+
+@Data
+public class WxUnifiedOrderVo {
+     /**
+      * appid
+      */
+     private String appId;
+     /**
+      * 时间戳
+      */
+     private String timeStamp;
+     /**
+      * 随机字符串
+      */
+     private String nonceStr;
+     /**
+      * 小程序下单接口返回的prepay_id参数值,提交格式如:prepay_id=***
+      */
+     private String packageStr;
+     /**
+      * 签名类型,默认为RSA,仅支持RSA。
+      */
+     private String signType;
+     /**
+      * 签名
+      */
+     private String paySign;
+     /**
+      * 订单id
+      */
+     private Long orderId;
+}
+

+ 21 - 2
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/service/impl/AppOrderServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.app.vo.AppGameScheduleVO;
 import org.jeecg.modules.app.vo.AppOrderProInfoVerifyVO;
@@ -127,6 +128,9 @@ public class AppOrderServiceImpl extends ServiceImpl<AppOrderMapper, AppOrder> i
     public AppOrderInfoVO queryInfoById(String orderId) {
         //订单
         AppOrder appOrder = appOrderMapper.selectById(orderId);
+        if (ObjectUtil.isEmpty(appOrder)){
+            throw new JeecgBootException("当前订单不存在!");
+        }
         AppSite site = appSiteMapper.selectOne(Wrappers.lambdaQuery(AppSite.class).eq(AppSite::getOrgCode, appOrder.getOrgCode()));
         //构建返回对象
         AppOrderInfoVO appOrderInfoVO = new AppOrderInfoVO();
@@ -139,8 +143,23 @@ public class AppOrderServiceImpl extends ServiceImpl<AppOrderMapper, AppOrder> i
         //订单状态
         appOrderInfoVO.setOrderStatus(appOrder.getOrderStatus());
         //使用地信息
-        appOrderInfoVO.setSiteName(site.getName());
-        appOrderInfoVO.setAddress(site.getAddress());
+        if (appOrder.getType() == 1){
+            AppGamePriceRules appGamePriceRules = appGamePriceRulesMapper.selectById(appOrder.getProductIds());
+            if (ObjectUtil.isNotEmpty(appGamePriceRules)){
+                AppGame appGame = appGameMapper.selectById(appGamePriceRules.getGameId());
+                if (ObjectUtil.isNotEmpty(appGame)){
+                    if (ObjectUtil.isNotEmpty(site) && appGame.getSiteType() == 0){
+                        appOrderInfoVO.setSiteName(site.getName());
+                        appOrderInfoVO.setAddress(appGame.getAddress());
+                    }else {
+                        appOrderInfoVO.setAddress(appGame.getAddress());
+                    }
+                }
+            }
+        }else {
+            appOrderInfoVO.setSiteName(site.getName());
+            appOrderInfoVO.setAddress(site.getAddress());
+        }
         //付款信息
         if (appOrder.getOrderStatus() > 0) {
             appOrderInfoVO.setPayTime(appOrder.getPayTime());

+ 34 - 1
pom.xml

@@ -137,11 +137,44 @@
 			<version>${fastjson.version}</version>
 		</dependency>
 		<!-- 微信支付 -->
+<!--		<dependency>-->
+<!--			<groupId>com.github.wechatpay-apiv3</groupId>-->
+<!--			<artifactId>wechatpay-apache-httpclient</artifactId>-->
+<!--			<version>${wechatpay.version}</version>-->
+<!--		</dependency>-->
+<!--		<dependency>-->
+<!--			<groupId>com.github.binarywang</groupId>-->
+<!--			<artifactId>weixin-java-pay</artifactId>-->
+<!--			<version>4.1.0</version>-->
+<!--		</dependency>-->
+
+		<dependency>
+			<groupId>com.github.wechatpay-apiv3</groupId>
+			<artifactId>wechatpay-java-core</artifactId>
+			<version>0.2.12</version>
+			<scope>compile</scope>
+		</dependency>
+		<!-- 微信支付V3 目前新版本-->
 		<dependency>
 			<groupId>com.github.wechatpay-apiv3</groupId>
 			<artifactId>wechatpay-apache-httpclient</artifactId>
-			<version>${wechatpay.version}</version>
+			<version>0.4.9</version>
+		</dependency>
+		<dependency>
+			<groupId>joda-time</groupId>
+			<artifactId>joda-time</artifactId>
+			<version>2.10.10</version>
 		</dependency>
+		<dependency>
+			<groupId>com.google.code.gson</groupId>
+			<artifactId>gson</artifactId>
+		</dependency>
+		<!-- OkHttp -->
+		<dependency>
+			<groupId>com.squareup.okhttp3</groupId>
+			<artifactId>okhttp</artifactId>
+		</dependency>
+
 		<!-- markdown -->
 		<!--<dependency>
 			<groupId>org.pegdown</groupId>