puzhibing
2025-01-11 f18a802137a7642473891f6886d44cf0c229efed
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/util/payment/TransferUtil.java
@@ -1,5 +1,6 @@
package com.ruoyi.other.util.payment;
import cn.hutool.http.ContentType;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
@@ -30,8 +31,16 @@
    * 商户号
    */
   private static final String merchantNo = "888122600004175";
   /**
    * 平台-报备商户号
    */
   public static final String sysTradeMerchantNo = "777168500885852";
   
   private static final String format = "yyyy-MM-dd HH:mm:ss";
   /**
    * 支付回调地址
    */
   private static final String callbackUrl = "http://221.182.45.100:9000";
   
   
   /**
@@ -42,6 +51,7 @@
   public static SinglePayResult singlePay(SinglePay singlePay){
      String url = "https://www.joinpay.com/payment/pay/singlePay";
      HttpRequest post = HttpUtil.createPost(url);
      post.contentType(ContentType.JSON.toString());
      JSONObject body = new JSONObject();
      //商户编号
      body.put("userNo", merchantNo);
@@ -84,7 +94,7 @@
       */
      body.put("paidUse", singlePay.getPaidUse());
      //商户通知地址
      body.put("callbackUrl", singlePay.getCallbackUrl());
      body.put("callbackUrl", callbackUrl + singlePay.getCallbackUrl());
      String sign = null;
      try {
         sign = sign(body);
@@ -124,6 +134,7 @@
   public static SinglePayQueryResult singlePayQuery(String merchantOrderNo){
      String url = "https://www.joinpay.com/payment/pay/singlePayQuery";
      HttpRequest post = HttpUtil.createPost(url);
      post.contentType(ContentType.JSON.toString());
      JSONObject body = new JSONObject();
      //商户编号
      body.put("userNo", merchantNo);
@@ -167,6 +178,7 @@
   public static AccountBalanceQueryResult accountBalanceQuery(){
      String url = "https://www.joinpay.com/payment/pay/accountBalanceQuery";
      HttpRequest post = HttpUtil.createPost(url);
      post.contentType(ContentType.JSON.toString());
      JSONObject body = new JSONObject();
      //商户编号
      body.put("userNo", merchantNo);
@@ -203,13 +215,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());
         }
      });
      // 构造签名键值对的格式
@@ -226,4 +238,9 @@
      return MD5AndKL.MD5(sb.toString());
   }
   
   public static void main(String[] args) {
      TransferUtil.accountBalanceQuery();
   }
}