From ea6bf9042d9ad4faaf328bdc68a41ef36b47f13d Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期二, 14 一月 2025 20:09:55 +0800
Subject: [PATCH] 12.18

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/payment/TransferUtil.java |   52 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/payment/TransferUtil.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/payment/TransferUtil.java
index c60dbc8..5d457f9 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/payment/TransferUtil.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/payment/TransferUtil.java
@@ -1,5 +1,6 @@
 package com.ruoyi.order.util.payment;
 
+import cn.hutool.http.ContentType;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
@@ -27,10 +28,18 @@
 	 * 商户号
 	 */
 	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";
+
+
 	/**
 	 * 单笔代付
 	 * @param singlePay
@@ -39,11 +48,12 @@
 	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);
 		//报备商户号
-		body.put("tradeMerchantNo", singlePay.getTradeMerchantNo());
+//		body.put("tradeMerchantNo", singlePay.getTradeMerchantNo());
 		//产品类型
 		body.put("productCode", "BANK_PAY_DAILY_ORDER");
 		//交易请求时间
@@ -81,7 +91,7 @@
 		 */
 		body.put("paidUse", singlePay.getPaidUse());
 		//商户通知地址
-		body.put("callbackUrl", singlePay.getCallbackUrl());
+		body.put("callbackUrl", callbackUrl + singlePay.getCallbackUrl());
 		String sign = null;
 		try {
 			sign = sign(body);
@@ -111,8 +121,8 @@
 		SinglePayResult uniPayResult = jsonObject.getObject("data", SinglePayResult.class);
 		return uniPayResult;
 	}
-	
-	
+
+
 	/**
 	 * 单笔代付查询接口
 	 * @param merchantOrderNo   订单号
@@ -121,6 +131,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);
@@ -155,8 +166,8 @@
 		SinglePayQueryResult uniPayResult = jsonObject.getObject("data", SinglePayQueryResult.class);
 		return uniPayResult;
 	}
-	
-	
+
+
 	/**
 	 * 可取余额查询
 	 * @return
@@ -164,6 +175,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);
@@ -196,22 +208,16 @@
 		AccountBalanceQueryResult uniPayResult = jsonObject.getObject("data", AccountBalanceQueryResult.class);
 		return uniPayResult;
 	}
-	
-	
-	
-	
-	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());
-			}
-		});
 		// 构造签名键值对的格式
 		StringBuilder sb = new StringBuilder();
-		for (Map.Entry<String, Object> item : infoIds) {
+		for (Map.Entry<String, Object> item : entries) {
 			if (item.getKey() != null || item.getKey() != "") {
 				Object val = item.getValue();
 				if (!(val == "" || val == null)) {
@@ -220,7 +226,9 @@
 			}
 		}
 		sb.append(key);
+		log.info("待签名串:{}", sb.toString());
 		return MD5AndKL.MD5(sb.toString());
 	}
 	
+	
 }

--
Gitblit v1.7.1