Files
g.hnyhua.cn/Mtxfw.Utility/WXPay.Refund.cs
2026-02-07 15:48:27 +08:00

42 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Web;
namespace Mtxfw.Utility
{
public class Refund
{
/***
* 申请退款完整业务流程逻辑
* @param transaction_id 微信订单号(优先使用)
* @param out_trade_no 商户订单号
* @param total_fee 订单总金额
* @param refund_fee 退款金额
* @return 退款结果xml格式
*/
public static string Run(Mtxfw.Utility.Config config, string transaction_id, string out_trade_no, string total_fee, string refund_fee)
{
Log.Info("Refund", "Refund is processing...");
WxPayData data = new WxPayData();
if (!string.IsNullOrEmpty(transaction_id))//微信订单号存在的条件下,则已微信订单号为准
{
data.SetValue("transaction_id", transaction_id);
}
else//微信订单号不存在,才根据商户订单号去退款
{
data.SetValue("out_trade_no", out_trade_no);
}
data.SetValue("total_fee", int.Parse(total_fee));//订单总金额
data.SetValue("refund_fee", int.Parse(refund_fee));//退款金额
data.SetValue("out_refund_no", WxPayApi.GenerateOutTradeNo(config));//随机生成商户退款单号
data.SetValue("op_user_id", config.webPARTNER);//操作员,默认为商户号
WxPayData result = WxPayApi.Refund(config,data);//提交退款申请给API接收返回数据
Log.Info("Refund", "Refund process complete, result : " + result.ToXml());
return result.ToPrintStr();
}
}
}