//bool isClientIpOk() //{ // if (this.clientIp == null || this.clientIp.Length == 0) // return true; // else return viviLib.Text.Validate.IsIPSect(clientIp); //} /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { string error = string.Empty, apikey = ""; bool riskWarning = true; ////IP验证 //if (!string.IsNullOrEmpty(this.clientIp)) //{ // if (viviLib.Web.IPHelper.GetValue(this.clientIp) != viviLib.Web.IPHelper.GetValue(viviLib.Web.ServerVariables.TrueIP)) // { // return; // } //} #region Step1 必要的参数不能为空 if (string.IsNullOrEmpty(this.userid)) { error = "error:1001 商户ID(userid)不能空!"; } else if (string.IsNullOrEmpty(bankid)) { error = "error:1002 银行编号(bankid)不能空!"; } else if (string.IsNullOrEmpty(money)) { error = "error:1003 订单金额(money)不能空!"; } else if (string.IsNullOrEmpty(orderid)) { error = "error:1004 商户订单号(orderid)不能空!"; } else if (string.IsNullOrEmpty(notifyurl)) { error = "error:1005 商户接收后台返回储值结果的地址(url)不能空!"; } /*else if (string.IsNullOrEmpty(version)) * { * error = "error:1006 版本号(version)不能空!"; * }*/ else if (string.IsNullOrEmpty(sign)) { error = "error:1006 签名数据(sign)不能空!"; } #endregion #region Step2 检查参数长度 else if (userid.Length > 10) { error = "error:1020 商户ID(userid)长度超过5位!"; } else if (bankid.Length > 5) { error = "error:1021 银行编号(bankid)长度超过4位!"; } else if (orderid.Length > 30) { error = "error:1022 商户订单号(orderid)长度超过30位!"; } else if (money.Length > 8) { error = "error:1023 订单金额(money)长度超过最长限制!"; } else if (this.notifyurl.Length > 255) { error = "error:1024 商户接收后台返回储值结果的地址(url)长度超过255位!"; } else if (this.returnurl.Length > 255) { error = "error:1025 下行同步通知地址(aurl)长度超过255位!"; } //else if (this.clientIp.Length > 20) //{ // error = "error:1026 支付用户IP(payerIp)长度超过20位!"; //} else if (this.attach.Length > 255) { error = "error:1027 备注消息(attach)长度超过255位!"; } else if (this.sign.Length != 32) { error = "error:1028 签名(sign)长度不正确!"; } #endregion #region Step3 格式验证 else if (!viviLib.Text.Validate.IsNumeric(userid)) { error = "error:1040 商户ID(userid)格式不正确!"; } else if (!viviLib.Text.Validate.IsNumeric(bankid)) { error = "error:1041 银行编号(bankid)格式不正确!"; } //else if (!viviLib.Text.Validate.IsNumber(money) || !viviLib.Text.Validate.IsNumeric(money))//二位小数 //{ // error = "error:1042 订单金额(money)格式不正确!"; //} else if (!IsNotifyUrlOk()) { error = "error:1043 商户接收后台返回储值结果的地址(url)格式不正确!"; } else if (!IsReturnUrlOk()) { error = "error:1044 下行同步通知地址(aurl)格式不正确!"; } //else if (!isClientIpOk()) //{ // error = "error:1045 支付用户IP(payerIp)格式不正确!"; //} #endregion //完成基础资料的验证 if (!string.IsNullOrEmpty(error)) { WebUtility.ShowErrorMsg(error); return; } UserInfo userInfo = null; decimal tranAmt = decimal.Zero; int userId = int.Parse(userid); #region Step4 数据验证 if (!decimal.TryParse(money, out tranAmt)) { error = "error:1060 订单金额(money)有误!"; } else if (tranAmt < this.MinTranAMT) { error = "error:1061 订单金额(money)小于最小允许交易额!"; } else if (tranAmt > this.MaxChargeAMT) { error = string.Format("error:1062 订单金额(money){0:f2}大于最大允许交易额{1:f2}!", tranAmt, this.MaxChargeAMT); } else { var checkResult = Factory.Instance.CheckApiParms(userId, ChannelTypeId, RequiredCheckUserOrderNo, this.orderid); if (checkResult == null) { error = "error:1063 系统错误"; } else { userInfo = checkResult.Obj as UserInfo; if (userInfo == null) { error = "error:1067 系统错误"; } else if (checkResult.ErrCode == 1) { error = "error:1064 商户编号不存在"; } else if (checkResult.ErrCode == 2) { error = "error:1065 商户状态不正常"; } else if (checkResult.ErrCode == 3) { error = "error:1069 商户订单号重复"; } else if (!viviapi.SysInterface.Bank.Card70.BankReceiveVerify(sign, new object[] { userId, orderid.Trim(), bankid.Trim(), userInfo.APIKey })) { error = "error:1066 签名错误!"; } else { apikey = userInfo.APIKey; riskWarning = userInfo.RiskWarning == 1 ? true : false; } } } if (!string.IsNullOrEmpty(error)) { WebUtility.ShowErrorMsg(error); return; } #endregion int typeId = 0; int supplierId = 0; ChannelInfo channelInfo = viviapi.BLL.Channel.Channel.GetModel(sysBankcode, userId, true); if (channelInfo == null) { error = "error:1067:银行编号不存在!"; } else if (channelInfo.isOpen.Value != 1) { error = "error:1068:通道维护中!"; } if (!string.IsNullOrEmpty(error)) { if (DebuglogOpen) { if (userInfo != null && userInfo.isdebug == 1) { var debugInfo = new viviapi.Model.Sys.debuginfo { addtime = DateTime.Now, bugtype = viviapi.Model.Sys.debugtypeenum.网银订单, detail = version, errorcode = error, errorinfo = error, userid = userInfo.ID, url = Request.RawUrl.ToString(CultureInfo.InvariantCulture) }; viviapi.BLL.Sys.Debuglog.Insert(debugInfo); } } WebUtility.ShowErrorMsg(error); return; } //else if (!UserFactory.CheckUserOrderId(userId, orderid)) //{ // error = "error:1068:商户订单号重复!"; //} typeId = channelInfo.typeId; supplierId = channelInfo.supplier.Value; var order = new OrderBankInfo { orderid = Factory.Instance.GenerateOrderId(OrderPrefix), addtime = DateTime.Now, attach = attach, notifycontext = string.Empty, notifycount = 0, notifystat = 0, notifyurl = this.notifyurl, clientip = ServerVariables.TrueIP, completetime = DateTime.Now, returnurl = returnurl, ordertype = 1, typeId = typeId, paymodeId = this.sysBankcode, supplierId = supplierId, supplierOrder = string.Empty, userid = userId, userorder = orderid, refervalue = tranAmt, version = version }; //order.payRate = 0M; //order.supplierRate = chanelInfo.supprate; if (Request.UrlReferrer != null) { order.referUrl = Request.UrlReferrer.ToString(); } else { order.referUrl = string.Empty; } order.server = RuntimeSetting.ServerId; if (userInfo != null) { order.manageId = userInfo.manageId; //业务 } if (!order.manageId.HasValue || order.manageId.Value <= 0) { //if (AgentId > 0) //{ // if (viviapi.BLL.User.Factory.ChkAgent(AgentId)) // { // order.agentId = AgentId;//代理 // } //} //else { order.agentId = viviapi.BLL.User.Factory.GetPromID(userId); } } viviapi.Cache.WebCache.GetCacheService().AddObject(order.orderid, order, ExpiresTime); // newOrder.Insert(order); SellFactory.OnlineBankPay(order.userid, apikey, supplierId, order.orderid, order.refervalue, order.paymodeId, riskWarning); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { string error = string.Empty, apikey = ""; bool riskWarning = false; #region Step1 必要的参数不能为空 if (string.IsNullOrEmpty(this.Userid)) { error = "error:1001 商户ID(parter)不能空!"; } else if (string.IsNullOrEmpty(Bankid)) { error = "error:1002 银行类型(type)不能空!"; } else if (string.IsNullOrEmpty(Money)) { error = "error:1003 订单金额(value)不能空!"; } else if (string.IsNullOrEmpty(Orderid)) { error = "error:1004 商户订单号(orderid)不能空!"; } else if (string.IsNullOrEmpty(Notifyurl)) { error = "error:1005 下行异步通知地址(callbackurl)不能空!"; } else if (string.IsNullOrEmpty(Sign)) { error = "error:1006 MD5签名(sign)不能空!"; } #endregion #region Step2 检查参数长度 else if (Userid.Length > 5) { error = "error:1020 商户ID(parter)长度超过5位!"; } else if (Bankid.Length > 4) { error = "error:1021 银行类型(type)长度超过4位!"; } else if (Orderid.Length > 30) { error = "error:1022 商户订单号(orderid)长度超过30位!"; } else if (Money.Length > 8) { error = "error:1023 订单金额(value)长度超过最长限制!"; } else if (this.Notifyurl.Length > 255) { error = "error:1024 下行异步通知地址(callbackurl)长度超过255位!"; } else if (this.Returnurl.Length > 255) { error = "error:1025 下行同步通知地址(hrefbackurl)长度超过255位!"; } else if (this.ClientIp.Length > 20) { error = "error:1026 支付用户IP(payerIp)长度超过20位!"; } else if (this.Attach.Length > 255) { error = "error:1027 备注消息(attach)长度超过255位!"; } else if (this.Sign.Length != 32) { error = "error:1028 签名(sign)长度不正确!"; } #endregion #region Step3 格式验证 else if (!viviLib.Text.Validate.IsNumeric(Userid)) { error = "error:1040 商户ID(parter)格式不正确!"; } else if (!viviLib.Text.Validate.IsNumeric(Bankid)) { error = "error:1041 银行类型(type)格式不正确!"; } else if (!IsNotifyUrlOk()) { error = "error:1043 下行异步通知地址(callbackurl)格式不正确!"; } else if (!IsReturnUrlOk()) { error = "error:1044 下行同步通知地址(hrefbackurl)格式不正确!"; } else if (!IsClientIpOk()) { error = "error:1045 支付用户IP(payerIp)格式不正确!"; } #endregion //完成基础资料的验证 if (!string.IsNullOrEmpty(error)) { WebUtility.ShowErrorMsg(error); return; } UserInfo userInfo = null; decimal tranAmt = decimal.Zero; int userId = int.Parse(Userid); #region Step4 数据验证 if (!CheckUrlReferrer(userId)) { string host = string.Empty; if (Request.UrlReferrer != null) { host = Request.UrlReferrer.Host; } error = string.Format("error:1070 来路地址不合法!{0}", host); } else if (!decimal.TryParse(Money, out tranAmt)) { error = "error:1060 订单金额(value)有误!"; } else if (tranAmt < this.MinTranAMT) { error = "error:1061 订单金额(value)小于最小允许交易额!"; } else if (tranAmt > this.MaxChargeAMT) { error = string.Format("error:1062 订单金额(value){0:f2}大于最大允许交易额{1:f2}!", tranAmt, this.MaxChargeAMT); } else { var checkResult = Factory.Instance.CheckApiParms(userId, ChannelTypeId, RequiredCheckUserOrderNo, this.Orderid); if (checkResult == null) { error = "error:1063 系统错误"; } else { userInfo = checkResult.Obj as UserInfo; if (userInfo == null) { error = "error:1067 系统错误"; } else if (checkResult.ErrCode == 1) { error = "error:1064 商户编号不存在"; } else if (checkResult.ErrCode == 2) { error = "error:1065 商户状态不正常"; } else if (checkResult.ErrCode == 3) { error = "error:1069 商户订单号重复"; } else if (!viviapi.SysInterface.Bank.MyAPI.Utility.ReceiveVerify(Userid , this.Bankid , this.Money , this.Orderid , this.Notifyurl , userInfo.APIKey , Sign)) { error = "error:1066 签名错误!"; } else { apikey = userInfo.APIKey; //riskWarning = userInfo.RiskWarning == 1 ? true : false; } } } if (!string.IsNullOrEmpty(error)) { WebUtility.ShowErrorMsg(error); return; } #endregion int typeId = 0; int supplierId = 0; var channelInfo = viviapi.BLL.Channel.Factory.GetModel(ChannelTypeId, Bankid, userId, true); if (channelInfo == null) { error = "error:1067:银行编号不存在!"; } else if (channelInfo.isOpen != null && channelInfo.isOpen.Value != 1) { error = "error:1068:通道维护中!"; } if (!string.IsNullOrEmpty(error)) { if (DebuglogOpen) { if (userInfo != null && userInfo.isdebug == 1) { var debugInfo = new viviapi.Model.Sys.debuginfo { addtime = DateTime.Now, bugtype = viviapi.Model.Sys.debugtypeenum.网银订单, detail = string.Empty, errorcode = error, errorinfo = error, userid = userInfo.ID, url = Request.RawUrl.ToString(CultureInfo.InvariantCulture) }; viviapi.BLL.Sys.Debuglog.Insert(debugInfo); } } WebUtility.ShowErrorMsg(error); return; } if (channelInfo != null) { typeId = channelInfo.typeId; if (channelInfo.supplier != null) { supplierId = channelInfo.supplier.Value; } } var order = new OrderBankInfo { orderid = Factory.Instance.GenerateOrderId(OrderPrefix), addtime = DateTime.Now, attach = Attach, notifycontext = string.Empty, notifycount = 0, notifystat = 0, notifyurl = this.Notifyurl, clientip = ServerVariables.TrueIP, completetime = DateTime.Now, returnurl = Returnurl, ordertype = 1, typeId = typeId, paymodeId = this.Bankid, supplierId = supplierId, supplierOrder = string.Empty, userid = userId, userorder = Orderid, refervalue = tranAmt, referUrl = Request.UrlReferrer != null?Request.UrlReferrer.ToString() : string.Empty, server = RuntimeSetting.ServerId, manageId = 0, version = version }; if (userInfo != null) { order.manageId = userInfo.manageId; //业务 } if (!order.manageId.HasValue || order.manageId.Value <= 0) { if (AgentId > 0) { if (viviapi.BLL.User.Factory.ChkAgent(AgentId)) { order.agentId = AgentId;//代理 } } else { order.agentId = viviapi.BLL.User.Factory.GetPromID(userId); } } viviapi.Cache.WebCache.GetCacheService().AddObject(order.orderid, order, ExpiresTime); // NewOrder.Insert(order); SellFactory.OnlineBankPay(order.userid, apikey, supplierId, order.orderid, order.refervalue, order.paymodeId, riskWarning); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { string error = string.Empty, apikey = ""; bool riskWarning = true; #region Step1 必要的参数不能为空 if (string.IsNullOrEmpty(this.Userid)) { error = "error:1001 商户ID(p1_MerId)不能空!"; } else if (string.IsNullOrEmpty(Bankid)) { error = "error:1002 银行类型(pd_FrpId)不能空!"; } else if (string.IsNullOrEmpty(Money)) { error = "error:1003 订单金额(p3_Amt)不能空!"; } else if (string.IsNullOrEmpty(Orderid)) { error = "error:1004 商户订单号(p2_Order)不能空!"; } else if (string.IsNullOrEmpty(Notifyurl)) { error = "error:1005 下行异步通知地址(p8_Url)不能空!"; } /*else if (string.IsNullOrEmpty(version)) * { * error = "error:1006 版本号(version)不能空!"; * }*/ else if (string.IsNullOrEmpty(Sign)) { error = "error:1006 MD5签名(hmac)不能空!"; } #endregion #region Step2 检查参数长度 else if (Userid.Length > 11) { error = "error:1020 商户ID(p1_MerId)长度超过11位!"; } else if (Bankid.Length > 50) { error = "error:1021 支付通道编码(pd_FrpId)长度超过50位!"; } else if (Orderid.Length > 50) { error = "error:1022 商户订单号(p2_Order)长度超过50位!"; } else if (Money.Length > 20) { error = "error:1023 订单金额( p3_Amt)长度超过最长限制!"; } else if (this.Notifyurl.Length > 255) { error = "error:1024 下行异步通知地址(p8_Url)长度超过255位!"; } else if (this.Returnurl.Length > 2) { error = "error:1025 p9_SAF( p9_SAF)长度超过255位!"; } //else if (this.clientIp.Length > 20) //{ // error = "error:1026 支付用户IP(payerIp)长度超过20位!"; //} else if (this.Attach.Length > 255) { error = "error:1027 商户扩展信息(pa_MP)长度超过255位!"; } else if (this.Sign.Length != 32) { error = "error:1028 签名数据(hmac)长度不正确!"; } #endregion #region Step3 格式验证 else if (!viviLib.Text.Validate.IsNumeric(Userid)) { error = "error:1040 商户编号(p1_MerId)格式不正确!"; } //else if (!viviLib.Text.Validate.IsLetterOrNumber(bankid)) //{ // error = "error:1041 支付通道编码(pd_FrpId)格式不正确!"; //} //else if (!viviLib.Text.Validate.IsNumber(money) || !viviLib.Text.Validate.IsNumeric(money))//二位小数 //{ // error = "error:1042 订单金额(value)格式不正确!"; //} else if (!IsNotifyUrlOk()) { error = "error:1043 商户接收支付成功数据的地址(p8_Url)格式不正确!"; } //else if (!isReturnUrlOk()) //{ // error = "error:1044 送货地址(hrefbackurl)格式不正确!"; //} //else if (!isClientIpOk()) //{ // error = "error:1045 支付用户IP(payerIp)格式不正确!"; //} #endregion //完成基础资料的验证 if (!string.IsNullOrEmpty(error)) { WebUtility.ShowErrorMsg(error); return; } UserInfo userInfo = null; decimal tranAmt = decimal.Zero; int userId = 0; if (!int.TryParse(Userid, out userId)) { error = "error:1064 商户编号不存在!"; } #region Step4 数据验证 else if (!decimal.TryParse(Money, out tranAmt)) { error = "error:1060 支付金额(p3_Amt)有误!"; } else if (tranAmt < this.MinTranAMT) { error = "error:1061 订单金额(p3_Amt)小于最小允许交易额!"; } else if (tranAmt > this.MaxChargeAMT) { error = string.Format("error:1062 订单金额(p3_Amt){0:f2}大于最大允许交易额{1:f2}!", tranAmt, this.MaxChargeAMT); } else { var checkResult = Factory.Instance.CheckApiParms(userId, ChannelTypeId, RequiredCheckUserOrderNo, this.Orderid); if (checkResult == null) { error = "error:1063 系统错误"; } else { userInfo = checkResult.Obj as UserInfo; if (userInfo == null) { error = "error:1067 系统错误"; } else if (checkResult.ErrCode == 1) { error = "error:1064 商户编号不存在"; } else if (checkResult.ErrCode == 2) { error = "error:1065 商户状态不正常"; } else if (checkResult.ErrCode == 3) { error = "error:1069 商户订单号重复"; } else if (!viviapi.SysInterface.Bank.YeePay.CheckSign(this.Userid , this.Orderid , this.Money , this.P4Cur , this.P5Pid , this.P6Pcat , this.P7Pdesc , Notifyurl , Returnurl , Attach , Bankid , PrNeedResponse , userInfo.APIKey , Sign)) { error = "error:1066 签名错误!"; } else { apikey = userInfo.APIKey; riskWarning = userInfo.RiskWarning == 1 ? true : false; } } } if (!string.IsNullOrEmpty(error)) { WebUtility.ShowErrorMsg(error); return; } #endregion int typeId = 0; int supplierId = 0; var channelInfo = viviapi.BLL.Channel.Factory.GetModel(ChannelTypeId, SysBankcode, userId, true); if (channelInfo == null) { error = "error:1067:银行编号不存在!"; } else if (channelInfo.isOpen.Value != 1) { error = "error:1068:通道维护中!"; } if (!string.IsNullOrEmpty(error)) { #region if (DebuglogOpen) { if (userInfo != null && userInfo.isdebug == 1) { var debugInfo = new debuginfo { addtime = DateTime.Now, bugtype = viviapi.Model.Sys.debugtypeenum.网银订单, detail = string.Empty, errorcode = error, errorinfo = error, userid = userInfo.ID }; if (Request.RawUrl != null) { debugInfo.url = Request.RawUrl.ToString(); } else { debugInfo.url = string.Empty; } viviapi.BLL.Sys.Debuglog.Insert(debugInfo); } } #endregion WebUtility.ShowErrorMsg(error); return; } //else if (!UserFactory.CheckUserOrderId(userId, orderid)) //{ // error = "error:1068:商户订单号重复!"; //} typeId = channelInfo.typeId; supplierId = channelInfo.supplier.Value; var order = new OrderBankInfo { orderid = Factory.Instance.GenerateOrderId(OrderPrefix), addtime = DateTime.Now, attach = Attach, notifycontext = string.Empty, notifycount = 0, notifystat = 0, notifyurl = Notifyurl, clientip = ServerVariables.TrueIP, completetime = DateTime.Now, returnurl = Notifyurl, ordertype = 1, typeId = typeId, paymodeId = SysBankcode, supplierId = supplierId, supplierOrder = string.Empty, userid = userId, userorder = Orderid, refervalue = tranAmt, cus_subject = P5Pid, cus_field1 = P6Pcat, cus_description = P7Pdesc, cus_field2 = P4Cur, cus_field3 = PrNeedResponse, cus_field4 = Returnurl, server = RuntimeSetting.ServerId, version = Version }; //order.payRate = 0M; //order.supplierRate = chanelInfo.supprate; if (Request.UrlReferrer != null) { order.referUrl = Request.UrlReferrer.ToString(); } else { order.referUrl = string.Empty; } //订单所属业务 order.manageId = userInfo.manageId; if (!order.manageId.HasValue || order.manageId.Value <= 0) { order.agentId = viviapi.BLL.User.Factory.GetPromID(userId); } viviapi.Cache.WebCache.GetCacheService().AddObject(order.orderid, order, ExpiresTime); // NewOrder.Insert(order); SellFactory.OnlineBankPay(order.userid, apikey, supplierId, order.orderid, order.refervalue, order.paymodeId, riskWarning); }