This commit is contained in:
parent
9b9ba5adad
commit
50eb3996d9
|
|
@ -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")
|
||||
{
|
||||
// 转账成功,标记提现完成
|
||||
|
|
|
|||
|
|
@ -239,6 +239,37 @@ public class WxPayService
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解密转账回调通知(字段为 out_bill_no、transfer_bill_no、state)
|
||||
/// </summary>
|
||||
public TransferNotifyResult? DecryptTransferNotify(string body)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Deserialize<JsonElement>(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<JsonElement>(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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成签名
|
||||
/// </summary>
|
||||
|
|
@ -315,3 +346,13 @@ public class TransferResult
|
|||
public string PackageInfo { get; set; } = "";
|
||||
public string State { get; set; } = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转账回调解密结果
|
||||
/// </summary>
|
||||
public class TransferNotifyResult
|
||||
{
|
||||
public string OutBillNo { get; set; } = "";
|
||||
public string TransferBillNo { get; set; } = "";
|
||||
public string State { get; set; } = "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,5 +45,5 @@
|
|||
"Username": "admin",
|
||||
"Password": "admin123"
|
||||
},
|
||||
"BaseUrl": "https://your-domain.com"
|
||||
"BaseUrl": "https://api.zwz.shhmkjgs.cn"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user