Skip to content

Commit

Permalink
修改BasePayApis 此类型不再为静态类 使用ISenparcWeixinSettingForTenpayV3初始化实例
Browse files Browse the repository at this point in the history
  • Loading branch information
RockRockWhite committed Aug 22, 2021
1 parent 16e5ee8 commit b4b351e
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.AspNetCore.Mvc;
using Senparc.CO2NET.Extensions;
using Senparc.CO2NET.Utilities;
using Senparc.Weixin.Entities;
using Senparc.Weixin.Exceptions;
using Senparc.Weixin.Helpers;
using Senparc.Weixin.MP;
Expand Down Expand Up @@ -57,6 +58,19 @@ public static TenPayV3Info TenPayV3Info
}
}

/// <summary>
/// 用于初始化BasePayApis
/// </summary>
private readonly ISenparcWeixinSettingForTenpayV3 _tenpayV3Setting;

private readonly BasePayApis _basePayApis;

public TenPayRealV3Controller()
{
_tenpayV3Setting = Senparc.Weixin.Config.SenparcWeixinSetting.TenpayV3Setting;
_basePayApis = new BasePayApis(_tenpayV3Setting);
}

/// <summary>
/// 获取用户的OpenId
/// </summary>
Expand Down Expand Up @@ -191,7 +205,7 @@ public async Task<IActionResult> JsApi(int productId, int hc)

//var result = TenPayOldV3.Unifiedorder(xmlDataInfo);//调用统一订单接口
//JsSdkUiPackage jsPackage = new JsSdkUiPackage(TenPayV3Info.AppId, timeStamp, nonceStr,);
var result = await BasePayApis.JsApiAsync(jsApiRequestData);
var result = await _basePayApis.JsApiAsync(jsApiRequestData);
var package = string.Format("prepay_id={0}", result.prepay_id);

ViewData["product"] = product;
Expand Down Expand Up @@ -356,7 +370,7 @@ public async Task<IActionResult> Refund()
//#region 新方法(Senparc.Weixin v6.4.4+)
//var result = TenPayOldV3.Refund(_serviceProvider, dataInfo);//证书地址、密码,在配置文件中设置,并在注册微信支付信息时自动记录
//#endregion
var result = await BasePayApis.RefundAsync(dataInfo);
var result = await _basePayApis.RefundAsync(dataInfo);

WeixinTrace.SendCustomLog("进入退款流程", "3 Result:" + result.ToJson());
ViewData["Message"] = $"退款结果:{result.status} {result.ResultCode}。您可以刷新当前页面查看最新结果。";
Expand Down Expand Up @@ -485,11 +499,11 @@ public async Task<IActionResult> OrderQuery(string out_trade_no = null, string t
//选择方式查询订单
if (out_trade_no is not null)
{
result = await BasePayApis.OrderQueryByOutTradeNoAsync(out_trade_no, TenPayV3Info.MchId);
result = await _basePayApis.OrderQueryByOutTradeNoAsync(out_trade_no, TenPayV3Info.MchId);
}
if (transaction_id is not null)
{
result = await BasePayApis.OrderQueryByTransactionIdAsync(transaction_id, TenPayV3Info.MchId);
result = await _basePayApis.OrderQueryByTransactionIdAsync(transaction_id, TenPayV3Info.MchId);
}

return Json(result);
Expand All @@ -509,7 +523,7 @@ public async Task<IActionResult> CloseOrder(string out_trade_no)
}

ReturnJsonBase result = null;
result = await BasePayApis.CloseOrderAsync(out_trade_no, TenPayV3Info.MchId);
result = await _basePayApis.CloseOrderAsync(out_trade_no, TenPayV3Info.MchId);

return Json(result);
}
Expand Down

0 comments on commit b4b351e

Please sign in to comment.