/// <summary> /// APP支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public Task <WeChatMiniPayOutput> WeChatMiniPay(WeChatMiniPayInput input) { var allinpayDefaultClient = new AllinpayDefaultClient(_allinpaySettings.CusId, _allinpaySettings.AppId, _allinpaySettings.AppKey); var response = allinpayDefaultClient.WeChatMiniPay(input); if (response.RetCode == "FAIL") { LoggerAction?.Invoke("Error", "通联支付请求参数错误"); throw new Exception("通联支付请求参数错误,请检查!"); } return(Task.FromResult(new WeChatMiniPayOutput { Response = response })); }
/// <summary> /// 支付回调通知处理 /// </summary> /// <param name="dic"></param> /// <returns></returns> public bool PayNotifyHandler(Dictionary <string, string> dic) { try { var alipaySignPublicKey = _alipaySettings.AlipaySignPublicKey; var charset = _alipaySettings.CharSet; var signtype = _alipaySettings.SignType; var flag = AlipaySignature.RSACheckV1(dic, alipaySignPublicKey, charset, signtype, false); return(flag); } catch (Exception e) { LoggerAction?.Invoke("Error", e.Message); return(false); } }
/// <summary> /// 支付回调通知处理 /// </summary> /// <param name="dic"></param> /// <returns></returns> public bool PayNotifyHandler(Dictionary <string, string> dic) { try { var allinpayKey = _allinpaySettings.AppKey; if (!dic.ContainsKey("sign"))//如果不包含sign,则不进行处理 { LoggerAction?.Invoke("Error", "sign is null"); return(false); } return(AllinpayUtil.ValidSign(dic, allinpayKey)); } catch (Exception e) { LoggerAction?.Invoke("Error", e.Message); return(false); } }
/// <summary> /// JSAPI支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public Task <JsApiPayOutput> WeChatJsApiPay(JsApiPayInput input) { var allinpayDefaultClient = new AllinpayDefaultClient(_allinpaySettings); var response = allinpayDefaultClient.WeChatJsApiPay(input); if (response.RetCode == "FAIL") { LoggerAction?.Invoke("Error", "通联支付请求参数错误(FAIL):" + _allinpaySettings); LoggerAction?.Invoke("Error", "input:" + input); LoggerAction?.Invoke("Error", "RetMsg:" + response.RetMsg + " ErrMsg:" + response.ErrMsg); throw new Exception("通联支付请求参数错误,请检查!"); } return(Task.FromResult(new JsApiPayOutput { Response = response })); }
/// <summary> /// 支付回调 /// </summary> /// <param name="dic"></param> /// <returns></returns> public bool PayNotifyHandler(Dictionary <string, string> dic) { try { var sArray = new SortedDictionary <string, string>(); foreach (var item in dic) { sArray.Add(item.Key, item.Value); } var aliNotify = new NotifyHelper(); var verifyResult = aliNotify.Verify(sArray, dic["notify_id"], dic["sign"], _alipaySettings); return(verifyResult); } catch (Exception e) { LoggerAction?.Invoke("Error", e.Message); return(false); } }
/// <summary> /// Wap支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public Task <WapPayOutput> WapPay(WapPayInput input) { var client = GetClient(); var request = new AlipayTradeWapPayRequest(); var model = new AlipayTradeWapPayModel { 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_WAP_WAY", PromoParams = input.PromoParams, //SpecifiedChannel StoreId = input.StoreId, Subject = input.Subject, TimeoutExpress = input.TimeoutExpress, TotalAmount = input.TotalAmount.ToString(CultureInfo.InvariantCulture), QuitUrl = input.QuitUrl }; request.SetBizModel(model); request.SetNotifyUrl(input.NotifyUrl ?? alipaySettings.Notify); var response = client.pageExecute(request); if (response.IsError) { LoggerAction?.Invoke("Error", "支付宝支付请求参数错误:" + JsonConvert.SerializeObject(model)); throw new AlipayExcetion("支付宝支付请求参数错误,请检查!"); } return(Task.FromResult(new WapPayOutput { Body = response.Body })); }
private DefaultAopClient GetClient() { try { var client = new DefaultAopClient( alipaySettings.Gatewayurl, alipaySettings.AppId, alipaySettings.PrivateKey, "json", "1.0", alipaySettings.SignType, alipaySettings.AlipayPublicKey, alipaySettings.CharSet, alipaySettings.IsKeyFromFile); return(client); } catch (Exception ex) { LoggerAction?.Invoke("Error", "支付宝配置错误:"); throw new AlipayExcetion("支付宝配置错误,请检查!", ex); } }
/// <inheritdoc /> /// <summary> /// 网站支付 /// </summary> /// <param name="input"></param> /// <returns></returns> public Task <PayOutput> Pay(PayInput input) { //把请求参数打包成数组 var sParaTemp = new SortedDictionary <string, string> { { "service", "create_forex_trade" }, { "partner", _alipaySettings.Partner }, { "_input_charset", _alipaySettings.CharSet.ToUpper() }, { "sign_type", _alipaySettings.SignType }, { "notify_url", input.NotifyUrl ?? _alipaySettings.Notify }, { "return_url", input.ReturnUrl ?? _alipaySettings.ReturnUrl }, { "currency", input.Currency ?? _alipaySettings.Currency }, { "out_trade_no", input.TradeNo ?? Guid.NewGuid().ToString("N") }, { "subject", input.Subject }, { "product_code", "NEW_OVERSEAS_SELLER" }, }; if (!string.IsNullOrWhiteSpace(input.Body)) { //商品信息,不支持特殊字符。格式:[{"goods_name":"名称1","quantity":"数量1"},{"goods_name":"名称2","quantity":"数量2"}]。 if (!input.Body.StartsWith("[")) { input.Body = JsonConvert.SerializeObject(new List <object>() { new { goods_name = input.Body, quantity = 1 } }); } sParaTemp.Add("body", input.Body); } if (input.RmbFee > 0) { sParaTemp.Add("rmb_fee", input.RmbFee.ToString()); } else { sParaTemp.Add("total_fee", input.TotalFee.ToString()); } if (!string.IsNullOrWhiteSpace(input.TimeoutRule)) { sParaTemp.Add("timeout_rule", input.TimeoutRule); } if (!string.IsNullOrWhiteSpace(input.AuthToken)) { sParaTemp.Add("auth_token", input.AuthToken); } if (!string.IsNullOrWhiteSpace(input.Supplier)) { sParaTemp.Add("supplier", input.Supplier); } if (!string.IsNullOrWhiteSpace(input.SecondaryMerchantId)) { sParaTemp.Add("secondary_merchant_id", input.SecondaryMerchantId); } if (!string.IsNullOrWhiteSpace(input.SecondaryMerchantName)) { sParaTemp.Add("secondary_merchant_name", input.SecondaryMerchantName); } if (!string.IsNullOrWhiteSpace(input.SecondaryMerchantIndustry)) { sParaTemp.Add("secondary_merchant_industry", input.SecondaryMerchantIndustry); } if (input.OrderGmtCreate.HasValue) { sParaTemp.Add("order_gmt_create", input.OrderGmtCreate.Value.ToString("yyyy-MM-dd hh:mm:ss")); } if (input.OrderValidTime.HasValue && input.OrderValidTime > 0) { sParaTemp.Add("order_valid_time", input.OrderValidTime.Value.ToString()); } #region 设置分账信息 if (input.SplitFundInfo != null && input.SplitFundInfo.Count > 0) { foreach (var splitFundInfoDto in input.SplitFundInfo) { if (input.RmbFee > 0) { splitFundInfoDto.Currency = "CNY"; } else { splitFundInfoDto.Currency = input.Currency ?? _alipaySettings.Currency; } } //分账信息 sParaTemp.Add("split_fund_info", Newtonsoft.Json.JsonConvert.SerializeObject(input.SplitFundInfo)); } else if (_alipaySettings.SplitFundInfo != null && _alipaySettings.SplitFundInfo.Count > 0) { input.SplitFundInfo = new List <SplitFundInfoDto>(); foreach (var splitFundInfo in _alipaySettings.SplitFundInfo) { var splitFundInfoDto = new SplitFundInfoDto() { Desc = splitFundInfo.Desc, TransIn = splitFundInfo.TransIn }; if (input.RmbFee > 0) { splitFundInfoDto.Currency = "CNY"; } else { splitFundInfoDto.Currency = input.Currency ?? _alipaySettings.Currency; } if (splitFundInfo.AmountRate > 0) { var amount = input.TotalFee > 0 ? input.TotalFee : input.RmbFee; //日元取整数,其他的保留两位小数 splitFundInfoDto.Amount = splitFundInfoDto.Currency == "JPY" ? decimal.Floor(splitFundInfo.AmountRate * amount) : decimal.Round(splitFundInfo.AmountRate * amount, 2); } } //分账信息 sParaTemp.Add("split_fund_info", Newtonsoft.Json.JsonConvert.SerializeObject(input.SplitFundInfo)); } #endregion //过滤签名参数数组 sParaTemp.FilterPara(); var dic = sParaTemp.BuildRequestPara(_alipaySettings); LoggerAction?.Invoke("Debug", "支付参数:" + JsonConvert.SerializeObject(dic)); var html = dic.GetHtmlSubmitForm(_alipaySettings.Gatewayurl, _alipaySettings.CharSet); return(Task.FromResult(new PayOutput { FormHtml = html, Parameters = dic })); }