puzhibing
2025-01-13 acccff9860b271d55c55dc87486f7c20b9896e6c
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/payment/PaymentUtil.java
@@ -3,6 +3,7 @@
import cn.hutool.http.*;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.order.util.payment.model.*;
import lombok.extern.slf4j.Slf4j;
@@ -26,6 +27,10 @@
    * 商户号
    */
   private static final String merchantNo = "888122600004175";
   /**
    * 平台-报备商户号
    */
   private static final String sysTradeMerchantNo = "777168500885852";
   /**
    * 支付回调地址
    */
@@ -74,7 +79,7 @@
      //APPID
      body.put("q7_AppId", appId);
      //报备商户号
      body.put("qa_TradeMerchantNo", tradeMerchantNo);
      body.put("qa_TradeMerchantNo", StringUtils.isNotEmpty(tradeMerchantNo) ? tradeMerchantNo : sysTradeMerchantNo);
      String sign = null;
      try {
         sign = sign(body);
@@ -155,7 +160,7 @@
      //退款金额
      body.put("p4_RefundAmount", refundAmount);
      //服务器异步通知地址
      body.put("p6_NotifyUrl", notifyUrl);
      body.put("p6_NotifyUrl", callbackUrl + notifyUrl);
      String sign = null;
      try {
         sign = sign(body);
@@ -249,13 +254,13 @@
   
   
   
   public static String sign(JSONObject body) throws Exception{
   public static String sign(JSONObject body) {
      Set<Map.Entry<String, Object>> entries = body.entrySet();
      List<Map.Entry<String, Object>> infoIds = new ArrayList<Map.Entry<String, Object>>(entries);
      // 对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序)
      Collections.sort(infoIds, new Comparator<Map.Entry<String, Object>>() {
         public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
            return (o1.getKey()).toString().compareTo(o2.getKey());
            return (o1.getKey()).compareTo(o2.getKey());
         }
      });
      // 构造签名键值对的格式