From 50eb3996d9b25ee04247fd6be3dc42384597f512 Mon Sep 17 00:00:00 2001
From: 18631081161 <2088094923@qq.com>
Date: Fri, 17 Apr 2026 22:18:25 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=8E=B0=E6=89=93=E6=AC=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
server/Endpoints/EarningEndpoints.cs | 26 ++++++------------
server/Services/WxPayService.cs | 41 ++++++++++++++++++++++++++++
server/appsettings.json | 2 +-
3 files changed, 51 insertions(+), 18 deletions(-)
diff --git a/server/Endpoints/EarningEndpoints.cs b/server/Endpoints/EarningEndpoints.cs
index 61535db..5ca1479 100644
--- a/server/Endpoints/EarningEndpoints.cs
+++ b/server/Endpoints/EarningEndpoints.cs
@@ -366,38 +366,30 @@ public static class EarningEndpoints
try
{
- // 解密回调数据
- var notifyResult = wxPay.VerifyAndDecryptNotify(serialNo, timestamp, nonce, signature, body);
+ // 用转账专用方法解密回调数据
+ var notifyResult = wxPay.DecryptTransferNotify(body);
if (notifyResult == null)
{
Console.WriteLine("[转账回调] 解密失败");
return Results.Json(new { code = "FAIL", message = "解密失败" }, statusCode: 500);
}
- // 回调中 out_trade_no 对应 out_bill_no
- var outBillNo = notifyResult.OrderNo;
- var state = notifyResult.TradeState;
+ var outBillNo = notifyResult.OutBillNo;
+ var transferBillNo = notifyResult.TransferBillNo;
+ var state = notifyResult.State;
- Console.WriteLine($"[转账回调] outBillNo={outBillNo}, state={state}");
+ Console.WriteLine($"[转账回调] outBillNo={outBillNo}, transferBillNo={transferBillNo}, state={state}");
- // 查找对应的提现记录(out_bill_no 格式为 W{id}T{timestamp})
+ // 通过微信转账单号精确匹配提现记录
var withdrawal = await db.Withdrawals
- .FirstOrDefaultAsync(w => w.TransferBillNo != "" &&
- w.Status == WithdrawalStatus.WaitConfirm);
+ .FirstOrDefaultAsync(w => w.TransferBillNo == transferBillNo && w.Status == WithdrawalStatus.WaitConfirm);
- // 通过 TransferBillNo 精确匹配
if (withdrawal == null)
{
- // 尝试从 outBillNo 解析提现 ID
- Console.WriteLine($"[转账回调] 未找到匹配的提现记录: {outBillNo}");
+ Console.WriteLine($"[转账回调] 未找到匹配的提现记录: {transferBillNo}");
return Results.Json(new { code = "SUCCESS", message = "OK" });
}
- // 根据微信回调的转账单号匹配
- withdrawal = await db.Withdrawals
- .FirstOrDefaultAsync(w => w.TransferBillNo == notifyResult.TransactionId ||
- w.Status == WithdrawalStatus.WaitConfirm);
-
if (state == "SUCCESS" || state == "ACCEPTED")
{
// 转账成功,标记提现完成
diff --git a/server/Services/WxPayService.cs b/server/Services/WxPayService.cs
index 05ed60a..b3484ba 100644
--- a/server/Services/WxPayService.cs
+++ b/server/Services/WxPayService.cs
@@ -239,6 +239,37 @@ public class WxPayService
};
}
+ ///
+ /// 解密转账回调通知(字段为 out_bill_no、transfer_bill_no、state)
+ ///
+ public TransferNotifyResult? DecryptTransferNotify(string body)
+ {
+ try
+ {
+ var json = JsonSerializer.Deserialize(body);
+ var resource = json.GetProperty("resource");
+ var ciphertext = resource.GetProperty("ciphertext").GetString()!;
+ var associatedData = resource.GetProperty("associated_data").GetString() ?? "";
+ var nonceStr = resource.GetProperty("nonce").GetString()!;
+
+ var decrypted = AesGcmDecrypt(ciphertext, nonceStr, associatedData);
+ Console.WriteLine($"[转账回调] 解密内容: {decrypted}");
+ var result = JsonSerializer.Deserialize(decrypted);
+
+ return new TransferNotifyResult
+ {
+ OutBillNo = result.TryGetProperty("out_bill_no", out var obn) ? obn.GetString() ?? "" : "",
+ TransferBillNo = result.TryGetProperty("transfer_bill_no", out var tbn) ? tbn.GetString() ?? "" : "",
+ State = result.TryGetProperty("state", out var st) ? st.GetString() ?? "" : ""
+ };
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"[微信支付] 转账回调解密失败: {ex.Message}");
+ return null;
+ }
+ }
+
///
/// 生成签名
///
@@ -315,3 +346,13 @@ public class TransferResult
public string PackageInfo { get; set; } = "";
public string State { get; set; } = "";
}
+
+///
+/// 转账回调解密结果
+///
+public class TransferNotifyResult
+{
+ public string OutBillNo { get; set; } = "";
+ public string TransferBillNo { get; set; } = "";
+ public string State { get; set; } = "";
+}
diff --git a/server/appsettings.json b/server/appsettings.json
index ca04acc..daefd41 100644
--- a/server/appsettings.json
+++ b/server/appsettings.json
@@ -45,5 +45,5 @@
"Username": "admin",
"Password": "admin123"
},
- "BaseUrl": "https://your-domain.com"
+ "BaseUrl": "https://api.zwz.shhmkjgs.cn"
}