Ejemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public debuginfo GetModel(int id)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            debuginfo model = new debuginfo();
            DataSet   ds    = DataBase.ExecuteDataset(CommandType.StoredProcedure, "proc_debuginfo_GetModel", parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["bugtype"].ToString() != "")
                {
                    model.bugtype = (debugtypeenum)int.Parse(ds.Tables[0].Rows[0]["bugtype"].ToString());
                }
                if (ds.Tables[0].Rows[0]["userid"].ToString() != "")
                {
                    model.userid = int.Parse(ds.Tables[0].Rows[0]["userid"].ToString());
                }
                model.url       = ds.Tables[0].Rows[0]["url"].ToString();
                model.errorcode = ds.Tables[0].Rows[0]["errorcode"].ToString();
                model.errorinfo = ds.Tables[0].Rows[0]["errorinfo"].ToString();
                model.detail    = ds.Tables[0].Rows[0]["detail"].ToString();
                model.userorder = ds.Tables[0].Rows[0]["userorder"].ToString();
                if (ds.Tables[0].Rows[0]["addtime"].ToString() != "")
                {
                    model.addtime = DateTime.Parse(ds.Tables[0].Rows[0]["addtime"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <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);
        }