예제 #1
0
        public static void SynchronousNotifyX(OrderBankInfo orderInfo)
        {
            if (orderInfo == null)
            {
                return;
            }

            byte exists = BankNotify.Instance.Exists(orderInfo.orderid);

            if (exists == 0 || exists == 1)
            {
                string notifyUrl = Utility.GetBankBackUrl(orderInfo, true);
                if (!string.IsNullOrEmpty(notifyUrl))
                {
                    bool isOK = Process(orderInfo.version, orderInfo.orderid, notifyUrl);
                    if (isOK == false)
                    {
                        BanknotifyQueue.Send(orderInfo);
                    }
                }
            }
            else if (exists == 3)
            {
                BanknotifyQueue.Send(orderInfo);
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderinfo"></param>
        /// <param name="result"></param>
        public static void BankOrderReturn(OrderBankInfo orderinfo, string result, HttpContext context)
        {
            if (orderinfo == null || string.IsNullOrEmpty(orderinfo.returnurl))
            {
                return;
            }

            string userKey = BLL.User.UserFactory.GetUsersKey(orderinfo.userid);

            string md5Str = string.Format("result={0}&userid={1}&orderid={2}&money={3}key={4}"
                                          , result
                                          , orderinfo.userid
                                          , orderinfo.userorder
                                          , decimal.Round(orderinfo.realvalue.Value, 2)
                                          , userKey);

            string sign = viviLib.Security.Cryptography.MD5(md5Str);

            string parms = string.Format("result={0}&userid={1}&orderid={2}&money={3}&ext={4}&sign={5}",
                                         result
                                         , orderinfo.userid
                                         , orderinfo.userorder
                                         , decimal.Round(orderinfo.realvalue.Value, 2)
                                         , System.Web.HttpUtility.UrlEncode(orderinfo.attach, System.Text.Encoding.GetEncoding("GBK"))
                                         , sign);

            string returnurl = orderinfo.returnurl + "?" + parms;

            if (context != null)
            {
                context.Response.Redirect(returnurl);
            }
        }
예제 #3
0
        public static string GetCallBackUrl(OrderBankInfo orderinfo)
        {
            string result = orderinfo.status == 2 ? "0" : "1";

            if (orderinfo == null || string.IsNullOrEmpty(orderinfo.notifyurl))
            {
                return(string.Empty);
            }

            string userKey = BLL.User.UserFactory.GetUsersKey(orderinfo.userid);

            string md5Str = string.Format("result={0}&userid={1}&orderid={2}&money={3}key={4}"
                                          , result
                                          , orderinfo.userid
                                          , orderinfo.userorder
                                          , decimal.Round(orderinfo.realvalue.Value, 2)
                                          , userKey);

            string sign = viviLib.Security.Cryptography.MD5(md5Str);

            string parms = string.Format("result={0}&userid={1}&orderid={2}&money={3}&ext={4}&sign={5}",
                                         result
                                         , orderinfo.userid
                                         , orderinfo.userorder
                                         , decimal.Round(orderinfo.realvalue.Value, 2)
                                         , System.Web.HttpUtility.UrlEncode(orderinfo.attach, System.Text.Encoding.GetEncoding("GBK"))
                                         , sign);

            string callBackUrl = orderinfo.notifyurl + "?" + parms;

            return(callBackUrl);
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            viviapi.BLL.ManageFactory.CheckSecondPwd();

            if (!this.IsPostBack)
            {
                txtOrderId.Text = OrderId;

                string where = string.Empty;
                DataTable list = Factory.GetList(where).Tables[0];
                foreach (DataRow dr in list.Rows)
                {
                    this.ddlSupp.Items.Add(new ListItem(dr["name"].ToString(), dr["code"].ToString()));
                }
                if (!string.IsNullOrEmpty(OrderId))
                {
                    OrderBankInfo orderBank = viviapi.BLL.Order.Bank.Factory.Instance.GetModelByOrderId(OrderId);
                    if (orderBank != null)
                    {
                        ddlSupp.SelectedValue = orderBank.supplierId.ToString(CultureInfo.InvariantCulture);
                        this.txtOrderAmt.Text = decimal.Round(orderBank.refervalue).ToString("f2");

                        btnAdd.Enabled = (orderBank.status == 1);
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Notify(OrderBankInfo model)
        {
            int rowsAffected = 0;

            SqlParameter[] parameters =
            {
                new SqlParameter("@orderid",        SqlDbType.VarChar,   30),
                new SqlParameter("@againNotifyUrl", SqlDbType.VarChar, 2000),
                new SqlParameter("@notifycount",    SqlDbType.Int,        4),
                new SqlParameter("@notifystat",     SqlDbType.TinyInt,    1),
                new SqlParameter("@notifycontext",  SqlDbType.VarChar,  200),
                new SqlParameter("@notifytime",     SqlDbType.DateTime)
            };
            parameters[0].Value = model.orderid;
            //parameters[1].Value = model.notifyurl;
            parameters[1].Value = model.againNotifyUrl;
            parameters[2].Value = model.notifycount;
            parameters[3].Value = model.notifystat;
            parameters[4].Value = model.notifycontext;
            parameters[5].Value = model.notifytime;

            rowsAffected = DataBase.ExecuteNonQuery(System.Data.CommandType.StoredProcedure, "proc_orderbank_notify", parameters);
            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="order"></param>
        public void DoNotify(OrderBankInfo order)
        {
            if (order == null)
            {
                return;
            }

            BLL.OrderNotifyBase.AsynchronousNotify(1, order);
        }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderinfo"></param>
        /// <param name="isNotify"></param>
        /// <param name="apiKey"></param>
        /// <returns></returns>
        public static string CreateNotifyUrl(OrderBankInfo orderinfo, bool isNotify, string apiKey)
        {
            string notifyUrl = string.Empty;

            if (orderinfo == null || string.IsNullOrEmpty(apiKey))
            {
                return(notifyUrl);
            }

            notifyUrl = isNotify ? orderinfo.notifyurl : orderinfo.returnurl;

            string userorder = orderinfo.userorder;
            string opstate   = orderinfo.opstate;

            string returncode = "11";

            if (orderinfo.status == 2 || orderinfo.status == 8)
            {
                returncode = "1";
            }

            string money = "0";

            if (orderinfo.realvalue.HasValue)
            {
                money = decimal.Round(orderinfo.realvalue.Value, 2).ToString(CultureInfo.InvariantCulture);
            }

            string plain = string.Format(Vb7010BankNotifyVerifyStr
                                         , returncode
                                         , orderinfo.userid
                                         , userorder
                                         , apiKey);

            string sign = Cryptography.MD5(plain);

            var parms = new StringBuilder();

            parms.AppendFormat("returncode={0}", HttpUtility.UrlEncode(returncode));
            parms.AppendFormat("&userid={0}", HttpUtility.UrlEncode(orderinfo.userid.ToString(CultureInfo.InvariantCulture)));
            parms.AppendFormat("&orderid={0}", HttpUtility.UrlEncode(userorder));
            parms.AppendFormat("&money={0}", HttpUtility.UrlEncode(money));
            parms.AppendFormat("&sign={0}", HttpUtility.UrlEncode(sign));
            parms.AppendFormat("&ext={0}", HttpUtility.UrlEncode(orderinfo.attach, System.Text.Encoding.GetEncoding("GB2312")));

            if (notifyUrl.IndexOf("?", System.StringComparison.Ordinal) > 0)
            {
                notifyUrl = notifyUrl + "&" + parms.ToString();
            }
            else
            {
                notifyUrl = notifyUrl + "?" + parms.ToString();
            }

            return(notifyUrl);
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderinfo"></param>
        /// <param name="isNotify"></param>
        /// <param name="apiKey"></param>
        /// <returns></returns>
        public static string CreateNotifyUrl(OrderBankInfo orderinfo, bool isNotify, string apiKey)
        {
            string notifyUrl = string.Empty;

            if (orderinfo == null || string.IsNullOrEmpty(apiKey))
            {
                return(notifyUrl);
            }

            notifyUrl = isNotify ? orderinfo.notifyurl : orderinfo.returnurl;

            string userorder = orderinfo.userorder;
            string opstate   = orderinfo.opstate;

            if (string.IsNullOrEmpty(opstate))
            {
                opstate = orderinfo.status == 2 ? "0" : "-1";
            }

            string systime = "";

            if (orderinfo.completetime.HasValue)
            {
                systime = orderinfo.completetime.Value.ToString("yyyy/MM/dd HH:mm:ss");
            }

            string ovalue = "0";

            if (orderinfo.realvalue.HasValue)
            {
                ovalue = decimal.Round(orderinfo.realvalue.Value, 2).ToString(CultureInfo.InvariantCulture);
            }

            string plain = string.Format("orderid={0}&opstate={1}&ovalue={2}{3}"
                                         , userorder
                                         , opstate
                                         , ovalue
                                         , apiKey);
            string locationsign = Cryptography.MD5(plain);

            var parms = new StringBuilder();

            parms.AppendFormat("orderid={0}", UrlEncode(userorder));
            parms.AppendFormat("&opstate={0}", UrlEncode(opstate));
            parms.AppendFormat("&ovalue={0}", UrlEncode(ovalue));
            parms.AppendFormat("&sysorderid={0}", UrlEncode(orderinfo.orderid));
            parms.AppendFormat("&ekaorderid={0}", HttpUtility.UrlEncode(orderinfo.orderid));
            parms.AppendFormat("&ekatime={0}", HttpUtility.UrlEncode(systime));
            parms.AppendFormat("&attach={0}", UrlEncode(orderinfo.attach));
            parms.AppendFormat("&msg={0}", UrlEncode(orderinfo.msg));
            parms.AppendFormat("&sign={0}", UrlEncode(locationsign));

            notifyUrl = notifyUrl + "?" + parms.ToString();

            return(notifyUrl);
        }
예제 #9
0
        public static void AsynchronousNotify(OrderBankInfo orderInfo)
        {
            if (orderInfo == null || orderInfo.status == 1)
            {
                return;
            }

            string notifyUrl = Utility.GetBankBackUrl(orderInfo, true);

            Common.AsynchronousNotify(1, orderInfo, notifyUrl);
        }
예제 #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="orderMessage">All information for an order</param>
 public void Send(OrderBankInfo orderMessage)
 {
     try
     {
         // This method does not involve in distributed transaction and optimizes performance using Single type
         base.transactionType = MessageQueueTransactionType.Single;
         base.Send(orderMessage);
     }
     catch (Exception exception)
     {
         viviLib.ExceptionHandling.ExceptionHandler.HandleException(exception);
     }
 }
예제 #11
0
        /// <summary>
        /// 取通知地址
        /// </summary>
        /// <param name="orderinfo"></param>
        /// <param name="isNotify"></param>
        /// <returns></returns>
        public static string GetBankBackUrl(OrderBankInfo orderinfo, bool isNotify)
        {
            if (orderinfo == null)
            {
                return(string.Empty);
            }

            string notifyUrl = isNotify ? orderinfo.notifyurl : orderinfo.returnurl;

            if (string.IsNullOrEmpty(notifyUrl))
            {
                return(string.Empty);
            }

            var userinfo = BLL.User.Factory.GetCacheUserBaseInfo(orderinfo.userid);

            if (userinfo == null)
            {
                return(string.Empty);
            }

            string ver    = orderinfo.version;
            string apikey = userinfo.APIKey;

            if (ver == MyAPI.Utility.EnName)
            {
                notifyUrl = MyAPI.Utility.CreateNotifyUrl(orderinfo, isNotify, apikey);
            }
            else if (ver == Eka.VbYika)
            {
                notifyUrl = Eka.CreateNotifyUrl(orderinfo, isNotify, apikey);
            }
            else if (ver == Card70.Vb7010)
            {
                notifyUrl = Card70.CreateNotifyUrl(orderinfo, isNotify, apikey);
            }
            else if (ver == YeePay.VbYee10)
            {
                notifyUrl = YeePay.CreateNotifyUrl(orderinfo, isNotify, apikey);
            }
            else if (ver == HuaQi.Vbhq10)
            {
                notifyUrl = HuaQi.CreateNotifyUrl(orderinfo, isNotify, apikey);
            }
            return(notifyUrl);
        }
예제 #12
0
        public static string GetReturnUrl(OrderBankInfo orderInfo)
        {
            string returnUrl = GetBankBackUrl(orderInfo, false);

            if (string.IsNullOrEmpty(returnUrl))
            {
                var parms = new StringBuilder();
                parms.AppendFormat("o={0}", orderInfo.orderid);
                parms.AppendFormat("&uo={0}", orderInfo.userorder);
                parms.AppendFormat("&c={0}", orderInfo.paymodeId);
                parms.AppendFormat("&t={0}", orderInfo.typeId);
                parms.AppendFormat("&v={0:f2}", orderInfo.realvalue);
                parms.AppendFormat("&e={0}", orderInfo.msg);
                parms.AppendFormat("&u={0}", orderInfo.userid);
                parms.AppendFormat("&s={0}", orderInfo.status);

                returnUrl = RuntimeSetting.GatewayUrl + "/PayResult.aspx?" + parms.ToString();
            }

            return(returnUrl);
        }
예제 #13
0
        /// <summary>
        /// 记录在队列中失败列表 重新补发
        /// </summary>
        private static void ProcessNotify()
        {
            BLL.OrderBankNotify notifyBLL = new viviapi.BLL.OrderBankNotify();

            for (int j = 0; j < notifybatchSize; j++)
            {
                try
                {
                    OrderBankInfo _order = notifyBLL.ReceiveFromQueue(notifyqueueTimeout);
                    _order.notifycount = 0;

                    OrderNotify notifyInfo = new OrderNotify();
                    notifyInfo.orderInfo = _order;

                    Timer Tmr = new Timer(notifyBLL.NotifyCheckStatus, notifyInfo, 0, 1000);
                    notifyInfo.tmr = Tmr;
                }
                catch
                {
                }
            }
        }
예제 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="oclass"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string GetNotifyUrl(int oclass, object obj)
        {
            string notifyUrl = string.Empty;

            if (oclass == 1)//网银
            {
                OrderBankInfo orderInfo = obj as OrderBankInfo;
                if (orderInfo == null)
                {
                    return(string.Empty);
                }

                OrderBank bll = new OrderBank();
                notifyUrl = "";   //bll.GetCallBackUrl(orderInfo);
            }
            else if (oclass == 2) //点卡
            {
                OrderCardInfo orderInfo = obj as OrderCardInfo;
                if (orderInfo == null)
                {
                    return(string.Empty);
                }

                OrderCard bll = new OrderCard();
                //notifyUrl = bll.GetCallBackUrl(orderInfo);
            }
            else if (oclass == 3)//短信及声讯
            {
                OrderSmsInfo orderInfo = obj as OrderSmsInfo;
                if (orderInfo == null)
                {
                    return(string.Empty);
                }
                OrderSms bll = new OrderSms();
                notifyUrl = bll.GetCallBackUrl(orderInfo);
            }
            return(notifyUrl);
        }
예제 #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="orderinfo"></param>
 /// <param name="result"></param>
 public static void BankOrderNotify(OrderBankInfo orderinfo, string result, HttpContext context)
 {
 }
예제 #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                string orderId = this.txtOrderId.Text.Trim();
                if (string.IsNullOrEmpty(orderId))
                {
                    ShowMessageBox("请输入订单号");
                    return;
                }

                if (string.IsNullOrEmpty(ddlSupp.SelectedValue))
                {
                    ShowMessageBox("请选择接口商");
                    return;
                }

                string  orderAmt = this.txtOrderAmt.Text.Trim();
                decimal amt      = 0M;
                if (string.IsNullOrEmpty(orderAmt))
                {
                    ShowMessageBox("请输入订单金额");
                    return;
                }

                if (!decimal.TryParse(orderAmt, out amt))
                {
                    ShowMessageBox("订单金额不能为空");
                    return;
                }
                if (amt <= 0M)
                {
                    ShowMessageBox("金额不能为0");
                    return;
                }

                OrderBankInfo orderBank = viviapi.BLL.Order.Bank.Factory.Instance.GetModelByOrderId(orderId);
                if (orderBank == null)
                {
                    ShowMessageBox("不存在此订单");
                    return;
                }

                if (orderBank.status != 1)
                {
                    ShowMessageBox("订单状态不正确");
                    return;
                }

                string supp = this.ddlSupp.SelectedValue;

                if (orderBank.status == 1)
                {
                    FunExecResult result = viviapi.ETAPI.Common.OrderBankUtils.InsertToDb(int.Parse(supp)
                                                                                          , orderBank
                                                                                          , "Sys" + DateTime.Now.Ticks.ToString()
                                                                                          , 2
                                                                                          , "0"
                                                                                          , "手动补单"
                                                                                          , amt, 0M);

                    if (result.ErrCode == 0)
                    {
                        if (orderBank.status != 1)
                        {
                            APINotification.SynchronousNotifyX(orderBank);
                        }

                        ShowMessageBox("操作成功");
                    }
                    else
                    {
                        ShowMessageBox("操作失败");
                    }
                }
                else
                {
                    ShowMessageBox("订单状态不正确");
                }
            }
        }
예제 #17
0
 /// <summary>
 /// 发送完成的订单到队列
 /// </summary>
 /// <param name="orderMessage">All information for an order</param>
 public void Complete(OrderBankInfo orderMessage)
 {
     // This method does not involve in distributed transaction and optimizes performance using Single type
     base.transactionType = MessageQueueTransactionType.Single;
     base.Send(orderMessage);
 }
예제 #18
0
        const int DefaultTimeout = 2 * 60 * 1000; // 2 minutes timeout

        #region UpdatetoDB
        /// <summary>
        /// 将结果返回到数据库
        /// </summary>
        /// <param name="oclass"></param>
        /// <param name="obj"></param>
        /// <param name="agurl"></param>
        /// <param name="times"></param>
        /// <param name="callbacktext"></param>
        private static void UpdatetoDB(int oclass, object obj, string agurl, int times, string callbacktext, bool success, string errcode)
        {
            if (oclass == 1)
            {
                OrderBankInfo orderInfo = obj as OrderBankInfo;
                if (orderInfo != null)
                {
                    OrderBank dal = new OrderBank();

                    //string SuccessFlag = SystemApiHelper.Successflag(orderInfo.version);

                    bool isnotifysucc = SystemApiHelper.CheckCallBackIsSuccess(orderInfo.version, callbacktext);

                    orderInfo.notifystat     = isnotifysucc ? 2 : 4;
                    orderInfo.againNotifyUrl = agurl;
                    orderInfo.notifycontext  = callbacktext;
                    orderInfo.notifycount    = times;
                    orderInfo.notifytime     = DateTime.Now;
                    dal.UpdateNotifyInfo(orderInfo);

                    if (orderInfo.notifystat != 2)
                    {
                        //没有成功将发送到异常队列 多次通知
                        banknotifyQueue.Send(orderInfo);
                    }
                }
            }
            else if (oclass == 2)
            {
                OrderCardInfo orderInfo = obj as OrderCardInfo;
                if (orderInfo != null)
                {
                    OrderCard dal = new OrderCard();

                    bool isnotifysucc = SystemApiHelper.CheckCallBackIsSuccess(orderInfo.version, callbacktext);
                    orderInfo.notifystat     = isnotifysucc ? 2 : 4;
                    orderInfo.againNotifyUrl = agurl;
                    orderInfo.notifycontext  = callbacktext;
                    orderInfo.notifycount    = times;
                    orderInfo.notifytime     = DateTime.Now;

                    dal.UpdateNotifyInfo(orderInfo);

                    if (orderInfo.notifystat != 2)
                    {
                        //没有成功将发送到异常队列 多次通知
                        cardnotifyQueue.Send(orderInfo);
                    }
                }
            }
            else if (oclass == 3)
            {
                OrderSmsInfo orderInfo = obj as OrderSmsInfo;

                if (orderInfo != null)
                {
                    OrderSms dal = new OrderSms();

                    orderInfo.notifystat     = success ? 2:4;
                    orderInfo.issucc         = success;
                    orderInfo.errcode        = errcode;
                    orderInfo.againNotifyUrl = agurl;
                    orderInfo.notifycontext  = callbacktext;
                    orderInfo.notifycount    = times;
                    dal.UpdateNotifyInfo(orderInfo);

                    if (orderInfo.notifystat != 2)
                    {
                        //没有成功将发送到异常队列 多次通知
                        smsnotifyQueue.Send(orderInfo);
                    }
                }
            }
        }
예제 #19
0
        internal OrderBankInfo GetModelFromDs(DataSet ds)
        {
            var model = new OrderBankInfo();

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = long.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.orderid = ds.Tables[0].Rows[0]["orderid"].ToString();
                if (ds.Tables[0].Rows[0]["ordertype"].ToString() != "")
                {
                    model.ordertype = int.Parse(ds.Tables[0].Rows[0]["ordertype"].ToString());
                }
                if (ds.Tables[0].Rows[0]["userid"].ToString() != "")
                {
                    model.userid = int.Parse(ds.Tables[0].Rows[0]["userid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["typeId"].ToString() != "")
                {
                    model.typeId = int.Parse(ds.Tables[0].Rows[0]["typeId"].ToString());
                }
                model.paymodeId = ds.Tables[0].Rows[0]["paymodeId"].ToString();
                model.userorder = ds.Tables[0].Rows[0]["userorder"].ToString();
                if (ds.Tables[0].Rows[0]["refervalue"].ToString() != "")
                {
                    model.refervalue = decimal.Parse(ds.Tables[0].Rows[0]["refervalue"].ToString());
                }
                if (ds.Tables[0].Rows[0]["realvalue"].ToString() != "")
                {
                    model.realvalue = decimal.Parse(ds.Tables[0].Rows[0]["realvalue"].ToString());
                }
                model.notifyurl      = ds.Tables[0].Rows[0]["notifyurl"].ToString();
                model.againNotifyUrl = ds.Tables[0].Rows[0]["againNotifyUrl"].ToString();
                if (ds.Tables[0].Rows[0]["notifycount"].ToString() != "")
                {
                    model.notifycount = int.Parse(ds.Tables[0].Rows[0]["notifycount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["notifystat"].ToString() != "")
                {
                    model.notifystat = int.Parse(ds.Tables[0].Rows[0]["notifystat"].ToString());
                }
                model.notifycontext = ds.Tables[0].Rows[0]["notifycontext"].ToString();
                model.returnurl     = ds.Tables[0].Rows[0]["returnurl"].ToString();
                model.attach        = ds.Tables[0].Rows[0]["attach"].ToString();
                model.payerip       = ds.Tables[0].Rows[0]["payerip"].ToString();
                model.clientip      = ds.Tables[0].Rows[0]["clientip"].ToString();
                model.referUrl      = ds.Tables[0].Rows[0]["referUrl"].ToString();
                if (ds.Tables[0].Rows[0]["addtime"].ToString() != "")
                {
                    model.addtime = DateTime.Parse(ds.Tables[0].Rows[0]["addtime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["supplierID"].ToString() != "")
                {
                    model.supplierId = int.Parse(ds.Tables[0].Rows[0]["supplierID"].ToString());
                }
                model.supplierOrder = ds.Tables[0].Rows[0]["supplierOrder"].ToString();
                if (ds.Tables[0].Rows[0]["status"].ToString() != "")
                {
                    model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["completetime"].ToString() != "")
                {
                    model.completetime = DateTime.Parse(ds.Tables[0].Rows[0]["completetime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["payRate"].ToString() != "")
                {
                    model.payRate = decimal.Parse(ds.Tables[0].Rows[0]["payRate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["supplierRate"].ToString() != "")
                {
                    model.supplierRate = decimal.Parse(ds.Tables[0].Rows[0]["supplierRate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["promRate"].ToString() != "")
                {
                    model.promRate = decimal.Parse(ds.Tables[0].Rows[0]["promRate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["payAmt"].ToString() != "")
                {
                    model.payAmt = decimal.Parse(ds.Tables[0].Rows[0]["payAmt"].ToString());
                }
                if (ds.Tables[0].Rows[0]["promAmt"].ToString() != "")
                {
                    model.promAmt = decimal.Parse(ds.Tables[0].Rows[0]["promAmt"].ToString());
                }
                if (ds.Tables[0].Rows[0]["supplierAmt"].ToString() != "")
                {
                    model.supplierAmt = decimal.Parse(ds.Tables[0].Rows[0]["supplierAmt"].ToString());
                }
                if (ds.Tables[0].Rows[0]["profits"].ToString() != "")
                {
                    model.profits = decimal.Parse(ds.Tables[0].Rows[0]["profits"].ToString());
                }
                if (ds.Tables[0].Rows[0]["server"].ToString() != "")
                {
                    model.server = int.Parse(ds.Tables[0].Rows[0]["server"].ToString());
                }
                if (ds.Tables[0].Rows[0]["manageId"].ToString() != "")
                {
                    model.manageId = int.Parse(ds.Tables[0].Rows[0]["manageId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["commission"].ToString() != "")
                {
                    model.commission = decimal.Parse(ds.Tables[0].Rows[0]["commission"].ToString());
                }
                model.version = ds.Tables[0].Rows[0]["version"].ToString();
                if (ds.Tables[0].Rows[0]["cus_subject"] != null && ds.Tables[0].Rows[0]["cus_subject"].ToString() != "")
                {
                    model.cus_subject = ds.Tables[0].Rows[0]["cus_subject"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cus_price"] != null && ds.Tables[0].Rows[0]["cus_price"].ToString() != "")
                {
                    model.cus_price = ds.Tables[0].Rows[0]["cus_price"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cus_quantity"] != null &&
                    ds.Tables[0].Rows[0]["cus_quantity"].ToString() != "")
                {
                    model.cus_quantity = ds.Tables[0].Rows[0]["cus_quantity"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cus_description"] != null &&
                    ds.Tables[0].Rows[0]["cus_description"].ToString() != "")
                {
                    model.cus_description = ds.Tables[0].Rows[0]["cus_description"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cus_field1"] != null && ds.Tables[0].Rows[0]["cus_field1"].ToString() != "")
                {
                    model.cus_field1 = ds.Tables[0].Rows[0]["cus_field1"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cus_field2"] != null && ds.Tables[0].Rows[0]["cus_field2"].ToString() != "")
                {
                    model.cus_field2 = ds.Tables[0].Rows[0]["cus_field2"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cus_field3"] != null && ds.Tables[0].Rows[0]["cus_field3"].ToString() != "")
                {
                    model.cus_field3 = ds.Tables[0].Rows[0]["cus_field3"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cus_field4"] != null && ds.Tables[0].Rows[0]["cus_field4"].ToString() != "")
                {
                    model.cus_field4 = ds.Tables[0].Rows[0]["cus_field4"].ToString();
                }
                if (ds.Tables[0].Rows[0]["cus_field5"] != null && ds.Tables[0].Rows[0]["cus_field5"].ToString() != "")
                {
                    model.cus_field5 = ds.Tables[0].Rows[0]["cus_field5"].ToString();
                }
                if (ds.Tables[0].Rows[0]["agentid"] != null && ds.Tables[0].Rows[0]["agentid"].ToString() != "")
                {
                    model.agentId = Convert.ToInt32(ds.Tables[0].Rows[0]["agentid"].ToString());
                }

                return(model);
            }
            return(null);
        }
예제 #20
0
        /// <summary>
        ///  增加一条数据
        /// </summary>
        public long Insert(OrderBankInfo model)
        {
            //try
            //{
            SqlParameter[] parameters =
            {
                new SqlParameter("@id",              SqlDbType.BigInt,       8),
                new SqlParameter("@orderid",         SqlDbType.VarChar,     30),
                new SqlParameter("@ordertype",       SqlDbType.TinyInt,      1),
                new SqlParameter("@userid",          SqlDbType.Int,          4),
                new SqlParameter("@typeId",          SqlDbType.Int),
                new SqlParameter("@paymodeId",       SqlDbType.VarChar,     10),
                new SqlParameter("@userorder",       SqlDbType.VarChar,     30),
                new SqlParameter("@refervalue",      SqlDbType.Decimal,      9),
                new SqlParameter("@notifyurl",       SqlDbType.VarChar,    200),
                new SqlParameter("@returnurl",       SqlDbType.VarChar,    200),
                new SqlParameter("@attach",          SqlDbType.VarChar,    255),
                new SqlParameter("@payerip",         SqlDbType.VarChar,     20),
                new SqlParameter("@clientip",        SqlDbType.VarChar,     20),
                new SqlParameter("@referUrl",        SqlDbType.VarChar,    200),
                new SqlParameter("@addtime",         SqlDbType.DateTime),
                new SqlParameter("@supplierId",      SqlDbType.Int,          4),
                new SqlParameter("@status",          SqlDbType.TinyInt,      1),
                new SqlParameter("@server",          SqlDbType.Int),
                new SqlParameter("@manageId",        SqlDbType.Int),      //业务员
                new SqlParameter("@version",         SqlDbType.VarChar,     10),
                new SqlParameter("@cus_subject",     SqlDbType.NVarChar,   100),
                new SqlParameter("@cus_price",       SqlDbType.NVarChar,    50),
                new SqlParameter("@cus_quantity",    SqlDbType.NVarChar,    50),
                new SqlParameter("@cus_description", SqlDbType.NVarChar,  1000),
                new SqlParameter("@cus_field1",      SqlDbType.NVarChar,   100),
                new SqlParameter("@cus_field2",      SqlDbType.NVarChar,   100),
                new SqlParameter("@cus_field3",      SqlDbType.NVarChar,   100),
                new SqlParameter("@cus_field4",      SqlDbType.NVarChar,   100),
                new SqlParameter("@cus_field5",      SqlDbType.NVarChar,   100),
                new SqlParameter("@agentId",         SqlDbType.Int,          4),
            };
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value     = model.orderid;
            parameters[2].Value     = model.ordertype;
            parameters[3].Value     = model.userid;
            parameters[4].Value     = model.typeId;
            parameters[5].Value     = model.paymodeId;
            parameters[6].Value     = model.userorder;
            parameters[7].Value     = model.refervalue;
            parameters[8].Value     = model.notifyurl;
            parameters[9].Value     = model.returnurl;
            parameters[10].Value    = model.attach;
            parameters[11].Value    = model.payerip;
            parameters[12].Value    = model.clientip;
            parameters[13].Value    = model.referUrl;
            parameters[14].Value    = model.addtime;
            parameters[15].Value    = model.supplierId;
            parameters[16].Value    = model.status;
            parameters[17].Value    = model.server;
            parameters[18].Value    = model.manageId;
            parameters[19].Value    = model.version;

            parameters[20].Value = model.cus_subject;
            parameters[21].Value = model.cus_price;
            parameters[22].Value = model.cus_quantity;
            parameters[23].Value = model.cus_description;
            parameters[24].Value = model.cus_field1;
            parameters[25].Value = model.cus_field2;
            parameters[26].Value = model.cus_field3;
            parameters[27].Value = model.cus_field4;
            parameters[28].Value = model.cus_field5;
            parameters[29].Value = model.agentId;

            DataBase.ExecuteNonQuery(System.Data.CommandType.StoredProcedure, "proc_orderbank_add", parameters);
            return((long)parameters[0].Value);
            //}
            //catch (Exception ex)
            //{
            //    viviLib.ExceptionHandling.ExceptionHandler.HandleException(ex);
            //    return 0;
            //}
        }
예제 #21
0
 /// <summary>
 /// This method serializes the order object and send it to the queue for asynchronous processing
 /// </summary>
 /// <param name="order">All information about the order</param>
 public void Insert(OrderBankInfo order)
 {
     asynchOrder.Send(order);
 }
예제 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="supplierId">接口供应商ID</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="supplierOrderId"></param>
        /// <param name="status"></param>
        /// <param name="opstate">状态码</param>
        /// <param name="msg">返回信息</param>
        /// <param name="tranAmt">结算金额</param>
        /// <param name="suppSettleAmt">供应商给平台的结算价</param>
        /// <returns></returns>
        public static FunExecResult InsertToDb(int supplierId
                                               , OrderBankInfo orderInfo
                                               , string supplierOrderId
                                               , int status
                                               , string opstate
                                               , string msg
                                               , decimal tranAmt
                                               , decimal suppSettleAmt)
        {
            var result = new FunExecResult()
            {
                ErrCode = 0,
                ErrMsg  = ""
            };

            string cacheKey = "OrderBankComplete" + orderInfo.orderid + orderInfo.supplierId.ToString(CultureInfo.InvariantCulture);

            object flag = Cache.WebCache.GetCacheService().RetrieveObject(cacheKey);

            if (flag != null)
            {
                return(result);
            }

            try
            {
                orderInfo.supplierId = supplierId;
                orderInfo.status     = status;
                orderInfo.deduct     = 0;

                #region 扣量
                if (BLL.Sys.TransactionSettings.OpenDeduct && status == 2)
                {
                    Model.User.UserInfo userInfo = BLL.User.Factory.GetCacheUserBaseInfo(orderInfo.userid);
                    if (userInfo != null)
                    {
                        //0x3e8 1000 扣率 扣率 = 被扣单的机率是多少
                        if (new Random(Guid.NewGuid().GetHashCode()).Next(1, 1000) <= userInfo.CPSDrate)
                        {
                            orderInfo.deduct = 1;
                        }
                    }
                }
                #endregion

                orderInfo.realvalue    = tranAmt;
                orderInfo.supplierId   = supplierId;
                orderInfo.completetime = DateTime.Now;

                orderInfo.payRate      = 0M;
                orderInfo.payAmt       = 0M;
                orderInfo.promRate     = 0M;
                orderInfo.promAmt      = 0M;
                orderInfo.supplierRate = 0M;
                orderInfo.supplierAmt  = 0M;
                orderInfo.profits      = 0M;

                if (status == 2)
                {
                    if (orderInfo.deduct == 0)
                    {
                        #region 计算费率
                        if (orderInfo.payRate <= 0M)
                        {
                            orderInfo.payRate = BLL.Finance.PayRate.Instance.GetUserPayRate(orderInfo.userid,
                                                                                            orderInfo.typeId);
                        }
                        orderInfo.payAmt = orderInfo.payRate * tranAmt;


                        if (orderInfo.agentId > 0)
                        {
                            //代理费率
                            orderInfo.promRate = BLL.Finance.PayRate.Instance.GetUserPayRate(orderInfo.agentId,
                                                                                             orderInfo.typeId);
                            //代理金额
                            orderInfo.promAmt = (orderInfo.promRate - orderInfo.payRate) * tranAmt;

                            if (orderInfo.promAmt < 0)
                            {
                                orderInfo.promAmt = 0;
                            }
                        }
                        #endregion
                    }
                    if (orderInfo.supplierRate <= 0M)
                    {
                        #region 计算平台费率
                        var chanelInfo = BLL.Channel.Channel.GetModel(orderInfo.paymodeId, orderInfo.userid, false);
                        if (chanelInfo != null)
                        {
                            orderInfo.supplierRate = chanelInfo.supprate;
                        }
                        #endregion
                    }

                    orderInfo.supplierAmt = suppSettleAmt;
                    if (suppSettleAmt > 0 && tranAmt > 0)
                    {
                        orderInfo.supplierRate = suppSettleAmt / tranAmt;
                    }

                    //利润
                    orderInfo.profits = orderInfo.supplierAmt - orderInfo.payAmt - orderInfo.promAmt;
                }

                orderInfo.opstate = opstate;
                orderInfo.msg     = msg;

                orderInfo.supplierOrder = "";
                if (!string.IsNullOrEmpty(supplierOrderId))
                {
                    orderInfo.supplierOrder = supplierOrderId;
                }

                BLLBank.Complete(orderInfo);

                result.ErrCode = 0;
                result.ErrMsg  = "success";

                Cache.WebCache.GetCacheService().AddObject(cacheKey, status, 5);
            }
            catch (System.Threading.ThreadAbortException ex)
            {
                result.ErrCode = 98;
                result.ErrMsg  = ex.Message;
                //
            }
            catch (Exception ex)
            {
                result.ErrCode = 99;
                result.ErrMsg  = ex.Message;
            }

            return(result);
        }
예제 #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderinfo"></param>
        /// <param name="isNotify"></param>
        /// <param name="apiKey"></param>
        /// <returns></returns>
        public static string CreateNotifyUrl(OrderBankInfo orderinfo, bool isNotify, string apiKey)
        {
            string notifyUrl = string.Empty;

            if (orderinfo == null || string.IsNullOrEmpty(apiKey))
            {
                return(notifyUrl);
            }

            notifyUrl = isNotify ? orderinfo.notifyurl : orderinfo.returnurl;

            string refervalue = decimal.Round(orderinfo.refervalue, 2).ToString(CultureInfo.InvariantCulture);
            string realvalue  = "0";

            if (orderinfo.realvalue.HasValue)
            {
                realvalue = decimal.Round(orderinfo.realvalue.Value, 2).ToString(CultureInfo.InvariantCulture);
            }


            string errcode = "116";

            if (orderinfo.status == 2 || orderinfo.status == 8)
            {
                errcode = "0";
            }
            //P_UserId | P_OrderId | P_CardId | P_CardPass | P_FaceValue | P_ChannelId | SalfStr
            string plain = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}"
                                         , orderinfo.userid
                                         , orderinfo.userorder
                                         , string.Empty
                                         , string.Empty
                                         , refervalue
                                         , orderinfo.cus_field2
                                         , apiKey);

            string sign = Cryptography.MD5(plain);

            var parms = new StringBuilder();

            parms.AppendFormat("P_UserId={0}", orderinfo.userid);
            parms.AppendFormat("&P_OrderId={0}", orderinfo.userorder);
            parms.AppendFormat("&P_CardId={0}", string.Empty);
            parms.AppendFormat("&P_CardPass={0}", string.Empty);
            parms.AppendFormat("&P_FaceValue={0}", refervalue);
            parms.AppendFormat("&P_ChannelId={0}", orderinfo.cus_field2);//约定为充值类型
            parms.AppendFormat("&P_PayMoney={0}", realvalue);
            parms.AppendFormat("&P_Subject={0}", orderinfo.cus_subject);
            parms.AppendFormat("&P_Price={0}", orderinfo.cus_price);
            parms.AppendFormat("&P_Quantity={0}", orderinfo.cus_quantity);
            parms.AppendFormat("&P_Description={0}", orderinfo.cus_description);
            parms.AppendFormat("&P_Notic={0}", orderinfo.attach);
            parms.AppendFormat("&P_ErrCode={0}", errcode);
            parms.AppendFormat("&P_ErrMsg={0}", orderinfo.msg);
            parms.AppendFormat("&P_PostKey={0}", sign);

            if (notifyUrl.IndexOf("?", System.StringComparison.Ordinal) > 0)
            {
                notifyUrl = notifyUrl + "&" + parms.ToString();
            }
            else
            {
                notifyUrl = notifyUrl + "?" + parms.ToString();
            }

            return(notifyUrl);
        }
예제 #24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var orderInfo = new OrderBankInfo();

            BanknotifyQueue.Send(orderInfo);
        }
예제 #25
0
        /// <summary>
        ///
        /// </summary>
        void ChargeBank()
        {
            string error = string.Empty;

            #region Step1 必要的参数不能为空
            if (string.IsNullOrEmpty(this.parter))
            {
                error = "error:1001 商户ID(P_UserId)不能空!";
            }
            else if (string.IsNullOrEmpty(orderid))
            {
                error = "error:1004 商户订单号(P_OrderId)不能空!";
            }
            else if (string.IsNullOrEmpty(money))
            {
                error = "error:1003 充值金额(P_FaceValue)不能空!";
            }
            else if (string.IsNullOrEmpty(type))
            {
                error = "error:1002 充值类型(P_ChannelId)不能空!";
            }
            else if (string.IsNullOrEmpty(P_Price))
            {
                error = "error:1007 产品价格(P_Price)不能空!";
            }
            else if (string.IsNullOrEmpty(P_Quantity))
            {
                error = "error:1008 产品数量(P_Quantity)不能空!";
            }
            else if (string.IsNullOrEmpty(notifyurl))
            {
                error = "error:1005 充值状态通知地址(P_Result_URL)不能空!";
            }
            else if (string.IsNullOrEmpty(sign))
            {
                error = "error:1006 MD5签名(sign)不能空!";
            }
            #endregion
            #region Step2 检查参数长度
            else if (this.parter.Length > 10)
            {
                error = "error:1020 商户ID(P_UserId)长度超过10位!";
            }
            else if (orderid.Length > 32)
            {
                error = "error:1022 商户订单号(P_OrderId)长度超过32位!";
            }
            else if (money.Length > 8)
            {
                error = "error:1023 订单金额(P_FaceValue)长度超过最长限制!";
            }
            else if (this.notifyurl.Length > 255)
            {
                error = "error:1024 充值状态通知地址(P_Result_URL)长度超过255位!";
            }
            else if (this.returnurl.Length > 255)
            {
                error = "error:1025 充值后网页跳转地址(P_Notify_URL)长度超过255位!";
            }
            else if (this.attach.Length > 255)
            {
                error = "error:1027 用户附加信息(P_Notic)长度超过255位!";
            }
            else if (this.P_Description.Length > 255)
            {
                error = "error:1029 产品描述(P_Description)长度超过255位!";
            }
            else if (this.P_Subject.Length > 50)
            {
                error = "error:1029 产品描述(P_Subject)长度超过50位!";
            }
            else if (this.sign.Length != 32)
            {
                error = "error:1028 签名认证串(sign)长度不正确!";
            }
            #endregion
            #region Step3 格式验证
            else if (!viviLib.Text.Validate.IsNumeric(parter))
            {
                error = "error:1040 商户ID(P_UserId)格式不正确!";
            }
            else if (!viviLib.Text.Validate.IsNumeric(type))
            {
                error = "error:1041 充值类型(P_ChannelId)格式不正确!";
            }
            else if (!checkOrderMoney())
            {
                error = "error:1042 订单金额(P_FaceValue)格式不正确!";
            }
            else if (!checkPrice())
            {
                error = "error:1045 产品价格(P_Price)格式不正确!";
            }
            else if (!checkPQuantity())
            {
                error = "error:1046 产品数量(P_Quantity)格式不正确!";
            }
            else if (!isNotifyUrlOk())
            {
                error = "error:1043 充值状态通知地址(P_Result_URL)格式不正确!";
            }
            else if (!isReturnUrlOk())
            {
                error = "error:1044 充值后网页跳转地址(P_Notify_URL)格式不正确!";
            }
            #endregion
            #region Step4 数据验证
            else if (SysChannelId <= 0)
            {
                error = "error:1067 不存在此支付通道(P_ChannelId)!";
            }
            else if (TranAmt <= 0M)
            {
                error = "error:1060 订单金额(P_FaceValue)有误!";
            }
            else if (TranAmt < this.MinTranAMT)
            {
                error = "error:1061 订单金额(P_FaceValue)小于最小允许交易额!";
            }
            else if (TranAmt > this.MaxChargeAMT)
            {
                error = string.Format("error:1062 订单金额(P_FaceValue){0:f2}大于最大允许交易额{1:f2}!", TranAmt, this.MaxChargeAMT);
            }
            else if (UserInfo == null)
            {
                error = "error:1064 商户(P_UserId)不存在";
            }
            else if (UserInfo.Status != 2)
            {
                error = "error:1065 商户(P_UserId)状态不正常";
            }
            else if (!viviapi.SysInterface.Bank.HuaQi.ReceiveVerify(version, sign, new object[] { this.parter, this.orderid, this.cardno, this.cardpass, this.money, this.type, UserInfo.APIKey }))
            {
                error = "error:1066 签名认证串(P_PostKey)错误!";
            }
            #endregion

            if (string.IsNullOrEmpty(error))
            {
                ChannelTypeInfo chanTypeInfo = viviapi.BLL.Channel.ChannelType.GetCacheModel(this.SysChannelId);
                if (chanTypeInfo == null)
                {
                    error = "error:1068:不存在此支付通道(P_ChannelId)!";
                }
                else if (chanTypeInfo.isOpen == OpenEnum.Close)
                {
                    error = "error:1069:通道(P_ChannelId)维护中!";
                }
            }

            if (!string.IsNullOrEmpty(error))
            {
                #region 处理日志
                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
                        };
                        debugInfo.url = Request.RawUrl.ToString(CultureInfo.InvariantCulture);

                        viviapi.BLL.Sys.Debuglog.Insert(debugInfo);
                    }
                }

                WebUtility.ShowErrorMsg(error);
                return;

                #endregion
            }
            else
            {
                #region 初始化订单
                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      = viviLib.Web.ServerVariables.TrueIP,
                    completetime  = DateTime.Now,
                    returnurl     = returnurl,
                    ordertype     = 1,
                    typeId        = SysChannelId,
                    paymodeId     = string.Empty,
                    supplierId    = 0,
                    supplierOrder = string.Empty,
                    userid        = Userid,
                    userorder     = orderid,
                    refervalue    = TranAmt
                };
                //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;
                order.manageId = UserInfo.manageId;

                order.version         = version;
                order.cus_subject     = this.P_Subject;
                order.cus_price       = this.P_Price;
                order.cus_quantity    = this.P_Quantity;
                order.cus_description = this.P_Description;
                order.cus_field2      = type;

                viviapi.Cache.WebCache.GetCacheService().AddObject(order.orderid, order, ExpiresTime);
                //
                orderBankBLL.Insert(order);
                #endregion

                string redirectUrl = "/SelectBank.aspx?sysorderid=" + order.orderid;
                Response.Redirect(redirectUrl, true);
            }
        }
예제 #26
0
        /// <summary>
        ///  结算
        /// </summary>
        public bool Complete(OrderBankInfo model)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter("@suppId",        SqlDbType.Int),
                new SqlParameter("@orderid",       SqlDbType.VarChar,   30),
                new SqlParameter("@userId",        SqlDbType.Int),
                new SqlParameter("@typeId",        SqlDbType.Int),
                new SqlParameter("@status",        SqlDbType.TinyInt),
                new SqlParameter("@deduct",        SqlDbType.TinyInt),
                new SqlParameter("@supplierOrder", SqlDbType.VarChar,   50),
                new SqlParameter("@realvalue",     SqlDbType.Decimal,    9),
                new SqlParameter("@payRate",       SqlDbType.Decimal,    9),
                new SqlParameter("@supplierRate",  SqlDbType.Decimal,    9),
                new SqlParameter("@payAmt",        SqlDbType.Decimal,    9),
                new SqlParameter("@supplierAmt",   SqlDbType.Decimal,    9),
                new SqlParameter("@profits",       SqlDbType.Decimal,    9),
                new SqlParameter("@addtime",       SqlDbType.DateTime),
                new SqlParameter("@completetime",  SqlDbType.DateTime),
                new SqlParameter("@manageId",      SqlDbType.Int),
                new SqlParameter("@promRate",      SqlDbType.Decimal,    9),
                new SqlParameter("@promAmt",       SqlDbType.Decimal,    9),
                new SqlParameter("@promId",        SqlDbType.Int)
            };
            parameters[0].Value  = model.supplierId;
            parameters[1].Value  = model.orderid;
            parameters[2].Value  = model.userid;
            parameters[3].Value  = model.typeId;
            parameters[4].Value  = model.status;
            parameters[5].Value  = model.deduct;
            parameters[6].Value  = model.supplierOrder;
            parameters[7].Value  = model.realvalue;
            parameters[8].Value  = model.payRate;
            parameters[9].Value  = model.supplierRate;
            parameters[10].Value = model.payAmt;
            parameters[11].Value = model.supplierAmt;
            parameters[12].Value = model.profits;
            parameters[13].Value = DateTime.Now;
            parameters[14].Value = model.completetime;
            parameters[15].Value = model.manageId;
            parameters[16].Value = model.promRate;
            parameters[17].Value = model.promAmt;
            parameters[18].Value = model.agentId;

            /*
             *  1 不存在此订单
             * 2 订单已处理
             * 3
             *          0 处理成功
             */
            object result = DataBase.ExecuteScalar(CommandType.StoredProcedure, "proc_orderbank_settled", parameters);

            if (result == DBNull.Value)
            {
                return(false);
            }

            byte bresult = Convert.ToByte(result);

            bool sucess = (bresult == 0 || bresult == 2);

            return(sucess);
        }
예제 #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderInfo"></param>
        public static void ReturnToMerchant(OrderBankInfo orderInfo)
        {
            string returnUrl = GetReturnUrl(orderInfo);

            HttpContext.Current.Response.Redirect(returnUrl, true);
        }
예제 #28
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 = 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);
        }
예제 #29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string   error = string.Empty, apikey = string.Empty;
            decimal  tranAmt  = decimal.Zero;
            UserInfo userInfo = null;
            int      userId   = 1080;
            //请求的集合
            NameValueCollection nvcSource = Request.Form == null && Request.Form.Count > 0 ? Request.Form : Request.QueryString;
            string data      = nvcSource["data"];
            string aeskey    = "1234567890123456";
            string preEncode = AESUtil.Decrypt(data, aeskey);
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(preEncode);
            NameValueCollection nvc = new NameValueCollection();

            foreach (var item in dic)
            {
                nvc.Add(item.Key, item.Value);
            }
            //数据验证
            string Money   = nvc["amount"];
            string Orderid = nvc["requestid"];

            Notifyurl = nvc["callbackurl"];
            #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, 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 (!VerifyHmac(nvc, 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;
            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                              = "",
                ordertype                              = 1,
                typeId                                 = typeId,
                paymodeId                              = 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)
            {
                order.agentId = viviapi.BLL.User.Factory.GetPromID(userId);
            }
            viviapi.Cache.WebCache.GetCacheService().AddObject(order.orderid, order, ExpiresTime);
            //
            NewOrder.Insert(order);

            //viviapi.ETAPI.ebao.EBaoApi api = new viviapi.ETAPI.ebao.EBaoApi();
            //string ret = string.Empty;
            ////if (nvc.AllKeys.Contains("p8_FrpId") && !string.IsNullOrEmpty(nvc.Get("p8_FrpId")))
            ////{
            ////    ret = api.Pay(nvc, "2");
            ////    Response.Write(ret);
            ////}
            ////else
            ////{
            ////    ret = api.Pay(nvc, "1");
            ////    Response.Redirect(ret);
            ////}
            //ret = api.Pay(nvc, "1");

            viviapi.ETAPI.ebao2.EBaoNewApi api = new EBaoNewApi();
            string ret = api.Pay(nvc, HttpContext.Current);
            return;
        }
예제 #30
0
 /// <summary>
 /// This method serializes the order object and send it to the queue for asynchronous processing
 /// </summary>
 /// <param name="order">All information about the order</param>
 public void Complete(OrderBankInfo order)
 {
     asynchOrder.Complete(order);
 }