/// <summary> /// 微信APP支付 /// </summary> /// <param name="input"></param> /// <returns></returns> //[HttpPost("AppPay/WeChat")] protected Task <AppPayOutput> WeChatAppPay(AppPayInput input) { if (WeChatPayApi == null) { throw new UserFriendlyException("支付未开放,请联系管理员!"); } var appPayInput = new WeChat.Pay.Dto.AppPayInput { Body = input.Body, OutTradeNo = input.OutTradeNo, Attach = input.CustomData, TotalFee = input.TotalAmount, SpbillCreateIp = _clientInfoProvider?.ClientIpAddress }; try { var appPayOutput = WeChatPayApi.AppPay(appPayInput); return(Task.FromResult(appPayOutput)); } catch (Exception ex) { throw new UserFriendlyException(ex.Message); } }
/// <summary> /// 支付宝APP支付 /// </summary> /// <param name="input"></param> /// <returns></returns> //[HttpPost("AppPay/Alipay")] protected async Task <string> AliAppPay(AppPayInput input) { if (AlipayAppService == null) { throw new UserFriendlyException("支付未开放,请联系管理员!"); } var appPayInput = new Alipay.Dto.AppPayInput { Body = input.Body, Subject = input.Subject, TradeNo = input.OutTradeNo, PassbackParams = input.CustomData, TotalAmount = input.TotalAmount }; try { var appPayOutput = await AlipayAppService.AppPay(appPayInput); return(appPayOutput.Response.Body); } catch (Exception ex) { throw new UserFriendlyException(ex.Message); } }
/// <summary> /// 支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public override async Task <object> ToPay(PayInputBase input) { var weChatPayApi = IocResolver.Resolve <WeChatPayApi>(); if (weChatPayApi == null) { throw new UserFriendlyException("支付未开放,请联系管理员!"); } var appPayInput = new AppPayInput() { Body = input.Body, OutTradeNo = input.OutTradeNo, Attach = input.Key, TotalFee = input.TotalAmount, SpbillCreateIp = _clientInfoProvider?.ClientIpAddress }; try { var appPayOutput = weChatPayApi.AppPay(appPayInput); return(await Task.FromResult(appPayOutput)); } catch (Exception ex) { throw new UserFriendlyException(ex.Message); } }
/// <summary> /// 支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public override async Task <object> ToPay(PayInputBase input) { var api = IocResolver.Resolve <IAlipayAppService>(); if (api == null) { throw new UserFriendlyException("支付未开放,请联系管理员!"); } var appPayInput = new AppPayInput() { Body = input.Body, Subject = input.Subject, TradeNo = input.OutTradeNo, PassbackParams = input.CustomData, TotalAmount = input.TotalAmount }; try { var appPayOutput = await api.AppPay(appPayInput); return(appPayOutput.Response.Body); } catch (Exception ex) { throw new UserFriendlyException(ex.Message); } }
/// <summary> /// APP支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public Task <AppPayOutput> AppPay(AppPayInput input) { var client = GetClient(); var request = new AlipayTradeAppPayRequest(); var model = new AlipayTradeAppPayModel { Body = input.Body, DisablePayChannels = input.DisablePayChannels, EnablePayChannels = input.EnablePayChannels, //ExtendParams = input.ex GoodsType = input.GoodsType, OutTradeNo = input.TradeNo ?? Guid.NewGuid().ToString("N"), PassbackParams = WebUtility.UrlEncode(input.PassbackParams), ProductCode = "QUICK_MSECURITY_PAY", PromoParams = input.PromoParams, //SpecifiedChannel StoreId = input.StoreId, Subject = input.Subject, TimeoutExpress = input.TimeoutExpress, TotalAmount = input.TotalAmount.ToString() }; request.SetBizModel(model); request.SetNotifyUrl(input.NotifyUrl ?? alipaySettings.Notify); var response = client.SdkExecute(request); if (response.IsError) { LoggerAction?.Invoke("Error", "支付宝支付请求参数错误:" + JsonConvert.SerializeObject(model)); throw new AlipayExcetion("支付宝支付请求参数错误,请检查!"); } return(Task.FromResult(new AppPayOutput { Response = response })); }
/// <summary> /// 支付宝APP支付 /// </summary> /// <param name="input"></param> /// <returns></returns> //[HttpPost("AppPay/GlobalAlipay")] protected async Task <PayOutput> GlobalAlipay(AppPayInput input) { if (GlobalAlipayAppService == null) { throw new UserFriendlyException("支付未开放,请联系管理员!"); } var payInput = new Alipay.Global.Dto.PayInput { Body = input.Body, Subject = input.Subject, TradeNo = input.OutTradeNo, //PassbackParams = input.CustomData, TotalFee = input.TotalAmount, }; try { return(await GlobalAlipayAppService.Pay(payInput)); } catch (Exception ex) { throw new UserFriendlyException(ex.Message); } }
/// <summary> /// APP支付 /// APP统一下单接口 /// https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1 /// </summary> /// <returns></returns> public AppPayOutput AppPay(AppPayInput input) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (input.TotalFee <= 0) { throw new ArgumentException("金额不能小于0!", nameof(input.TotalFee)); } if (string.IsNullOrWhiteSpace(input.Body)) { throw new ArgumentNullException("商品描述必须填写!", nameof(input.Body)); } if (string.IsNullOrWhiteSpace(input.SpbillCreateIp)) { throw new ArgumentNullException("终端IP必须填写!", nameof(input.SpbillCreateIp)); } var url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; var config = GetConfig(); var model = new AppUnifiedorderRequest { AppId = config.PayAppId, MchId = config.MchId, Attach = input.Attach, Body = input.Body, Detail = input.Detail, FeeType = input.FeeType, GoodsTag = input.GoodsTag, LimitPay = input.LimitPay, OutTradeNo = input.OutTradeNo ?? weChatPayHelper.GenerateOutTradeNo(), SpbillCreateIp = input.SpbillCreateIp, TimeExpire = input.TimeExpire, TimeStart = input.TimeStart, TotalFee = ((int)(input.TotalFee * 100)).ToString(), NonceStr = weChatPayHelper.GetNoncestr(), NotifyUrl = config.PayNotifyUrl }; model.Sign = CreateSign(model); var result = weChatPayHelper.PostXML <UnifiedorderResult>(url, model); if (result.IsSuccess()) { var data = new { appid = result.AppId, noncestr = result.NonceStr, partnerid = result.Mch_Id, prepayid = result.PrepayId, package = "Sign=WXPay", timestamp = weChatPayHelper.GetTimestamp() }; return(new AppPayOutput { AppId = data.appid, MchId = model.MchId, PrepayId = result.PrepayId, NonceStr = data.noncestr, PaySign = weChatPayHelper.CreateMd5Sign(weChatPayHelper.GetDictionaryByType(data), config.TenPayKey), SignType = "MD5", TimeStamp = data.timestamp, Package = data.package }); } WeChatPayHelper.LoggerAction("Error", "支付错误:" + result.GetFriendlyMessage()); throw new WeChatPayException("支付错误,请联系客服或重新支付!"); }