mirror of
https://github.com/Varorbc/PaySharp.git
synced 2026-10-19 05:51:30 +08:00
327 lines
10 KiB
C#
327 lines
10 KiB
C#
using PaySharp.Core;
|
|
using PaySharp.Core.Response;
|
|
using PaySharp.Wechatpay;
|
|
using PaySharp.Wechatpay.Domain;
|
|
using PaySharp.Wechatpay.Request;
|
|
#if NETCOREAPP
|
|
using Microsoft.AspNetCore.Mvc;
|
|
#else
|
|
using System.Web.Mvc;
|
|
#endif
|
|
using System;
|
|
|
|
namespace PaySharp.Demo.Controllers
|
|
{
|
|
public class WechatpayController : Controller
|
|
{
|
|
private readonly IGateway _gateway;
|
|
|
|
public WechatpayController(IGateways gateways)
|
|
{
|
|
_gateway = gateways.Get<WechatpayGateway>();
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult PublicPay(string out_trade_no, int total_amount, string body, string open_id)
|
|
{
|
|
var request = new PublicPayRequest();
|
|
request.AddGatewayData(new PublicPayModel()
|
|
{
|
|
Body = body,
|
|
OutTradeNo = out_trade_no,
|
|
TotalAmount = total_amount,
|
|
OpenId = open_id
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult AppPay(string out_trade_no, int total_amount, string body)
|
|
{
|
|
var request = new AppPayRequest();
|
|
request.AddGatewayData(new AppPayModel()
|
|
{
|
|
Body = body,
|
|
TotalAmount = total_amount,
|
|
OutTradeNo = out_trade_no
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult AppletPay(string out_trade_no, int total_amount, string body, string open_id)
|
|
{
|
|
var request = new AppletPayRequest();
|
|
request.AddGatewayData(new AppletPayModel()
|
|
{
|
|
Body = body,
|
|
OutTradeNo = out_trade_no,
|
|
TotalAmount = total_amount,
|
|
OpenId = open_id
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult WapPay(string out_trade_no, int total_amount, string body, string scene_info)
|
|
{
|
|
var request = new WapPayRequest();
|
|
request.AddGatewayData(new WapPayModel()
|
|
{
|
|
Body = body,
|
|
TotalAmount = total_amount,
|
|
OutTradeNo = out_trade_no,
|
|
SceneInfo = scene_info
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult ScanPay(string out_trade_no, string body, int total_amount)
|
|
{
|
|
var request = new ScanPayRequest();
|
|
request.AddGatewayData(new ScanPayModel()
|
|
{
|
|
Body = body,
|
|
TotalAmount = total_amount,
|
|
OutTradeNo = out_trade_no
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult BarcodePay(string out_trade_no, string auth_code, int total_amount, string body)
|
|
{
|
|
var request = new BarcodePayRequest();
|
|
request.AddGatewayData(new BarcodePayModel()
|
|
{
|
|
Body = body,
|
|
TotalAmount = total_amount,
|
|
OutTradeNo = out_trade_no,
|
|
AuthCode = auth_code
|
|
});
|
|
request.PaySucceed += BarcodePay_PaySucceed;
|
|
request.PayFailed += BarcodePay_PayFaild;
|
|
|
|
var response = _gateway.Execute(request);
|
|
|
|
return Json(response);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 支付成功事件
|
|
/// </summary>
|
|
/// <param name="response">返回结果</param>
|
|
/// <param name="message">提示信息</param>
|
|
private void BarcodePay_PaySucceed(IResponse response, string message)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 支付失败事件
|
|
/// </summary>
|
|
/// <param name="response">返回结果,可能是BarcodePayResponse/QueryResponse</param>
|
|
/// <param name="message">提示信息</param>
|
|
private void BarcodePay_PayFaild(IResponse response, string message)
|
|
{
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Query(string out_trade_no, string trade_no)
|
|
{
|
|
var request = new QueryRequest();
|
|
request.AddGatewayData(new QueryModel()
|
|
{
|
|
TradeNo = trade_no,
|
|
OutTradeNo = out_trade_no
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Refund(string out_trade_no, string trade_no, int total_amount, int refund_amount, string refund_desc, string out_refund_no)
|
|
{
|
|
var request = new RefundRequest();
|
|
request.AddGatewayData(new RefundModel()
|
|
{
|
|
TradeNo = trade_no,
|
|
RefundAmount = refund_amount,
|
|
RefundDesc = refund_desc,
|
|
OutRefundNo = out_refund_no,
|
|
TotalAmount = total_amount,
|
|
OutTradeNo = out_trade_no
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult RefundQuery(string out_trade_no, string trade_no, string out_refund_no, string refund_no)
|
|
{
|
|
var request = new RefundQueryRequest();
|
|
request.AddGatewayData(new RefundQueryModel()
|
|
{
|
|
TradeNo = trade_no,
|
|
OutTradeNo = out_trade_no,
|
|
OutRefundNo = out_refund_no,
|
|
RefundNo = refund_no
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Close(string out_trade_no)
|
|
{
|
|
var request = new CloseRequest();
|
|
request.AddGatewayData(new CloseModel()
|
|
{
|
|
OutTradeNo = out_trade_no
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Cancel(string out_trade_no)
|
|
{
|
|
var request = new CancelRequest();
|
|
request.AddGatewayData(new CancelModel()
|
|
{
|
|
OutTradeNo = out_trade_no
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Transfer(string out_trade_no, string openid, string check_name, string true_name, int amount, string desc)
|
|
{
|
|
var request = new TransferRequest();
|
|
request.AddGatewayData(new TransferModel()
|
|
{
|
|
OutTradeNo = out_trade_no,
|
|
OpenId = openid,
|
|
Amount = amount,
|
|
Desc = desc,
|
|
CheckName = check_name,
|
|
TrueName = true_name
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult TransferQuery(string out_trade_no)
|
|
{
|
|
var request = new TransferQueryRequest();
|
|
request.AddGatewayData(new TransferQueryModel()
|
|
{
|
|
OutTradeNo = out_trade_no
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult PublicKey()
|
|
{
|
|
var request = new PublicKeyRequest();
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult TransferToBank(string out_trade_no, string bank_no, string true_name, string bank_code, int amount, string desc)
|
|
{
|
|
var request = new TransferToBankRequest();
|
|
request.AddGatewayData(new TransferToBankModel()
|
|
{
|
|
OutTradeNo = out_trade_no,
|
|
BankNo = bank_no,
|
|
Amount = amount,
|
|
Desc = desc,
|
|
BankCode = bank_code,
|
|
TrueName = true_name
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult TransferToBankQuery(string out_trade_no)
|
|
{
|
|
var request = new TransferToBankQueryRequest();
|
|
request.AddGatewayData(new TransferToBankQueryModel()
|
|
{
|
|
OutTradeNo = out_trade_no
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult BillDownload(string bill_date, string bill_type)
|
|
{
|
|
var request = new BillDownloadRequest();
|
|
request.AddGatewayData(new BillDownloadModel()
|
|
{
|
|
BillDate = bill_date,
|
|
BillType = bill_type
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return File(response.GetBillFile(), "text/csv", $"{DateTime.Now.ToString("yyyyMMddHHmmss")}.csv");
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult FundFlowDownload(string bill_date, string account_type)
|
|
{
|
|
var request = new FundFlowDownloadRequest();
|
|
request.AddGatewayData(new FundFlowDownloadModel()
|
|
{
|
|
BillDate = bill_date,
|
|
AccountType = account_type
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return File(response.GetBillFile(), "text/csv", $"{DateTime.Now.ToString("yyyyMMddHHmmss")}.csv");
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult OAuth(string code)
|
|
{
|
|
var request = new OAuthRequest();
|
|
request.AddGatewayData(new OAuthModel()
|
|
{
|
|
Code = code
|
|
});
|
|
|
|
var response = _gateway.Execute(request);
|
|
return Json(response);
|
|
}
|
|
}
|
|
}
|