Core(微信、⽀付宝⽀付异步回调通知)
public ActionResult WxPayNotify()
{
log.AddPayLog("WxPayNotify", "开始调⽤接⼝");
string returnCode = "FAIL";
string returnMsg = "FAIL";
string result = "<xml><return_code><![CDATA[{0}]]></return_code><return_msg><![CDATA[{1}]]></return_msg></xml>";
try
{
log.AddPayLog("WxPayNotify", "--------微信回调--开始--------");
NLoggerHelper.Default.Info("WxPayNotify---微信回调--开始");
ResponHandler resHandler = new ResponHandler(HttpContext);
WxPayNotify notify = new WxPayNotify(resHandler);
NLoggerHelper.Default.Info("WxPayNotify---微信回调--通知参数---" + notify.ToJson());
log.AddPayLog("WxPayNotify", "--------微信回调--通知参数--------" + notify.ToJson());
int tenantId = 0;
if (!notify.Attach.IsNullOrEmpty() && notify.Attach.Split('-').Length > 2)
{
tenantId = notify.Attach.Split('-')[1].ToInt32();
}
bool safe = notify.IsSafe();
if (safe)
{
if (notify.ResultCode.ToLower() == "success")
{
string orderType = string.Empty;
if (!notify.Attach.IsNullOrEmpty())
{
string[] arr = notify.Attach.Split('-');
if (arr.Length >= 2)
{
orderType = arr[0];
}
}
if (orderType == PayOrderType.RechargeOrder.ToString())
{
//充值
decimal tradeAmount = notify.TotalFee / 100m;
bool success = HandleRechargeOrderNotify(notify.OutTradeNo, notify.TransactionId, tradeAmount, notify.TimeEnd, PayWay.WxPay, noti fy.ToJson());
if (success)
{
returnCode = "SUCCESS";
returnMsg = "OK";
}
}
el
{
NLoggerHelper.Default.Info("WxPayNotify---微信回调--未知订单类型");
log.AddPayLog("WxPayNotify", "--------微信回调--未知订单类型--------");
}
}
el
{
NLoggerHelper.Default.Info("WxPayNotify---微信回调--交易失败");
log.AddPayLog("WxPayNotify", "--------微信回调--交易失败--------");
}
慕振飞}
el
{
NLoggerHelper.Default.Info("WxPayNotify---微信回调--参数安全认证失败");
log.AddPayLog("WxPayNotify", "--------微信回调--参数安全认证失败--------");
}
result = string.Format(result, returnCode, returnMsg);
NLoggerHelper.Default.Info("WxPayNotify---微信回调--结束:" + result);
log.AddPayLog("WxPayNotify", "--------微信回调--结束--------" + result);
}
catch (Exception ex)
{
NLoggerHelper.Default.Info("WxPayNotify---微信回调--异常:" + ex.ToString());
log.AddPayLog("WxPayNotify", "--------微信回调--异常:" + ex.ToString());
}
return Content(result, "text/xml");
}
public ActionResult AliPayNotify()
{
string result = "fail";
try
{
NLoggerHelper.Default.Info("AliPayNotify---⽀付宝回调---开始");
log.AddPayLog("AliPayNotify", "--------⽀付宝回调--开始--------");
var httpRequest = HttpContext.Request;
AliPayNotify notify = new AliPayNotify(httpRequest);
NLoggerHelper.Default.Info("AliPayNotify---⽀付宝回调---通知参数---" + notify.ToJson());
log.AddPayLog("AliPayNotify", "--------⽀付宝回调--通知参数--------" + notify.ToJson());
if (notify.IsSafe)
{治疗肺结核的药物
//交易⽀付成功
if (notify.TradeStatus == AliPayTradeStatus.TRADE_SUCCESS.ToString())
{
string orderType = string.Empty;
if (!notify.PassbackParams.IsNullOrEmpty())
{
string[] arr = notify.PassbackParams.Split('-');
if (arr.Length >= 2)
{
翦的拼音orderType = arr[0];
}
}
el
{
string[] arr = notify.Body.Split('-');
if (arr.Length >= 2)
{
orderType = arr[0];
}
}
if (orderType == PayOrderType.RechargeOrder.ToString())
{
//充值
bool success = HandleRechargeOrderNotify( notify.OutTradeNo, notify.TradeNo, notify.TotalAmount, notify.GmtPayment, PayWay.AliPay , notify.ToJson());
if (success)
{
result = "success";
}
}
el
{
NLoggerHelper.Default.Info("AliPayNotify---⽀付宝回调--未知订单类型");
log.AddPayLog("AliPayNotify", "--------⽀付宝回调--未知订单类型--------");
}
}
el
{
NLoggerHelper.Default.Info("AliPayNotify---⽀付宝回调--交易失败");
log.AddPayLog("AliPayNotify", "--------⽀付宝回调--交易失败--------");
}
}
泰伯墓
el
{
NLoggerHelper.Default.Info("AliPayNotify---⽀付宝回调--参数安全认证失败");
log.AddPayLog("AliPayNotify", "--------⽀付宝回调--参数安全认证失败--------");
}
log.AddPayLog("AliPayNotify", "--------⽀付宝回调--结束--------" + result);
}
catch (Exception ex)
{
NLoggerHelper.Default.Info("AliPayNotify---⽀付宝回调--异常:" + ex.ToString());
}
return Content(result);
}
相关类:
public class AliPayNotify
{
HttpRequest request = null;
public AliPayNotify(HttpRequest httpRequest)
{
request = httpRequest;
}
public bool IsSafe {
get {
bool safe = fal;
//验证商户
if (AppId == AliPay.AppId)
{
/
/获取当前请求中的post参数
var dict = new Dictionary<string, string>();
var keys = request.Form.Keys;
if (keys != null)
{
foreach (string key in keys)
{
dict.Add(key, request.Form[key]);
}
}
if (dict.Count > 0)
{
safe = AlipaySignature.RSACheckV1(dict, AliPay.AliPublicKey, AliPay.Chart, AliPay.SignType, fal); }
}
return safe;
}
}
#region 通知参数
/// <summary>
/// 通知时间
/// </summary>
public DateTime NotifyTime {
get {
return Convert.ToDateTime(request.Form["notify_time"]); }
}
/// <summary>
/// 通知类型
/// </summary>
public string NotifyType {
get {
return request.Form["notify_type"];
}
}
/
// <summary>
/// 通知校验id
/// </summary>
public string NotifyId {
get {
return request.Form["notify_id"];
}
}
/// <summary>
/// ⽀付宝分配给开发者的应⽤Id
/// </summary>
public string AppId {
get {
return request.Form["app_id"];
}
}
/// <summary>
/// 编码格式,如utf-8、gbk、gb2312等
/// </summary>
public string Chart {
get {
return request.Form["chart"];
}
}
/// <summary>
/// 调⽤的接⼝版本
/// </summary>
public string Version {
星海虹城
get {
return request.Form["version"];
}
}
/// <summary>
/
// 签名类型
/// </summary>
public string SignType {
get {
return request.Form["sign_type"];
}
}
/// <summary>
/// 签名
/// </summary>
public string Sign {
get {
高考数学考纲return request.Form["sign"];
}
}
/// <summary>
/// ⽀付宝交易号
/// </summary>
public string TradeNo {
get {
return request.Form["trade_no"];
}
十全九美
}
/// <summary>
卑微的自己/// 商户订单号
/// </summary>
public string OutTradeNo {
get {
return request.Form["out_trade_no"];
}
}
/// <summary>
/// 商户业务号,主要是退款通知中返回退款申请的流⽔号
/
// </summary>
public string OutBizNo {
get {
return request.Form["out_biz_no"];
}
}
/// <summary>
/// 买家⽀付宝⽤户号
/// </summary>
public string BuyerId {
get {
return request.Form["buyer_id"];
}
}
/// <summary>
/// 买家⽀付宝账号
/// </summary>
public string BuyerLogonId {
get {
return request.Form["buyer_logon_id"];
}
}
/
// <summary>
/// 卖家⽀付宝⽤户号
/// </summary>
public string SellerId {
get {
return request.Form["ller_id"];
}
}
/// <summary>
/// 卖家⽀付宝账号
/// </summary>
public string SellerEmail {
get {
return request.Form["ller_email"];
}
}
/// <summary>
/// 交易状态 WAIT_BUYER_PAY 交易创建,等待买家付款, TRADE_CLOSED 未付款交易超时关闭,或⽀付完成后全额退款, TRADE_SUCCESS 交易⽀付成功, TRADE_FINISHED 交易结束,不可退款
/// </summary>
public string TradeStatus {
get {
return request.Form["trade_status"];
}
}
/// <summary>
/// 订单⾦额(元)
/// </summary>
public decimal TotalAmount {