private void DoValidate() { PayConfiguration config = PayConfiguration.GetConfig(); NameValueCollection parameters = new NameValueCollection(); parameters.Add(this.Page.Request.Form); parameters.Add(this.Page.Request.QueryString); string tmpGatewayName = this.Page.Request.QueryString[Globals.GATEWAY_KEY]; if (string.IsNullOrEmpty(tmpGatewayName)) { this.ResponseStatus(true, "gatewaynotfound"); return; } this.GatewayName = tmpGatewayName.ToLower(); GatewayProvider provider = config.Providers[this.GatewayName] as GatewayProvider; if (provider == null) { this.ResponseStatus(true, "gatewaynotfound"); return; } this.Notify = NotifyQuery.Instance(provider.NotifyType, parameters); if (this.isBackRequest) { this.Notify.ReturnUrl = Globals.FullPath(string.Format(Globals.PAYMENT_RETURN_URL, this.GatewayName)); } this.RechargeId = long.Parse(this.Notify.GetOrderId(), CultureInfo.InvariantCulture); this.Amount = this.Notify.GetOrderAmount(); this.RechargeRequest = PaymentModeManage.GetRechargeRequest(this.RechargeId); if (this.RechargeRequest == null) { this.ResponseStatus(true, "success"); } else { this.Amount = this.RechargeRequest.RechargeBlance; this.paymode = PaymentModeManage.GetPaymentModeByName(this.RechargeRequest.PaymentGateway); if (this.paymode == null) { this.ResponseStatus(true, "gatewaynotfound"); } else { PayeeInfo payee = new PayeeInfo { EmailAddress = this.paymode.EmailAddress, Partner = this.paymode.Partner, Password = this.paymode.Password, PrimaryKey = this.paymode.SecretKey, SecondKey = this.paymode.SecondKey, SellerAccount = this.paymode.MerchantCode }; this.Notify.PaidToIntermediary += new NotifyEventHandler(this.notify_PaidToIntermediary); this.Notify.PaidToMerchant += new NotifyEventHandler(this.notify_PaidToMerchant); this.Notify.NotifyVerifyFaild += new NotifyEventHandler(this.notify_NotifyVerifyFaild); this.Notify.VerifyNotify(0x7530, payee); } } }
private void notify_PaidToMerchant(NotifyQuery sender) { DateTime now = DateTime.Now; TradeTypes selfHelpRecharge = TradeTypes.SelfHelpRecharge; decimal num = PaymentModeManage.GetAccountSummary(this.RechargeRequest.UserId). AccountAmount + this.RechargeRequest.RechargeBlance; BalanceDetailInfo balanceDetails = new BalanceDetailInfo { JournalNumber = this.RechargeRequest.RechargeId, UserId = this.RechargeRequest.UserId, TradeDate = now, TradeType = selfHelpRecharge, Income = this.RechargeRequest.RechargeBlance, Balance = num }; if (this.paymode != null) { balanceDetails.Remark = "充值支付方式:" + this.paymode.Name; } if (PaymentModeManage.AddBalanceDetail(balanceDetails)) { this.ResponseStatus(true, "success"); } else { PaymentModeManage.RemoveRechargeRequest(this.RechargeId); this.ResponseStatus(false, "fail"); } }
protected virtual void DoValidate() { PayConfiguration config = PayConfiguration.GetConfig(); NameValueCollection parameters = new NameValueCollection(); parameters.Add(this.Page.Request.Form); parameters.Add(this.Page.Request.QueryString); string tmpGatewayName = this.Page.Request.Params[Globals.GATEWAY_KEY]; if (string.IsNullOrEmpty(tmpGatewayName)) { this.ResponseStatus(false, "gatewaynotfound"); return; } this.GatewayName = tmpGatewayName.ToLower(); GatewayProvider provider = config.Providers[this.GatewayName] as GatewayProvider; if (provider == null) { this.ResponseStatus(false, "gatewaynotfound"); return; } this.Notify = NotifyQuery.Instance(provider.NotifyType, parameters); if (this.isBackRequest) { this.Notify.ReturnUrl = Globals.FullPath(string.Format(Option.ReturnUrl, this.GatewayName)); } this.Amount = this.Notify.GetOrderAmount(); this.OrderId = this.Notify.GetOrderId(); this.Order = this.GetOrderInfo(this.OrderId); if (this.Order == null) { this.ResponseStatus(false, "ordernotfound"); } else if (this.Order.PaymentStatus == PaymentStatus.Prepaid) { this.ResponseStatus(true, "success"); } else { //设置支付网关生成的订单ID this.Order.GatewayOrderId = this.Notify.GetGatewayOrderId(); PaymentModeInfo paymentMode = this.GetPaymentMode(this.Order.PaymentTypeId); if (paymentMode == null) { this.ResponseStatus(false, "gatewaynotfound"); } else { #region 测试模式 //DONE: 测试模式埋点 if (Globals.IsPaymentTestMode) { string sign = this.Page.Request.Params["sign"]; if (string.IsNullOrWhiteSpace(sign)) { this.ResponseStatus(false, "<TestMode> no sign"); } System.Text.StringBuilder url = new System.Text.StringBuilder( Globals.FullPath(string.Format(Option.ReturnUrl, this.GatewayName))); url.AppendFormat("&out_trade_no={0}", this.OrderId); url.AppendFormat("&total_fee={0}", this.Amount); if (sign != Globals.GetMd5(System.Text.Encoding.UTF8, url.ToString())) { this.ResponseStatus(false, "<TestMode> Unauthorized sign"); } //效验通过 PaidToSite(); return; } #endregion PayeeInfo payee = new PayeeInfo { EmailAddress = paymentMode.EmailAddress, Partner = paymentMode.Partner, Password = paymentMode.Password, PrimaryKey = paymentMode.SecretKey, SecondKey = paymentMode.SecondKey, SellerAccount = paymentMode.MerchantCode }; GatewayInfo getway = new GatewayInfo { ReturnUrl = Option.ReturnUrl, NotifyUrl = Option.NotifyUrl }; this.Notify.NotifyVerifyFaild += new NotifyEventHandler(this.notify_NotifyVerifyFaild); this.Notify.PaidToIntermediary += new NotifyEventHandler(this.notify_PaidToIntermediary); this.Notify.PaidToMerchant += new NotifyEventHandler(this.notify_PaidToMerchant); this.Notify.VerifyNotify(0x7530, payee, getway); } } }
private void notify_PaidToMerchant(NotifyQuery sender) { PaidToSite(); }
private void notify_PaidToIntermediary(NotifyQuery sender) { PaidToSite(); }
private void notify_NotifyVerifyFaild(NotifyQuery sender) { this.ResponseStatus(false, "verifyfaild"); }
protected void DoValidate() { PayConfiguration config = PayConfiguration.GetConfig(); NameValueCollection parameters = new NameValueCollection(); parameters.Add(HttpContext.Current.Request.QueryString); parameters.Add(HttpContext.Current.Request.Form); string gatewayData = parameters[Globals.GATEWAY_KEY]; if (string.IsNullOrEmpty(gatewayData)) { Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " gatewaydatanotfound GATEWAYDATA IS NULL")); this.ResponseStatus(false, "gatewaydatanotfound"); return; } parameters.Remove(Globals.GATEWAY_KEY); //获取GetwayData特殊Base64数据 GetwayDatas = Globals.DecodeData4Url(gatewayData).Split(new[] { '|' }, System.StringSplitOptions.None); if (GetwayDatas.Length < 1) { Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " gatewaydatanotfound GetwayDatas.Length < 1")); this.ResponseStatus(false, "gatewaydatanotfound"); return; } this.GatewayName = GetwayDatas[0].ToLower(); GatewayProvider provider = config.Providers[this.GatewayName] as GatewayProvider; if (provider == null) { this.ResponseStatus(false, "gatewaynotfound"); Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " gatewaydatanotfound PROVIDER IS NULL")); return; } if (string.IsNullOrWhiteSpace(provider.NotifyType)) { this.ResponseStatus(false, "notifytypenotfound"); Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " gatewaydatanotfound PROVIDER.NOTIFYTYPE IS NULL")); return; } if (provider.UseNotifyMode) //DONE: 使用差异通知模式 BEN NEW MODE 20131016 { this.Notify = NotifyQuery.Instance(provider.NotifyType, parameters, _isNotify ? NotifyMode.Notify : NotifyMode.Callback); } else //回调和通知均使用同一种模式 { this.Notify = NotifyQuery.Instance(provider.NotifyType, parameters); } if (this._isNotify) { this.Notify.ReturnUrl = Globals.FullPath(string.Format(Option.ReturnUrl, gatewayData)); } #region 加载企业ID if (Components.MvcApplication.IsAutoConn) { Common.CallContextHelper.SetAutoTag(Common.Globals.SafeLong(GetwayDatas[2], 0)); } #endregion #region 测试模式 if (Globals.IsPaymentTestMode) { this._orderId = parameters["out_trade_no"]; } #endregion else { this._orderId = this.Notify.GetOrderId(); } this.Order = Option.GetOrderInfo(this._orderId); if (this.Order == null) { Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " GETORDERINFO IS NULL| ORDERID:" + this._orderId)); this.ResponseStatus(false, "ordernotfound"); return; } #region 测试模式 if (Globals.IsPaymentTestMode) { this._amount = Globals.SafeDecimal(parameters["total_fee"], -1); } #endregion else { this._amount = this.Notify.GetOrderAmount() == decimal.Zero ? this.Order.Amount : this.Notify.GetOrderAmount(); } //设置支付网关生成的订单ID this.Order.GatewayOrderId = this.Notify.GetGatewayOrderId(); PaymentMode = this.GetPaymentMode(this.Order.PaymentTypeId); if (PaymentMode == null) { Core.Globals.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " PAYMENTMODE IS NULL| PaymentTypeId:" + this.Order.PaymentTypeId)); this.ResponseStatus(false, "gatewaynotfound"); return; } if (this.Order.PaymentStatus == PaymentStatus.Prepaid) { this.ResponseStatus(true, "success"); } else { #region 测试模式 //DONE: 测试模式埋点 if (Globals.IsPaymentTestMode) { string sign = HttpContext.Current.Request.QueryString["sign"]; if (string.IsNullOrWhiteSpace(sign)) { this.ResponseStatus(false, "<TestMode> no sign"); } System.Text.StringBuilder url = new System.Text.StringBuilder( Globals.FullPath(string.Format(Option.ReturnUrl, gatewayData))); url.AppendFormat("&out_trade_no={0}", this._orderId); url.AppendFormat("&total_fee={0}", this._amount); if (sign != Globals.GetMd5(System.Text.Encoding.UTF8, url.ToString())) { this.ResponseStatus(false, "<TestMode> Unauthorized sign"); } //效验通过 PaidToSite(); return; } #endregion PayeeInfo payee = new PayeeInfo { EmailAddress = PaymentMode.EmailAddress, Partner = PaymentMode.Partner, Password = PaymentMode.Password, PrimaryKey = PaymentMode.SecretKey, SecondKey = PaymentMode.SecondKey, SellerAccount = PaymentMode.MerchantCode }; GatewayInfo getway = new GatewayInfo { Data = gatewayData, DataList = GetwayDatas.ToList(), ReturnUrl = Option.ReturnUrl, NotifyUrl = Option.NotifyUrl }; this.Notify.NotifyVerifyFaild += new NotifyEventHandler(this.notify_NotifyVerifyFaild); this.Notify.PaidToIntermediary += new NotifyEventHandler(this.notify_PaidToIntermediary); this.Notify.PaidToMerchant += new NotifyEventHandler(this.notify_PaidToMerchant); this.Notify.VerifyNotify(0x7530, payee, getway); } }
private void notify_PaidToIntermediary(NotifyQuery sender) { this.ResponseStatus(false, "waitconfirm"); }
private void notify_NotifyVerifyFaild(NotifyQuery sender) { PaymentModeManage.RemoveRechargeRequest(this.RechargeId); this.ResponseStatus(false, "verifyfaild"); }