public JsonResult Charge(string pluginId, decimal amount, bool ispresent = false) { amount = Math.Round(amount, 2); if (amount <= 0) { return(Json(new { success = false, msg = "请输入正确的金额" })); } var plugin = Core.PluginsManagement.GetPlugin <IPaymentPlugin>(pluginId); var chargeDetail = new DTO.ChargeDetail(); chargeDetail.ChargeAmount = amount; chargeDetail.ChargeStatus = ChargeDetailInfo.ChargeDetailStatus.WaitPay; chargeDetail.ChargeWay = PaymentApplication.GetForeGroundPaymentName(plugin.PluginInfo.Description); chargeDetail.CreateTime = DateTime.Now; chargeDetail.MemId = CurrentUser.Id; if (ispresent && SiteSettings.IsOpenRechargePresent) { var rule = RechargePresentRuleApplication.GetRules().FirstOrDefault(d => d.ChargeAmount == amount); if (rule != null) { chargeDetail.PresentAmount = rule.PresentAmount; } } var id = MemberCapitalApplication.AddChargeApply(chargeDetail); string openId = Core.Helper.WebHelper.GetCookie(CookieKeysCollection.HIMALL_USER_OpenID); if (!string.IsNullOrWhiteSpace(openId)) { openId = Core.Helper.SecureHelper.AESDecrypt(openId, "Mobile"); } else { var openUserInfo = Application.MemberApplication.GetMemberOpenIdInfoByuserId(CurrentUser.Id, Entities.MemberOpenIdInfo.AppIdTypeEnum.Payment); if (openUserInfo != null) { openId = openUserInfo.OpenId; } } string webRoot = Request.Url.Scheme + "://" + Request.Url.Authority; string notifyUrl = webRoot + "/m-" + PlatformType + "/Payment/CapitalChargeNotify/" + plugin.PluginInfo.PluginId.Replace(".", "-") + "/"; string returnUrl = webRoot + "/m-" + PlatformType + "/Capital/Index"; var requestUrl = plugin.Biz.GetRequestUrl(returnUrl, notifyUrl, id.ToString(), amount, "会员充值", openId); return(Json(new { href = requestUrl, success = true })); }
public object PostCharge(PaymentChargeModel para) { para.amount = Math.Round(para.amount, 2); if (para.amount <= 0) { return(Json(ErrorResult <dynamic>("请输入正确的金额"))); } if (string.IsNullOrWhiteSpace(para.openId)) { return(Json(ErrorResult <dynamic>("缺少OpenId"))); } try { //获取支付插件 var mobilePayments = Core.PluginsManagement.GetPlugins <IPaymentPlugin>(true).Where(item => item.Biz.SupportPlatforms.Contains(Core.PlatformType.WeiXinSmallProg)); if (mobilePayments.Any()) { var plugin = mobilePayments.Where(x => x.PluginInfo.PluginId.Contains(para.typeId)).FirstOrDefault(); //添加充值明细 var chargeDetail = new DTO.ChargeDetail(); chargeDetail.ChargeAmount = para.amount; chargeDetail.ChargeStatus = ChargeDetailInfo.ChargeDetailStatus.WaitPay; chargeDetail.ChargeWay = PaymentApplication.GetForeGroundPaymentName(plugin.PluginInfo.Description); chargeDetail.CreateTime = DateTime.Now; chargeDetail.MemId = CurrentUser.Id; var sitesetting = SiteSettingApplication.SiteSettings; if (para.ispresent && sitesetting.IsOpenRechargePresent) { var rule = RechargePresentRuleApplication.GetRules().FirstOrDefault(d => d.ChargeAmount == para.amount); if (rule != null) { chargeDetail.PresentAmount = rule.PresentAmount; } } var id = MemberCapitalApplication.AddChargeApply(chargeDetail); string webRoot = CurrentUrlHelper.CurrentUrlNoPort(); string urlPre = webRoot + "/m-" + Core.PlatformType.Android + "/Payment/"; string notifyPre = urlPre + "CapitalChargeNotify/"; string returnPre = ""; var models = mobilePayments.ToArray().Select(item => { string url = string.Empty; try { url = item.Biz.GetRequestUrl(returnPre, notifyPre + item.PluginInfo.PluginId.Replace(".", "-") + "/", id.ToString(), para.amount, "会员充值", openId: para.openId); } catch (Exception ex) { Core.Log.Error("获取支付方式错误:", ex); } //适配小程序接口,从支付插件里解析出相应参数 //字符串格式:prepayId:234320480,partnerid:32423489,nonceStr=dslkfjsld #region 适配小程序接口,从支付插件里解析出相应参数 var prepayId = string.Empty; var nonceStr = string.Empty; var timeStamp = string.Empty; var sign = string.Empty; if (!string.IsNullOrWhiteSpace(url)) { var paras = url.Split(','); foreach (var str in paras) { var keyValuePair = str.Split(':'); if (keyValuePair.Length == 2) { switch (keyValuePair[0]) { case "prepayId": prepayId = keyValuePair[1]; break; case "nonceStr": nonceStr = keyValuePair[1]; break; case "timeStamp": timeStamp = keyValuePair[1]; break; case "sign": sign = keyValuePair[1]; break; } } } } #endregion return(new { prepayId = prepayId, nonceStr = nonceStr, timeStamp = timeStamp, sign = sign }); }); var model = models.FirstOrDefault(); if (null == model) { return(Json(ErrorResult <dynamic>("获取支付方式失败,请与管理员联系"))); } return(Json(model)); } else { Core.Log.Error("暂未配置支付方式"); return(Json(ErrorResult <dynamic>("暂未配置支付方式"))); } } catch (Exception ex) { Core.Log.Error("预账户充值报错:", ex); return(Json(ErrorResult <dynamic>("预账户充值报错"))); } }
/// <summary> /// 添加充值记录 /// </summary> /// <param name="model"></param> public static long AddChargeApply(DTO.ChargeDetail model) { return(_iMemberCapitalService.AddChargeApply(AutoMapper.Mapper.Map <Model.ChargeDetailInfo>(model))); }
/// <summary> /// 预账户充值接口 /// </summary> /// <param name="pluginId">支付插件Id</param> /// <param name="amount">充值金额</param> /// <returns></returns> public object Charge(PaymentChargeModel para) { para.amount = Math.Round(para.amount, 2); if (para.amount <= 0) { return(ErrorResult("请输入正确的金额")); } try { //获取支付插件 var mobilePayments = Core.PluginsManagement.GetPlugins <IPaymentPlugin>(true).OrderByDescending(d => d.PluginInfo.PluginId).Where(item => item.Biz.SupportPlatforms.Contains(Core.PlatformType.Android)); var plugin = mobilePayments.Where(x => x.PluginInfo.PluginId.Contains(para.typeid)).FirstOrDefault(); //添加充值明细 var chargeDetail = new DTO.ChargeDetail(); chargeDetail.ChargeAmount = para.amount; chargeDetail.ChargeStatus = ChargeDetailInfo.ChargeDetailStatus.WaitPay; //chargeDetail.ChargeWay = plugin.PluginInfo.DisplayName; chargeDetail.ChargeWay = PaymentApplication.GetForeGroundPaymentName(plugin.PluginInfo.Description); chargeDetail.CreateTime = DateTime.Now; chargeDetail.MemId = CurrentUser.Id; var sitesetting = SiteSettingApplication.SiteSettings; if (para.ispresent && sitesetting.IsOpenRechargePresent) { var rule = RechargePresentRuleApplication.GetRules().FirstOrDefault(d => d.ChargeAmount == para.amount); if (rule != null) { chargeDetail.PresentAmount = rule.PresentAmount; } } var id = MemberCapitalApplication.AddChargeApply(chargeDetail); string webRoot = CurrentUrlHelper.CurrentUrlNoPort(); string urlPre = webRoot + "/m-" + Core.PlatformType.Android + "/Payment/"; string notifyPre = urlPre + "CapitalChargeNotify/"; string returnPre = webRoot + "/m-" + Core.PlatformType.Android; var model = mobilePayments.ToArray().Select(item => { string url = string.Empty; try { url = item.Biz.GetRequestUrl(returnPre, notifyPre + item.PluginInfo.PluginId.Replace(".", "-") + "/", id.ToString(), para.amount, "会员充值"); } catch (Exception ex) { Core.Log.Error("获取支付方式错误:", ex); } return(new { id = item.PluginInfo.PluginId, //name = item.PluginInfo.DisplayName, name = PaymentApplication.GetForeGroundPaymentName(item.PluginInfo.DisplayName), logo = item.Biz.Logo, url = url }); }); model = model.Where(item => !string.IsNullOrWhiteSpace(item.url) && item.id.Contains(para.typeid)).OrderByDescending(d => d.id); dynamic result = SuccessResult(); result.data = model; return(result); } catch (Exception ex) { Core.Log.Error("预账户充值报错:", ex); return(ErrorResult("预账户充值报错")); } }
/// <summary> /// 添加充值记录 /// </summary> /// <param name="model"></param> public static long AddChargeApply(DTO.ChargeDetail model) { return(Service.AddChargeApply(AutoMapper.Mapper.Map <ChargeDetailInfo>(model))); }