Explorar el Código

fix(national-motion-system-biz): 修复订单支付与分账相关逻辑问题

修复了订单支付流程中注释代码未启用的问题,恢复了支付参数的正确设置。同时更新了微信支付服务中的交易状态查询逻辑,并完善了支付时间、交易号等字段的赋值。
此外,增加了对微信支付 V3 接口 GET 请求的签名支持,并补充了分账回退接口的常量定义。将部分同步操作标记为异步处理,优化后续业务流程兼容性。
wzq hace 3 semanas
padre
commit
a9c0f1f6dc

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

@@ -210,6 +210,8 @@ public class WeChatPayService {
                     appOrder.setPayStatus(CommonConstant.ORDER_STATUS_1);
                     appOrder.setPayTime(new Date());
                     appOrder.setPayType(CommonConstant.STATUS_0_INT);
+                    appOrder.setPayId(res.getString("transaction_id"));
+                    appOrder.setPayTime(dealDateFormat(res.getString("success_time")));
 
                     List<AppOrderProInfo> proInfoList = appOrderProInfoMapper.selectList(Wrappers.<AppOrderProInfo>lambdaQuery().eq(AppOrderProInfo::getOrderId, appOrder.getId()));
                     if (ObjectUtil.isNotEmpty(proInfoList)){
@@ -246,7 +248,7 @@ public class WeChatPayService {
         args.put("sp_mchid", WechatConstants.WECHAT_SP_MCH_ID);
         args.put("sub_mchid", WechatConstants.WECHAT_SUB_MCH_ID);
         url = url + "?" + WXPayUtility.urlEncode(args);
-        JSONObject res = wechatPayV3Utils.sendGet(url);
+        JSONObject res = wechatPayV3Utils.sendGet(url, null);
         return res ;
     }
 
@@ -292,7 +294,7 @@ public class WeChatPayService {
         appOrderRefundsInfoMapper.insert(appOrderRefundsInfo);
 
 
-        //todo 发起分账回退
+        //todo 异步发起分账回退
 
         try {
             JSONObject params = new JSONObject();

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

@@ -1194,8 +1194,8 @@ public class OrderServiceImpl implements IOrderService {
         if ((ObjectUtil.isNotEmpty(appOrder.getOrderOrFree()) && appOrder.getOrderOrFree() == 1) || appOrder.getPrice().compareTo(BigDecimal.ZERO)== 0) {
             payForm.setOrPayOrder(0);
         } else {
-//            Map<String, String> result = payment(appOrder.getId());
-//            payForm.setParams(result);
+            Map<String, String> result = payment(appOrder.getId());
+            payForm.setParams(result);
 
             //发布任务到redission延迟队列(16分钟)
             String task = CommonConstant.ORDER_TIME_OUT_TASK_PREFIX + appOrder.getId();
@@ -1245,8 +1245,8 @@ public class OrderServiceImpl implements IOrderService {
         //订单金额信息
         JSONObject amount_json = new JSONObject();
         //支付金额 单位:分
-//        amount_json.put("total", Integer.parseInt(amount_fee(appOrder.getPrice())));
-        amount_json.put("total", Integer.parseInt(amount_fee(new BigDecimal("0.01"))));//测试0.01元
+        amount_json.put("total", Integer.parseInt(amount_fee(appOrder.getPrice())));
+//        amount_json.put("total", Integer.parseInt(amount_fee(new BigDecimal("0.01"))));//测试0.01元
         amount_json.put("currency", "CNY");//固定传:CNY,代表人民币
         params.put("amount", amount_json);
 
@@ -1698,14 +1698,15 @@ public class OrderServiceImpl implements IOrderService {
         AppOrder appOrder = appOrderMapper.selectOne(Wrappers.<AppOrder>lambdaQuery().eq(AppOrder::getOrderCode, orderCode).last("limit 1"));
 
         //null代表查询失败 SUCCESS-成功 USERPAYING和ACCEPT为中间态 其他为支付失败
-//        JSONObject res = weChatPayService.orderQueryByOutTradeNo(orderCode);
-//        String s = res == null ? null : res.getString("trade_state");
-        String s = "SUCCESS";
+        JSONObject res = weChatPayService.orderQueryByOutTradeNo(orderCode);
+        String s = res == null ? null : res.getString("trade_state");
         if ("SUCCESS".equals(s) || appOrder.getOriginalPrice().compareTo(BigDecimal.ZERO)==0) {
 
             if (ObjectUtil.isNotEmpty(appOrder) && Objects.equals(appOrder.getOrderStatus(), CommonConstant.ORDER_STATUS_0)) {
                 appOrder.setOrderStatus(1);
-//                appOrder.setTransactionId(res.getString("transaction_id"));
+                appOrder.setPayTime(new Date());
+                appOrder.setPayStatus(1);
+                appOrder.setTransactionId(res.getString("transaction_id"));
                 appOrderMapper.updateById(appOrder);
                 List<AppOrderProInfo> proInfoList = appOrderProInfoMapper.selectList(Wrappers.<AppOrderProInfo>lambdaQuery().eq(AppOrderProInfo::getOrderId, appOrder.getId()));
                 if (CollUtil.isNotEmpty(proInfoList)) {

+ 6 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/pay/config/WechatPayV3Utils.java

@@ -18,6 +18,7 @@ import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.util.EntityUtils;
+import org.jeecg.modules.pay.paytest.SignUtils;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Component;
 
@@ -166,7 +167,7 @@ public class WechatPayV3Utils {
      * @param url 请求地址 参数直接在地址上拼接
      * @return
      */
-    public JSONObject sendGet(String url) {
+    public JSONObject sendGet(String url,String urlSuffix) {
         try {
             if (httpClient == null) {
                 setHttpClient();
@@ -174,6 +175,10 @@ public class WechatPayV3Utils {
             URIBuilder uriBuilder = new URIBuilder(url);
             HttpGet httpGet = new HttpGet(uriBuilder.build());
             httpGet.addHeader("Accept", "application/json");
+
+            String authorization = SignUtils.authorization("GET", urlSuffix, WechatConstants.WECHAT_SP_MCH_ID, WechatConstants.WECHAT_MCH_SERIAL_NUM, "", WechatConstants.WECHAT_MCH_PRIVATE_KEY);
+
+            httpGet.addHeader("Authorization", authorization);
             CloseableHttpResponse response = httpClient.execute(httpGet);
             String bodyAsString = EntityUtils.toString(response.getEntity());
             log.info("微信返回的内容:" + bodyAsString);

+ 3 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/pay/config/WechatUrlConstants.java

@@ -34,4 +34,7 @@ public class WechatUrlConstants {
     //服务商 查询分账结果
     public final static String PAY_V3_QUERY_PROFIT_SHARING = "https://api.mch.weixin.qq.com/v3/profitsharing/orders/";
 
+    //服务商 请求分账回退
+    public final static String PAY_V3_RETURN_ORDER = "https://api.mch.weixin.qq.com/v3/profitsharing/return-orders";
+
 }