public ActionResult Index(string etnum)
        {
            if (etnum.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "Some Error[00]";
                return(View("Error"));
            }
            string    tnum      = LokFuEncode.LokFuAPIDecode(etnum, DllName);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "Some Error[02]";
                return(View("Error"));
            }
            FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == FastOrder.PayWay);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "Some Error[03]";
                return(View("Error"));
            }
            if (FastPayWay.DllName != DllName)
            {
                ViewBag.ErrorMsg = "Some Error[04]";
                return(View("Error"));
            }
            string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
            if (PayConfigArr.Length != 3)
            {
                ViewBag.ErrorMsg = "Some Error[05]";
                return(View("Error"));
            }
            FastUserPay FastUserPay = Entity.FastUserPay.FirstOrDefault(n => n.PayWay == FastOrder.PayWay && n.UId == FastOrder.UId && n.MerState == 1);

            if (FastUserPay == null)
            {
                ViewBag.ErrorMsg = "商户通道异常";
                return(View("Error"));
            }

            string paywaycode = PayConfigArr[2];                                   //绑定通道
            string OrderMoney = (FastOrder.Amoney * 100).ToString("F0");           //金额,以分为单
            string ReturnUrl  = PayPath + "/PayCenter/HFJSPay/FastResult.html";    //支付成功跳转页
            string BackUrl    = NoticePath + "/PayCenter/HFJSPay/FastNotice.html"; //后台通过地址

            string Data = "{\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + FastUserPay.MerId + "\",\"paywaycode\":\"" + paywaycode + "\",\"orderid\":\"" + FastOrder.TNum + "\",\"backurl\":\"" + BackUrl + "\",\"fronturl\":\"" + ReturnUrl + "\"}";

            string DataBase64 = LokFuEncode.Base64Encode(Data, "utf-8");
            string Sign       = (DataBase64 + FastUserPay.MerKey).GetMD5();

            string GoUrl = "https://api.zhifujiekou.com/apis/fastorderspay?";

            GoUrl += "req=" + HttpUtility.UrlEncode(DataBase64);
            GoUrl += "&sign=" + Sign;

            Response.Redirect(GoUrl);

            return(View("Null"));
        }
Exemplo n.º 2
0
        public void Execute(IJobExecutionContext context)
        {
            string JobName = "OutMoney";
            string CanRun  = ConfigurationManager.AppSettings["Run" + JobName].ToString();

            if (CanRun == "true")
            {
                if (!IsRun)
                {
                    LokFuEntity Entity = new LokFuEntity();
                    IsRun = true;
                    try
                    {
                        Log.Write(JobName + "任务开始执行!");
                        //-------------------------------------------------------
                        #region 任务主体
                        #region 全局变量
                        SysSet BasicSet = Entity.SysSet.FirstOrDefault();

                        string NoticePath = ConfigurationManager.AppSettings["NoticePath"].ToString();
                        string NoticeUrl  = NoticePath + "/PayCenter/HFCash/Notice.html";
                        //提交结算中心
                        string merId  = ConfigurationManager.AppSettings["Cash_merId"].ToString();  //商户号
                        string merKey = ConfigurationManager.AppSettings["Cash_merKey"].ToString(); //商户密钥
                        #endregion
                        //0=无效,1=待执行,2=执行中,3=完成
                        IList <TaskCash> TaskCashList = Entity.TaskCash.Where(n => n.State == 1 || n.State == 2).OrderBy(n => n.Id).ToList();
                        //读取待执行
                        foreach (var P in TaskCashList)
                        {
                            //任务状态设置为执行中
                            if (P.State == 1)
                            {
                                P.State = 2;
                                P.STime = DateTime.Now;
                                Entity.SaveChanges();
                            }
                            IList <TaskCashInfo> TaskCashInfoList = Entity.TaskCashInfo.Where(n => (n.State == 1 || n.State == 2) && n.TId == P.Id).OrderBy(n => n.Id).ToList();
                            foreach (var p in TaskCashInfoList)
                            {
                                if (p.State == 1)
                                {
                                    p.State = 2;
                                    p.STime = DateTime.Now;
                                    Entity.SaveChanges();
                                }
                                OrderCash OC     = Entity.OrderCash.FirstOrDefault(n => n.OId == p.OId);
                                bool      CanPay = true;
                                if (OC == null)
                                {
                                    CanPay = false;
                                }
                                if (OC.FState == 1)//已付过款
                                {
                                    CanPay = false;
                                }
                                if (OC.OrderState != 2 || OC.PayState != 1)
                                {
                                    CanPay = false;
                                }
                                if (CanPay)//开启自动结算时执行
                                {
                                    if (BasicSet.CashPayWay == 0)
                                    {
                                        p.State  = 3;//标识成功
                                        p.OState = 2;
                                        p.NState = 1;
                                        p.Remark = "批量人工结算";
                                        p.ETime  = DateTime.Now;

                                        OC.PayState = 2;
                                        OC.FState   = 1;
                                        OC.FTime    = DateTime.Now;
                                        Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId);
                                        if (O != null)
                                        {
                                            O.PayState   = 2;
                                            O.InternalRm = "批量人工结算";
                                        }
                                        Entity.SaveChanges();
                                        //======分润======
                                        OC = OC.PayAgent(Entity, 1);
                                        if (O != null)
                                        {
                                            O.AgentPayGet = (decimal)OC.AgentCashGet;
                                        }
                                        Entity.SaveChanges();
                                    }
                                    else if (BasicSet.CashPayWay == 1)
                                    {
                                        #region 提交接口
                                        string  orderId    = OC.OId;//商户流水号
                                        decimal PayMoney   = OC.Amoney - (decimal)OC.UserRate;
                                        decimal money      = PayMoney * 100;
                                        long    intmoney   = Int64.Parse(money.ToString("F0"));
                                        string  OrderMoney = intmoney.ToString();//金额,以分为单


                                        string UserCardId = Entity.Users.FirstOrNew(n => n.Id == OC.UId).CardId;
                                        string PostJson   = "{\"action\":\"QCash\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\",\"bin\":\"" + OC.Bin + "\",\"accno\":\"" + OC.CardNum + "\",\"accname\":\"" + OC.Owner + "\",\"cardno\":\"" + UserCardId + "\"}";

                                        //传送数据Base64
                                        string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");

                                        //获得签名
                                        string Sign = (DataBase64 + merKey).GetMD5();

                                        //传送数据UrlEnCode
                                        DataBase64 = System.Web.HttpUtility.UrlEncode(DataBase64);

                                        //组装Post数据
                                        string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);

                                        string HFNFC_Url = "https://api.zhifujiekou.com/api/qcashgateway";

                                        //Post数据,获得结果
                                        string  Ret     = Utils.PostRequest(HFNFC_Url, PostData, "utf-8");
                                        string  runType = "PayOk";
                                        JObject JS      = new JObject();
                                        try
                                        {
                                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                        }
                                        catch (Exception)
                                        {
                                            Utils.WriteLog("[" + OC.OId + "]" + Ret, "PayCashCenterErr");
                                            runType = "PayIng";
                                        }
                                        string Remark = "";
                                        if (runType == "PayOk")
                                        {
                                            if (JS != null)
                                            {
                                                string resp = JS["resp"].ToString();
                                                Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                                                try
                                                {
                                                    JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                                }
                                                catch (Exception)
                                                {
                                                    runType = "PayIng";
                                                }
                                                if (runType == "PayOk")
                                                {
                                                    if (JS != null)
                                                    {
                                                        string respcode = JS["respcode"].ToString();
                                                        if (respcode != "00")
                                                        {
                                                            if (respcode == "45")
                                                            {
                                                                //限额了,需要特别处理
                                                                runType = "PayErr";
                                                            }
                                                            else
                                                            {
                                                                runType = "PayIng";
                                                            }
                                                            Remark = JS["respmsg"].ToString();
                                                        }
                                                        else
                                                        {
                                                            string resultcode = JS["resultcode"].ToString();
                                                            if (resultcode == "0000")
                                                            {
                                                                runType = "PayOk";
                                                            }
                                                            else if (resultcode == "2002" || resultcode == "2003")
                                                            {
                                                                runType = "PayErr";
                                                                Remark  = JS["resultmsg"].ToString();
                                                            }
                                                            else
                                                            {
                                                                runType = "PayIng";
                                                                Remark  = JS["resultmsg"].ToString();
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        runType = "PayIng";
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                runType = "PayIng";
                                            }
                                        }

                                        if (runType == "PayIng")
                                        {
                                            //处理中
                                            p.ETime = DateTime.Now;
                                            p.State = 5;//标识 未知状态
                                            Entity.SaveChanges();
                                        }
                                        if (runType == "PayErr")
                                        {
                                            OC.PayState = 3;
                                            OC.Remark   = Remark;
                                            p.State     = 4;//标识失败
                                            p.OState    = 2;
                                            p.NState    = 1;
                                            p.Remark    = Remark;
                                            p.ETime     = DateTime.Now;
                                            Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId);
                                            if (O != null)
                                            {
                                                O.PayState = 3;
                                                O.Remark   = Remark;
                                            }
                                            Entity.SaveChanges();
                                        }
                                        if (runType == "PayOk")
                                        {
                                            OC.PayState = 2;
                                            OC.FState   = 1;
                                            OC.FTime    = DateTime.Now;
                                            p.State     = 3;//标识成功
                                            p.OState    = 2;
                                            p.NState    = 1;
                                            p.ETime     = DateTime.Now;
                                            Entity.SaveChanges();
                                            OC = OC.PayAgent(Entity, 1);//======分润======
                                            Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId);
                                            if (O != null)
                                            {
                                                O.PayState    = 2;
                                                O.AgentPayGet = (decimal)OC.AgentCashGet;
                                                Entity.SaveChanges();
                                            }
                                        }
                                        Log.WriteLog("执行提现:" + p.OId, JobName);
                                        Thread.Sleep(1000);
                                        #endregion
                                    }
                                }
                                else
                                {
                                    p.Remark = "订单状态不符,需查单!";
                                    p.ETime  = DateTime.Now;
                                    p.State  = 5;//标识 未知状态
                                    Entity.SaveChanges();
                                }
                            }
                            //当前任务所有子项执行完成
                            int state1 = Entity.TaskCashInfo.Count(n => n.State == 1 && n.TId == P.Id);
                            int state2 = Entity.TaskCashInfo.Count(n => n.State == 2 && n.TId == P.Id);
                            int state3 = Entity.TaskCashInfo.Count(n => n.State == 3 && n.TId == P.Id);
                            int state4 = Entity.TaskCashInfo.Count(n => n.State == 4 && n.TId == P.Id);
                            int state5 = Entity.TaskCashInfo.Count(n => n.State == 5 && n.TId == P.Id);
                            if (state1 == 0 && state2 == 0)
                            {
                                P.State = 3;
                                P.ETime = DateTime.Now;
                            }
                            P.Success = state3 + state5;
                            P.Fail    = state4;
                            Entity.SaveChanges();
                            Log.WriteLog("TaskCashInfo任务执行完毕!共计" + TaskCashInfoList.Count + "笔交易", JobName);
                        }
                        Log.WriteLog("TaskCash任务执行完毕!共计" + TaskCashList.Count + "个任务", JobName);
                        #endregion
                        //-------------------------------------------------------
                        Log.Write(JobName + "任务执行结算!");
                    }
                    catch (Exception Ex)
                    {
                        Log.Write(JobName + "任务执行过程出错!", Ex);
                    }
                    IsRun = false;
                }
                else
                {
                    Log.Write(JobName + "任务还在执行中!");
                }
            }
        }
        public ActionResult Index(string etnum)
        {
            if (etnum.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "Some Error[00]";
                return(View("Error"));
            }
            string    tnum      = LokFuEncode.LokFuAPIDecode(etnum, DllName);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "Some Error[02]";
                return(View("Error"));
            }
            FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == FastOrder.PayWay);

            if (FastPayWay == null)
            {
                ViewBag.ErrorMsg = "Some Error[03]";
                return(View("Error"));
            }
            if (FastPayWay.DllName != DllName)
            {
                ViewBag.ErrorMsg = "Some Error[04]";
                return(View("Error"));
            }
            string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
            if (PayConfigArr.Length != 3)
            {
                ViewBag.ErrorMsg = "Some Error[05]";
                return(View("Error"));
            }
            FastUser FastUser = Entity.FastUser.FirstOrNew(n => n.UId == FastOrder.UId);

            string merId  = PayConfigArr[0];                             //商户号
            string merKey = PayConfigArr[1];                             //商户密钥
            string PayWay = PayConfigArr[2];                             //绑定通道

            string orderId    = FastOrder.TNum;                          //商户流水号
            string OrderMoney = (FastOrder.Amoney * 100).ToString("F0"); //金额,以分为单

            string TrueName = FastUser.TrueName;
            string CardId   = FastUser.CardId;

            //填写参数
            string ReturnUrl = PayPath + "/PayCenter/HFPay/FastResult.html";    //支付成功跳转页
            string BackUrl   = NoticePath + "/PayCenter/HFPay/FastNotice.html"; //后台通过地址


            if (TrueName.IsNullOrEmpty() || CardId.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "TrueName IsNull";
                return(View("Error"));
            }
            if (FastPayWay.Id == 8)
            {
                PayWay = "3855";
            }
            //if (FastPayWay.Id == 13)
            //{
            //    PayWay = "3852";
            //}

            string Data = "{\"action\":\"goAndPay\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"payway\":\"" + PayWay + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + BackUrl + "\",\"fronturl\":\"" + ReturnUrl + "\",\"accname\":\"" + TrueName + "\",\"accno\":\"" + CardId + "\"}";

            string DataBase64 = LokFuEncode.Base64Encode(Data, "utf-8");
            string Sign       = (DataBase64 + merKey).GetMD5();

            string GoUrl = "https://api.zhifujiekou.com/apis/gateway?";

            GoUrl += "req=" + HttpUtility.UrlEncode(DataBase64);
            GoUrl += "&sign=" + Sign;

            Response.Redirect(GoUrl);

            return(View("Null"));
        }
        private ActionResult WeiXinPay(Users Users, decimal Amount, PayConfig PayConfig, SysControl SysControl)
        {
            if (Users.Token.IsNullOrEmpty())
            {
                Users.Token = DateTime.Now.ToString().GetMD5();
                Entity.SaveChanges();
            }

            int InType = 0;

            if (SysControl.LagEntryNum > 0)
            {
                InType = 1;
            }

            #region 微信支付
            string PostJson = "{amoney:" + Amount.ToString("F2") + ",token:\"" + Users.Token + "\",payid:\"shop\",otype:8,action:\"Create\",x:\"0\",y:\"0\",intype:\"" + InType + "\",payway:\"" + PayConfig.Id + "\",orderaddress:\"网店收银台,IP:" + Utils.GetAddressAndIp() + "\",ip:\"" + Utils.GetIP() + "\"}";
            //提交数据
            string PostData = LokFuEncode.LokFuAPIEncode(PostJson, Shop_Keys);
            PostData = HttpUtility.UrlEncode(PostData);
            //Post参数
            string PostString = "eno=" + Shop_ENO + "&data=" + PostData + "&code=0000";
            //AppPath = "http://localhost:2610";
            string  url       = AppPath + "/API/OrderQC/";
            string  RetString = Utils.PostRequest(url, PostString, "utf-8");
            JObject json      = new JObject();
            try
            {
                json = (JObject)JsonConvert.DeserializeObject(RetString);
            }
            catch (Exception)
            {
                ViewBag.ErrorMsg = "接口数据有误![01]";
                return(View("Error"));
            }
            if (json == null)
            {
                ViewBag.ErrorMsg = "接口数据有误![02]";
                return(View("Error"));
            }
            string code = "";
            string data = "";
            try
            {
                code = json["code"].ToString();
                data = json["data"].ToString();
            }
            catch (Exception)
            {
                ViewBag.ErrorMsg = "接口数据有误![03]";
                return(View("Error"));
            }
            if (code != "0000")
            {
                ViewBag.ErrorMsg = "交易有误![" + code + "]";
                return(View("Error"));
            }
            //解密
            string  RetData = LokFuEncode.LokFuAPIDecode(data, Shop_Keys);
            JObject Json    = new JObject();
            try
            {
                Json = (JObject)JsonConvert.DeserializeObject(RetData);
            }
            catch (Exception)
            {
                ViewBag.ErrorMsg = "数据解析有误![01]";
                return(View("Error"));
            }
            if (Json == null)
            {
                ViewBag.ErrorMsg = "数据解析有误![02]";
                return(View("Error"));
            }
            Orders Orders = new Orders();
            Orders = JsonToObject.ConvertJsonToModel(Orders, Json);
            if (Orders.PayId.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "订单信息有误";
                return(View("Error"));
            }
            string   PayId        = Orders.PayId;
            string[] PayConfigArr = PayConfig.QueryArray.Split(new char[] { ',' });
            if (PayConfig.DllName == "WeiXin")
            {
                string AppId  = PayConfigArr[0];
                string AppKey = PayConfigArr[2];

                WxPayData jsApiParam = new WxPayData();
                jsApiParam.SetValue("appId", AppId);
                jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp());
                jsApiParam.SetValue("nonceStr", WxPayApi.GenerateNonceStr());
                jsApiParam.SetValue("package", "prepay_id=" + PayId);
                jsApiParam.SetValue("signType", "MD5");
                jsApiParam.SetValue("paySign", jsApiParam.MakeSign(AppKey));
                string Parameters = jsApiParam.ToJson();
                ViewBag.Parameters = Parameters;
                Orders             = Entity.Orders.FirstOrNew(n => n.TNum == Orders.TNum);
                ViewBag.Orders     = Orders;
                return(View("WeiXinPay"));
            }
            else if (PayConfig.DllName == "HFWeiXin")
            {
                //提交结算中心
                string merId      = PayConfigArr[0]; //商户号
                string merKey     = PayConfigArr[1]; //商户密钥
                string orderId    = Orders.TNum;     //商户流水号
                string myData     = "{\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\",\"code\":\"" + PayId + "\"}";
                string DataBase64 = LokFuEncode.Base64Encode(myData, "utf-8");
                string Sign       = (DataBase64 + merKey).GetMD5();
                DataBase64 = HttpUtility.UrlEncode(DataBase64);
                string myUrl = string.Format("req={0}&sign={1}", DataBase64, Sign);
                string Url   = "https://api.zhifujiekou.com/wxjsapi/gopay.html?" + myUrl;
                //Response.Redirect(Url);
                return(this.Redirect(Url));
            }
            else
            {
                return(View("Null"));
            }
            //return View("Null");
            #endregion
        }
Exemplo n.º 5
0
        public void Execute(IJobExecutionContext context)
        {
            string JobName = "FastQuery";
            string CanRun  = ConfigurationManager.AppSettings["Run" + JobName].ToString();

            if (CanRun == "true")
            {
                if (!IsRun)
                {
                    LokFuEntity Entity = new LokFuEntity();
                    IsRun = true;
                    try
                    {
                        Log.Write(JobName + "任务开始执行!");
                        //-------------------------------------------------------
                        #region 任务主体
                        //查询所有已支付但未代付订单
                        DateTime          STime = DateTime.Now.AddDays(-1);
                        DateTime          ETime = DateTime.Now.AddSeconds(-30);
                        IList <FastOrder> List  = Entity.FastOrder.Where(n => n.State == 1 && n.PayState == 1 && n.UserState == 3 && n.UserTime <ETime && n.UserTime> STime).ToList();
                        //UserState 0未付 1已付 2失败 3结果未明 4付起中
                        foreach (var p in List)
                        {
                            FastPayWay  FastPayWay  = Entity.FastPayWay.FirstOrDefault(n => n.Id == p.PayWay && n.State == 1);
                            FastUserPay FastUserPay = Entity.FastUserPay.FirstOrDefault(n => n.PayWay == p.PayWay && n.UId == p.UId);
                            if (FastPayWay != null)
                            {
                                string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
                                if (FastPayWay.DllName == "HFPay")
                                {
                                    #region 查代付结果
                                    if (PayConfigArr.Length == 3)
                                    {
                                        string HF_Url     = "https://api.zhifujiekou.com/api/qcashquery";
                                        string MerId      = PayConfigArr[0];
                                        string MerKey     = PayConfigArr[1];
                                        string orderId    = p.TNum;//商户流水号
                                        string PostJson   = "{\"merid\":\"" + MerId + "\",\"orderid\":\"" + orderId + "\"}";
                                        string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                                        string Sign       = (DataBase64 + MerKey).GetMD5();
                                        DataBase64 = HttpUtility.UrlEncode(DataBase64);
                                        string  PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                                        string  Ret      = Utils.PostRequest(HF_Url, PostData, "utf-8");
                                        JObject JS       = new JObject();
                                        try
                                        {
                                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                        }
                                        catch (Exception)
                                        {
                                            JS = null;
                                        }
                                        if (JS != null)
                                        {
                                            if (JS["resp"] != null)
                                            {
                                                string resp = JS["resp"].ToString();
                                                Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                                                try
                                                {
                                                    JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                                }
                                                catch (Exception)
                                                {
                                                    JS = null;
                                                }
                                                if (JS != null)
                                                {
                                                    string respcode = JS["respcode"].ToString();
                                                    if (respcode == "00")
                                                    {
                                                        string resultcode = JS["resultcode"].ToString();
                                                        if (resultcode == "0000")
                                                        {
                                                            p.UserState = 1;
                                                        }
                                                        else if (resultcode == "2002" || resultcode == "2003")
                                                        {
                                                            p.UserState = 2;
                                                        }
                                                        else
                                                        {
                                                        }
                                                        Entity.SaveChanges();
                                                    }
                                                }
                                            }
                                        }
                                        //================================================
                                        PayLog PayLog = new PayLog();
                                        PayLog.PId     = FastPayWay.Id;
                                        PayLog.OId     = p.TNum;
                                        PayLog.TId     = "";
                                        PayLog.Amount  = 0;
                                        PayLog.Way     = "FASTDFQ";
                                        PayLog.AddTime = DateTime.Now;
                                        PayLog.Data    = Ret;
                                        PayLog.State   = 1;
                                        Entity.PayLog.AddObject(PayLog);
                                        //================================================
                                        Entity.SaveChanges();
                                    }
                                    #endregion
                                }
                                if (FastPayWay.DllName == "HFJSPay")
                                {
                                    #region 结算系统
                                    //不需要
                                    fastordersqueryModel fastordersqueryModel = new fastordersqueryModel()
                                    {
                                        merid   = FastUserPay.MerId,
                                        orderid = "",
                                        queryid = p.TNum
                                    };
                                    fastordersqueryResult fastordersqueryResult = HFJSTools.fastordersquery(fastordersqueryModel, FastUserPay.MerKey);
                                    //================================================
                                    //记录通知信息
                                    PayLog PayLog = new PayLog();
                                    PayLog.PId     = p.PayWay.Value;
                                    PayLog.OId     = p.TNum;
                                    PayLog.TId     = fastordersqueryResult.queryid;
                                    PayLog.Amount  = p.Amoney;
                                    PayLog.Way     = "FASTDFQ";
                                    PayLog.AddTime = DateTime.Now;
                                    PayLog.Data    = HFJSTools.MyObjectToJson(fastordersqueryResult);
                                    PayLog.State   = 1;
                                    Entity.PayLog.AddObject(PayLog);
                                    Entity.SaveChanges();
                                    //================================================
                                    if (fastordersqueryResult.respcode == "00")
                                    {
                                        if (fastordersqueryResult.resultcode == "0000")
                                        {
                                            p.UserState = 1;
                                            Entity.SaveChanges();
                                        }
                                        if (fastordersqueryResult.resultcode == "1003")
                                        {
                                            p.UserState = 2;
                                            Entity.SaveChanges();
                                        }
                                    }
                                    else
                                    {
                                        string resp_desc = fastordersqueryResult.respmsg;
                                        Utils.WriteLog("HFJS[Query][" + p.TNum + "]:" + resp_desc, "JobHFJS");
                                    }
                                    #endregion
                                }
                            }
                            Log.WriteLog("查询代付[" + p.TNum + "]!", JobName);
                        }
                        #endregion
                        //-------------------------------------------------------
                        Log.Write(JobName + "任务执行结束![共计" + List.Count + "条]");
                    }
                    catch (Exception Ex)
                    {
                        Log.Write(JobName + "任务执行过程出错!", Ex);
                    }
                    IsRun = false;
                }
                else
                {
                    Log.Write(JobName + "任务还在执行中!");
                }
            }
        }
Exemplo n.º 6
0
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[OrderNFC]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }

            OrderF2F OrderF2F = new OrderF2F();

            OrderF2F = JsonToObject.ConvertJsonToModel(OrderF2F, json);

            UserTrack UserTrack = new UserTrack();

            UserTrack = JsonToObject.ConvertJsonToModel(UserTrack, json);

            #region 获取并处理用户信息
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == OrderF2F.Token);
            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                //DataObj.OutError("2006");
                //return;
            }
            if (baseUsers.MiBao != 1)//未设置支付密码
            {
                //DataObj.OutError("2008");
                //return;
            }
            string NeekName = baseUsers.NeekName;
            if (NeekName.IsNullOrEmpty())
            {
                NeekName = baseUsers.TrueName;
            }
            if (NeekName.IsNullOrEmpty())
            {
                NeekName = "货款";
            }
            #endregion

            if (OrderF2F.Action == "Create")
            {
                //处理交易地点
                if (OrderF2F.X.IsNullOrEmpty() || OrderF2F.Y.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
                int PayWay = OrderF2F.PayWay;
                if (PayWay.IsNullOrEmpty())
                {
                    PayWay = 7;//兼容老版本
                }

                //获取系统支付配置
                PayConfig PayConfig = Entity.PayConfig.FirstOrDefault(n => n.Id == PayWay && n.State == 1);
                if (PayConfig == null)
                {
                    DataObj.OutError("1000");
                    return;
                }
                if (PayConfig.GroupType != "NFC")
                {
                    DataObj.OutError("1000");
                    return;
                }
                int InType = 0;
                if (!OrderF2F.InType.IsNullOrEmpty())
                {
                    InType = 1;
                }
                SysControl SysControl = new SysControl();
                #region 版本比较 升级之后比较长时间后可以考滤删除版本判断代码
                bool IsNew     = true;
                var  vSysAgent = this.Entity.SysAgent.FirstOrDefault(o => o.Id == baseUsers.Agent);
                if (vSysAgent == null)
                {
                    DataObj.OutError("1000");
                    return;
                }
                IsNew = BizExt.NewOrOldVersion(vSysAgent, Equipment, this.Entity);
                #endregion
                if (IsNew)//新版
                {
                    if (InType == 1)
                    {
                        SysControl = Entity.SysControl.FirstOrDefault(n => n.Tag == "NFC" && n.PayWay == PayWay && n.LagEntryDay > 0);
                    }
                    else
                    {
                        SysControl = Entity.SysControl.FirstOrDefault(n => n.Tag == "NFC" && n.PayWay == PayWay && n.LagEntryDay == 0);
                    }
                }
                else//旧版
                {
                    SysControl = Entity.SysControl.FirstOrDefault(n => n.Tag == "NFC" && n.PayWay == PayWay);
                }

                //获取系统支付配置
                if (SysControl == null)
                {
                    DataObj.OutError("1005");
                    return;
                }
                SysControl syscontrol = SysControl.ChkState();
                if (syscontrol.State != 1)
                {
                    DataObj.OutError("1005");
                    return;
                }

                #region 创建交易
                OrderF2F.PayWay  = PayWay;
                OrderF2F.PayType = 0;
                OrderF2F.PayId   = PayConfig.DllName;
                OrderF2F.OType   = 9; //NFC

                //开始处理参数 PayId扣款码,OType通道,7支付宝,8微信
                if (OrderF2F.Amoney.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
                OrderF2F.Amoney = OrderF2F.Amoney.FormatMoney();

                //获取用户支付配置
                UserPay UserPay = Entity.UserPay.FirstOrDefault(n => n.UId == baseUsers.Id && n.PId == PayConfig.Id);
                if (UserPay == null)
                {
                    DataObj.OutError("1000");
                    return;
                }

                //获取分支机构信息
                SysAgent SysAgent = new SysAgent();
                if (!baseUsers.Agent.IsNullOrEmpty())
                {
                    SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == baseUsers.Agent);
                }


                //获取系统配置
                SysSet SysSet = Entity.SysSet.FirstOrDefault();
                if (InType == 1)
                {//客户端传来T+N但是系统没开启时无效
                    if (SysSet.LagEntry == 0)
                    {
                        InType = 0;
                    }
                }
                if (InType == 1)
                {
                    //手续费
                    OrderF2F.Poundage = 0;
                    //商户费率
                    OrderF2F.UserRate = 0;
                    //T+n时,代理佣金为 交易金额*费率
                    decimal AgentPayGet = OrderF2F.Amoney * SysSet.AgentGet;
                    OrderF2F.AgentPayGet = (Double)AgentPayGet;
                    //佣金舍位
                    OrderF2F.AgentPayGet = OrderF2F.AgentPayGet.Floor();
                }
                else
                {
                    //手续费
                    OrderF2F.Poundage = OrderF2F.Amoney * (decimal)UserPay.Cost;
                    //手续费取进
                    OrderF2F.Poundage = OrderF2F.Poundage.Ceiling();
                    //商户费率
                    OrderF2F.UserRate = UserPay.Cost;
                    //分支机构佣金设置为0,待分润计算后再写入
                    OrderF2F.AgentPayGet = 0;
                }

                OrderF2F.UId = baseUsers.Id;

                //到帐金额=支付金额-手续费
                OrderF2F.PayMoney = OrderF2F.Amoney - OrderF2F.Poundage;
                //第三方支付通道率
                OrderF2F.SysRate = (double)PayConfig.Cost;
                //这里是利润计算==========
                //利润=总金额-到帐-支付手续费
                decimal GetAll = OrderF2F.Amoney - OrderF2F.PayMoney - OrderF2F.Amoney * (decimal)OrderF2F.SysRate;
                //利润舍位
                GetAll = GetAll.Floor();
                //总利润
                OrderF2F.AIdPayGet = (double)GetAll;

                OrderF2F.Agent      = SysAgent.Id;//分支机构Id
                OrderF2F.AId        = baseUsers.AId;
                OrderF2F.FId        = 0;
                OrderF2F.OrderState = 1;
                OrderF2F.PayState   = 0;
                OrderF2F.AgentState = 0;
                OrderF2F.AddTime    = DateTime.Now;

                //写入前,判断交易金额限制
                if (OrderF2F.Amoney < syscontrol.SNum || OrderF2F.Amoney > syscontrol.ENum)
                {
                    DataObj.OutError("1006");
                    return;
                }

                //写入订单总表
                Orders Orders = new Orders();
                Orders.UId   = OrderF2F.UId;
                Orders.TName = NeekName;

                Orders.PayType = OrderF2F.PayType;
                Orders.PayName = "NFC";

                Orders.RUId     = 0;
                Orders.RName    = string.Empty;
                Orders.TType    = OrderF2F.OType;
                Orders.TState   = 1;
                Orders.Amoney   = OrderF2F.Amoney;
                Orders.Poundage = OrderF2F.Poundage;
                Orders.AddTime  = DateTime.Now;
                Orders.PayState = 0;
                Orders.PayWay   = PayConfig.Id;

                Orders.Agent      = OrderF2F.Agent;
                Orders.AgentState = 0;
                Orders.AId        = OrderF2F.AId;
                Orders.FId        = 0;

                string OrderAddress = OrderF2F.OrderAddress;
                if (OrderAddress.IsNullOrEmpty())
                {
                    OrderAddress = Utils.GetAddressByGPS(OrderF2F.X, OrderF2F.Y);
                }
                Orders.OrderAddress = OrderAddress;
                Orders.X            = OrderF2F.X;
                Orders.Y            = OrderF2F.Y;

                if (InType == 1)
                {
                    if (IsNew)//新版
                    {
                        Orders.LagEntryDay = SysControl.LagEntryDay;
                        Orders.LagEntryNum = SysControl.LagEntryNum;
                    }
                    else
                    {
                        Orders.LagEntryDay = SysSet.LagEntryDay;
                        Orders.LagEntryNum = SysSet.LagEntryNum;
                    }
                }
                else
                {
                    Orders.LagEntryDay = 0;
                    Orders.LagEntryNum = 0;
                }

                Entity.Orders.AddObject(Orders);
                Entity.SaveChanges();
                Entity.Refresh(RefreshMode.StoreWins, Orders);

                OrderF2F.OId = Orders.TNum;
                Entity.OrderF2F.AddObject(OrderF2F);
                Entity.SaveChanges();

                //=======================================
                UserTrack.ENo        = DataObj.ENo;
                UserTrack.OPType     = Orders.PayName;
                UserTrack.UserName   = Orders.TNum;
                UserTrack.GPSAddress = Orders.OrderAddress;
                UserTrack.GPSX       = Orders.X;
                UserTrack.GPSY       = Orders.Y;
                Orders.SeavGPSLog(UserTrack, Entity);
                //=======================================

                if (PayConfig.DllName == "NFC")
                {
                    string[] PayConfigArr = PayConfig.QueryArray.Split(',');
                    if (PayConfigArr.Length != 2)
                    {
                        DataObj.OutError("1000");
                        return;
                    }

                    string NoticeUrl = NoticePath + "/PayCenter/NFC/Notice.html";

                    NFCObj NFCObj = new NFCObj();
                    NFCObj.merchantCode    = PayConfigArr[0];                           //      商户编码
                    NFCObj.outOrderId      = Orders.TNum;                               //		订单号
                    NFCObj.outUserId       = Orders.UId.ToString();                     //		用户编号
                    NFCObj.orderCreateTime = Orders.AddTime.ToString("yyyyMMddHHmmss"); //		订单生成时间20140423112324
                    NFCObj.nonceStr        = Utils.RandomSMSCode(10);                   //		随机字符串
                    NFCObj.goodName        = Orders.TName;                              //		商品名称
                    NFCObj.goodsExplain    = Orders.TNum;;                              //		商品详情
                    NFCObj.totalAmount     = (Orders.Amoney * 100).ToString("F0");      //		订单金额	100
                    NFCObj.payNotifyUrl    = NoticeUrl;                                 //		支付通知地址
                    NFCObj.sign            = PayConfigArr[1];
                    NFCObj.lastPayTime     = "";
                    //===================================
                    JavaScriptSerializer jss = new JavaScriptSerializer();
                    string jsonString        = jss.Serialize(NFCObj);
                    try
                    {
                        json = (JObject)JsonConvert.DeserializeObject(jsonString);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[OrderNFC_My]:", "【jsonString】" + jsonString, Ex);
                    }
                    Orders.Json = json;
                }
                else if (PayConfig.DllName == "HFNFC")
                {
                    string NoticeUrl = NoticePath + "/PayCenter/HFNFC/Notice.html";

                    string[] PayConfigArr = PayConfig.QueryArray.Split(',');
                    if (PayConfigArr.Length != 3)
                    {
                        DataObj.OutError("1000");
                        return;
                    }
                    //提交结算中心
                    string merId    = PayConfigArr[0]; //商户号
                    string merKey   = PayConfigArr[1]; //商户密钥
                    string JsPayWay = PayConfigArr[2]; //绑定通道

                    string  orderId    = Orders.TNum;  //商户流水号
                    decimal money      = Orders.Amoney * 100;
                    long    intmoney   = Int64.Parse(money.ToString("F0"));
                    string  OrderMoney = intmoney.ToString();//金额,以分为单

                    string PostJson = "{\"action\":\"getOrder\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"payway\":\"" + JsPayWay + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\"}";

                    string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                    string Sign       = (DataBase64 + merKey).GetMD5();

                    DataBase64 = HttpUtility.UrlEncode(DataBase64);
                    string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);

                    string HFNFC_Url = "https://api.zhifujiekou.com/api/nfcgateway";

                    string Ret = Utils.PostRequest(HFNFC_Url, PostData, "utf-8");

                    JObject JS = new JObject();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[OrderNFC_HF]:", "【Ret】" + Ret, Ex);
                    }
                    if (JS == null)
                    {
                        DataObj.OutError("1000");
                        return;
                    }
                    string resp = JS["resp"].ToString();
                    Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[OrderNFC_HF]:", "【Ret2】" + Ret, Ex);
                    }
                    if (JS == null)
                    {
                        DataObj.OutError("1000");
                        return;
                    }
                    string respcode = JS["respcode"].ToString();
                    if (respcode != "00")
                    {
                        string respmsg = JS["respmsg"].ToString();
                        DataObj.OutError("1000");
                        Utils.WriteLog("[OrderNFC_HF_Err]:【" + respcode + "】" + respmsg, "orderface");
                        return;
                    }
                    JObject Json = (JObject)JS["webform"];
                    Orders.Json = Json;
                }
                Orders.Cols  = Orders.Cols + ",Json";
                DataObj.Data = Orders.OutJson();
                DataObj.Code = "0000";
                DataObj.OutString();
                #endregion
            }
            if (OrderF2F.Action == "GET")//获取订交易信息
            {
                //开始处理参数
                if (OrderF2F.OId.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
                Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == OrderF2F.OId && n.UId == baseUsers.Id);
                if (Orders == null)
                {
                    DataObj.OutError("1000");
                    return;
                }
                OrderF2F  Orderf2f  = Entity.OrderF2F.FirstOrDefault(n => n.OId == OrderF2F.OId && n.UId == baseUsers.Id);
                PayConfig PayConfig = Entity.PayConfig.FirstOrNew(n => n.Id == Orders.PayWay);
                if (Orders.TState == 1 && Orders.PayState == 0)
                {
                    if (PayConfig.DllName == "NFC")
                    {
                        //1000000951,f38e989d-900f-4768-8a01-f6667a21f7d3
                        string[] QueryArr = PayConfig.QueryArray.Split(',');
                        if (QueryArr.Length == 2)
                        {
                            string merchantCode = QueryArr[0];
                            string Key          = QueryArr[1];
                            string outOrderId   = Orders.TNum;
                            string dataStr      = "merchantCode=" + merchantCode + "&outOrderId=" + outOrderId;
                            string signStr      = dataStr + "&KEY=" + Key;
                            string sign         = signStr.GetMD5().ToUpper();
                            string dataJson     = "{\"merchantCode\":\"" + merchantCode + "\",\"outOrderId\":\"" + outOrderId + "\",\"sign\":\"" + sign + "\"}";
                            string postData     = "{\"param\":" + dataJson + ",\"project_id\":\"WEPAYPLUGIN_PAY\"}";
                            string postUrl      = "https://payment.kklpay.com/query/queryOrder.do";
                            string Ret          = Utils.GetPostJson(postUrl, postData);
                            //"{"code":"00","data":{"amount":1,"instructCode":"11001998044","merchantCode":"1000000951","outOrderId":"201511170900077","replyCode":"00","sign":"EA778C87B5ACDCBC7735BB78C15CAC72","transTime":"20151117174726","transType":"00200"},"msg":"成功"}"
                            JObject JS = new JObject();
                            try
                            {
                                JS = (JObject)JsonConvert.DeserializeObject(Ret);
                            }
                            catch (Exception Ex)
                            {
                                Utils.WriteLog("[OrderNFC]:JSON[" + Ret + "]" + Ex.ToString(), "orderface");
                            }
                            if (JS != null)
                            {
                                string code = JS["code"].ToString();//返回状态--
                                if (code == "00")
                                {
                                    JObject JSD = (JObject)JS["data"];
                                    if (JSD != null)
                                    {
                                        string amount        = JSD["amount"].ToString();       //交易金额 单位分
                                        string instructCode  = JSD["instructCode"].ToString(); //交易单号
                                        string merchantCodeR = JSD["merchantCode"].ToString(); //商户号
                                        string outOrderIdR   = JSD["outOrderId"].ToString();   //订单号
                                        string replyCode     = JSD["replyCode"].ToString();    //交易状态
                                        string transTime     = JSD["transTime"].ToString();    //交易时间
                                        string transType     = JSD["transType"].ToString();    //交易类型
                                        string signR         = JSD["sign"].ToString();
                                        //================================================
                                        PayLog PayLog = new PayLog();
                                        PayLog.PId     = PayConfig.Id;
                                        PayLog.OId     = outOrderId;
                                        PayLog.TId     = instructCode;
                                        PayLog.Amount  = decimal.Parse(amount) / 100;
                                        PayLog.Way     = "GET";
                                        PayLog.AddTime = DateTime.Now;
                                        PayLog.Data    = Ret;
                                        PayLog.State   = 1;
                                        Entity.PayLog.AddObject(PayLog);
                                        Entity.SaveChanges();
                                        //================================================
                                        if (replyCode == "00")
                                        {
                                            if (merchantCodeR == merchantCode)
                                            {
                                                int factmoney = int.Parse(amount);
                                                if (((int)(Orders.Amoney * 100)) == factmoney)
                                                {
                                                    //Orders.PayState = 1;//此处不保存支付状态,由通知返回再操作
                                                    Orders = Orders.PaySuccess(Entity);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //PaySuccess
                    }
                    else if (PayConfig.DllName == "HFNFC")
                    {
                        string[] QueryArr = PayConfig.QueryArray.Split(',');
                        if (QueryArr.Length == 3)
                        {
                            //提交结算中心
                            string merId      = QueryArr[0]; //商户号
                            string merKey     = QueryArr[1]; //商户密钥
                            string orderId    = Orders.TNum; //商户流水号
                            string PostJson   = "{\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\"}";
                            string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                            string Sign       = (DataBase64 + merKey).GetMD5();
                            DataBase64 = HttpUtility.UrlEncode(DataBase64);
                            string PostData  = string.Format("req={0}&sign={1}", DataBase64, Sign);
                            string HFNFC_Url = "https://api.zhifujiekou.com/api/query";
                            string Ret       = Utils.PostRequest(HFNFC_Url, PostData, "utf-8");

                            JObject JS = new JObject();
                            try
                            {
                                JS = (JObject)JsonConvert.DeserializeObject(Ret);
                            }
                            catch (Exception Ex)
                            {
                                Log.Write("[OrderNFC_HFQuery]:", "【Ret】" + Ret, Ex);
                            }
                            if (JS == null)
                            {
                                DataObj.OutError("1000");
                                return;
                            }
                            string resp = JS["resp"].ToString();
                            Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                            try
                            {
                                JS = (JObject)JsonConvert.DeserializeObject(Ret);
                            }
                            catch (Exception Ex)
                            {
                                Log.Write("[OrderNFC_HFQuery]:", "【Ret2】" + Ret, Ex);
                            }
                            if (JS == null)
                            {
                                DataObj.OutError("1000");
                                return;
                            }
                            string respcode = JS["respcode"].ToString();
                            if (respcode != "00")
                            {
                                string respmsg = JS["respmsg"].ToString();
                                DataObj.OutError("1000");
                                Utils.WriteLog("[OrderNFC_HFQuery_Err]:【" + respcode + "】" + respmsg, "orderface");
                                return;
                            }
                            string resultcode = JS["resultcode"].ToString();
                            if (resultcode == "0000" || resultcode == "1002" || resultcode == "1004")
                            {
                                string txnamt    = JS["txnamt"].ToString();
                                int    factmoney = int.Parse(txnamt);
                                if (((int)(Orders.Amoney * 100)) == factmoney)
                                {
                                    //Orders.PayState = 1;//此处不保存支付状态,由通知返回再操作
                                    Orders = Orders.PaySuccess(Entity);
                                }
                            }
                        }
                        //PaySuccess
                    }
                }
                DataObj.Data = Orders.OutJson();
                DataObj.Code = "0000";
                DataObj.OutString();
            }
        }
        private byte GetCardType(string BankNum)
        {
            string HaoFu_Auth_MerId  = ConfigurationManager.AppSettings["HaoFu_Auth_MerId"].ToString();
            string HaoFu_Auth_MerKey = ConfigurationManager.AppSettings["HaoFu_Auth_MerKey"].ToString();

            string data       = "{\"action\":\"bankcard\",\"merid\":\"" + HaoFu_Auth_MerId + "\",\"bankaccount\":\"" + BankNum + "\"}";
            string DataBase64 = LokFuEncode.Base64Encode(data, "utf-8");
            string Sign       = (DataBase64 + HaoFu_Auth_MerKey).GetMD5();

            DataBase64 = HttpUtility.UrlEncode(DataBase64, Encoding.UTF8);
            string postdata = "req=" + DataBase64 + "&sign=" + Sign;

            string CONTENT = Utils.PostRequest("https://api.zhifujiekou.com/api/bankcardtype", postdata, "utf-8");

            JObject JS = new JObject();

            try
            {
                JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
            }
            catch (Exception Ex)
            {
                Log.Write("[GetCardType]:", "【CONTENT】" + CONTENT, Ex);
            }
            if (JS == null)
            {
                return(0);
            }
            string resp = JS["resp"].ToString();

            CONTENT = LokFuEncode.Base64Decode(resp, "utf-8");
            try
            {
                JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
            }
            catch (Exception Ex)
            {
                Log.Write("[GetCardType]:", "【CONTENT2】" + CONTENT, Ex);
            }
            if (JS == null)
            {
                return(0);
            }
            string ret_code = JS["respcode"].ToString();

            if (ret_code == "0000")
            {
                string CardType = JS["cardtype"].ToString();
                if (CardType == "1")
                {
                    return(1);
                }
                if (CardType == "2")
                {
                    return(2);
                }
                return(0);
            }
            else
            {
                return(0);
            }
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[OrderQC]:", "【Data】" + Data, Ex);
                json = null;
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            OrderF2F OrderF2F = new OrderF2F();

            OrderF2F = JsonToObject.ConvertJsonToModel(OrderF2F, json);

            UserTrack UserTrack = new UserTrack();

            UserTrack = JsonToObject.ConvertJsonToModel(UserTrack, json);

            #region 获取并处理用户信息
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == OrderF2F.Token);
            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                //DataObj.OutError("2006");
                //return;
            }
            if (baseUsers.MiBao != 1)//未设置支付密码
            {
                //DataObj.OutError("2008");
                //return;
            }
            string NeekName = baseUsers.NeekName;
            if (NeekName.IsNullOrEmpty())
            {
                NeekName = baseUsers.TrueName;
            }
            if (NeekName.IsNullOrEmpty())
            {
                NeekName = "货款";
            }
            #endregion
            #region 创建交易
            if (OrderF2F.Action == "Create")
            {
                #region 处理选择通道
                int PayWay = OrderF2F.PayWay;

                string Tag     = "";
                byte   PayType = 1;
                string PayName = "";
                string OpenId  = ""; //微信JSAPI专用
                if (OrderF2F.OType == 7)
                {                    //支付宝
                    Tag = "AliPay";
                }
                if (OrderF2F.OType == 8)
                {//微信
                    Tag = "WeiXin";
                }

                if (PayWay.IsNullOrEmpty())
                {
                    if (Tag == "AliPay")
                    {
                        PayWay = 5;//兼容老版本
                    }
                    if (Tag == "WeiXin")
                    {
                        PayWay = 6;//兼容老版本
                    }
                }

                PayConfig PayConfig = Entity.PayConfig.FirstOrDefault(n => n.Id == PayWay && n.State == 1);
                //获取系统支付配置
                if (PayConfig == null)
                {
                    DataObj.OutError("1000");
                    return;
                }
                if (PayConfig.GroupType != Tag)
                {
                    DataObj.OutError("1000");
                    return;
                }
                PayName = "扫码付-" + PayConfig.Name;
                byte ComeWay = 1;
                if (!OrderF2F.PayId.IsNullOrEmpty())
                {
                    if (OrderF2F.PayId == "shop")
                    {
                        ComeWay = 2;
                    }
                    PayName = "收银台-" + PayConfig.Name;
                    if (OrderF2F.OType == 7)
                    {
                        if (OrderF2F.PayId == "shop")
                        {
                            OrderF2F.PayId = string.Empty;
                            PayType        = 2;
                        }
                    }
                    if (OrderF2F.OType == 8)
                    {
                        OpenId         = OrderF2F.PayId;
                        OrderF2F.PayId = string.Empty;
                        PayType        = 2;
                    }
                }
                int InType = 0;
                if (!OrderF2F.InType.IsNullOrEmpty())
                {
                    InType = 1;
                }
                SysControl SysControl = new SysControl();
                bool       IsNew      = true;
                if (OrderF2F.Id.IsNullOrEmpty())
                {
                    //这是旧逻辑,有一些旧版还在用
                    #region 版本比较 升级之后比较长时间后可以考滤删除版本判断代码
                    var vSysAgent = this.Entity.SysAgent.FirstOrDefault(o => o.Id == baseUsers.Agent);
                    if (vSysAgent == null)
                    {
                        DataObj.OutError("1000");
                        return;
                    }
                    IsNew = BizExt.NewOrOldVersion(vSysAgent, Equipment, this.Entity);
                    #endregion
                    if (IsNew)//新版
                    {
                        if (InType == 1)
                        {
                            SysControl = Entity.SysControl.FirstOrDefault(n => n.Tag == Tag && n.PayWay == PayWay && n.LagEntryDay > 0);
                        }
                        else
                        {
                            SysControl = Entity.SysControl.FirstOrDefault(n => n.Tag == Tag && n.PayWay == PayWay && n.LagEntryDay == 0);
                        }
                    }
                    else//旧版
                    {
                        SysControl = Entity.SysControl.FirstOrDefault(n => n.Tag == Tag && n.PayWay == PayWay);
                    }
                }
                else
                {
                    SysControl = Entity.SysControl.FirstOrDefault(n => n.Id == OrderF2F.Id);
                    if (SysControl.LagEntryDay > 0)
                    {
                        InType = 1;
                    }
                    else
                    {
                        InType = 0;
                    }
                }
                //获取系统支付配置
                if (SysControl == null)
                {
                    DataObj.OutError("1005");
                    return;
                }
                if (InType == 1 && (SysControl.LagEntryDay.IsNullOrEmpty() || SysControl.LagEntryNum.IsNullOrEmpty()))
                {
                    DataObj.Msg = "请升级到最新版再发起Tn到帐交易!";
                    DataObj.OutError("1005");
                    return;
                }
                SysControl syscontrol = SysControl.ChkState();
                if (syscontrol.State != 1)
                {
                    DataObj.OutError("1005");
                    return;
                }
                #endregion

                #region 订单生成
                //处理交易地点
                if (OrderF2F.X.IsNullOrEmpty() || OrderF2F.Y.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
                //开始处理参数 OType通道,7支付宝,8微信
                if (OrderF2F.Amoney.IsNullOrEmpty() || OrderF2F.OType.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
                OrderF2F.Amoney = OrderF2F.Amoney.FormatMoney();

                //获取用户支付配置
                UserPay UserPay = Entity.UserPay.FirstOrDefault(n => n.UId == baseUsers.Id && n.PId == PayWay);
                if (UserPay == null)
                {
                    DataObj.OutError("1000");
                    return;
                }
                //获取分支机构信息
                SysAgent SysAgent = new SysAgent();
                if (!baseUsers.Agent.IsNullOrEmpty())
                {
                    SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == baseUsers.Agent);
                }

                OrderF2F.PayWay = PayWay;

                //获取系统配置
                SysSet SysSet = Entity.SysSet.FirstOrDefault();
                if (InType == 1)
                {//客户端传来T+N但是系统没开启时无效
                    if (SysSet.LagEntry == 0)
                    {
                        InType = 0;
                    }
                }
                if (InType == 1)
                {
                    //手续费
                    OrderF2F.Poundage = 0;
                    //商户费率
                    OrderF2F.UserRate = 0;
                    //T+n时,代理佣金为 交易金额*费率
                    decimal AgentPayGet = OrderF2F.Amoney * SysSet.AgentGet;
                    OrderF2F.AgentPayGet = (Double)AgentPayGet;
                    //佣金舍位
                    OrderF2F.AgentPayGet = OrderF2F.AgentPayGet.Floor();
                }
                else
                {
                    //手续费
                    OrderF2F.Poundage = OrderF2F.Amoney * (decimal)UserPay.Cost;
                    //手续费取进
                    OrderF2F.Poundage = OrderF2F.Poundage.Ceiling();
                    //商户费率
                    OrderF2F.UserRate = UserPay.Cost;
                    //分支机构佣金设置为0,待分润计算后再写入
                    OrderF2F.AgentPayGet = 0;
                }

                OrderF2F.UId = baseUsers.Id;
                //到帐金额=支付金额-手续费
                OrderF2F.PayMoney = OrderF2F.Amoney - OrderF2F.Poundage;
                //第三方支付通道率
                OrderF2F.SysRate = (double)PayConfig.Cost;
                //这里是利润计算==========
                //利润=总金额-到帐-支付手续费
                decimal GetAll = OrderF2F.Amoney - OrderF2F.PayMoney - OrderF2F.Amoney * (decimal)OrderF2F.SysRate;
                //利润舍位
                GetAll = GetAll.Floor();
                //总利润
                OrderF2F.AIdPayGet = (double)GetAll;


                OrderF2F.Agent      = SysAgent.Id;//分支机构Id
                OrderF2F.AId        = baseUsers.AId;
                OrderF2F.FId        = 0;
                OrderF2F.OrderState = 1;
                OrderF2F.PayState   = 0;
                OrderF2F.AgentState = 0;
                OrderF2F.AddTime    = DateTime.Now;
                OrderF2F.PayId      = string.Empty;
                OrderF2F.PayType    = PayType;

                //写入前,判断交易金额限制
                if (OrderF2F.Amoney < syscontrol.SNum || OrderF2F.Amoney > syscontrol.ENum)
                {
                    DataObj.OutError("1006");
                    return;
                }
                //写入订单总表
                Orders Orders = new Orders();
                Orders.UId   = OrderF2F.UId;
                Orders.TName = NeekName;

                Orders.PayType = PayType;
                Orders.PayName = PayName;

                Orders.RUId     = 0;
                Orders.RName    = string.Empty;
                Orders.TType    = OrderF2F.OType;
                Orders.TState   = 1;
                Orders.Amoney   = OrderF2F.Amoney;
                Orders.Poundage = OrderF2F.Poundage;
                Orders.AddTime  = DateTime.Now;
                Orders.PayState = 0;
                Orders.PayWay   = PayConfig.Id;

                Orders.Agent      = OrderF2F.Agent;
                Orders.AgentState = 0;
                Orders.AId        = OrderF2F.AId;
                Orders.FId        = 0;
                Orders.ComeWay    = ComeWay;
                string OrderAddress = OrderF2F.OrderAddress;
                if (OrderAddress.IsNullOrEmpty())
                {
                    OrderAddress = Utils.GetAddressByGPS(OrderF2F.X, OrderF2F.Y);
                }
                Orders.OrderAddress = OrderAddress;
                Orders.X            = OrderF2F.X;
                Orders.Y            = OrderF2F.Y;

                if (InType == 1)
                {
                    if (IsNew)//新版
                    {
                        Orders.LagEntryDay = SysControl.LagEntryDay;
                        Orders.LagEntryNum = SysControl.LagEntryNum;
                    }
                    else
                    {
                        Orders.LagEntryDay = SysSet.LagEntryDay;
                        Orders.LagEntryNum = SysSet.LagEntryNum;
                    }
                }
                else
                {
                    Orders.LagEntryDay = 0;
                    Orders.LagEntryNum = 0;
                }

                Entity.Orders.AddObject(Orders);
                Entity.SaveChanges();
                Entity.Refresh(RefreshMode.StoreWins, Orders);

                OrderF2F.OId = Orders.TNum;
                Entity.OrderF2F.AddObject(OrderF2F);
                Entity.SaveChanges();

                //=======================================
                UserTrack.ENo        = DataObj.ENo;
                UserTrack.OPType     = Orders.PayName;
                UserTrack.UserName   = Orders.TNum;
                UserTrack.GPSAddress = Orders.OrderAddress;
                UserTrack.GPSX       = Orders.X;
                UserTrack.GPSY       = Orders.Y;
                if (!OrderF2F.IP.IsNullOrEmpty())
                {
                    UserTrack.IP = OrderF2F.IP;
                }
                Orders.SeavGPSLog(UserTrack, Entity);
                //=======================================

                #endregion

                if (PayConfig.DllName == "AliPay")
                {
                    #region 提交支付宝
                    string[] PayConfigArr = PayConfig.QueryArray.Split(new char[] { ',' });    //接口信息 商户号,密钥,支付宝号
                    if (PayConfigArr.Length != 3)
                    {
                        DataObj.OutError("9999");
                        return;
                    }
                    if (AlipayVer == "1.0")
                    {
                        #region 1.0老接口
                        Submit Submit = new Submit();
                        Submit.pid = PayConfigArr[0];
                        Submit.key = PayConfigArr[1];
                        //卖家支付宝帐户
                        string seller_email = PayConfigArr[2];

                        //订单业务类型
                        string product_code = "QR_CODE_OFFLINE";
                        //SOUNDWAVE_PAY_OFFLINE:声波支付,FINGERPRINT_FAST_PAY:指纹支付,BARCODE_PAY_OFFLINE:条码支付

                        ////////////////////////////////////////////////////////////////////////////////////////////////
                        //把请求参数打包成数组
                        SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();
                        sParaTemp.Add("partner", Submit.pid);
                        sParaTemp.Add("_input_charset", "utf-8");
                        sParaTemp.Add("service", "alipay.acquire.precreate");

                        sParaTemp.Add("out_trade_no", OrderF2F.OId);
                        sParaTemp.Add("subject", Orders.TName + ":" + OrderF2F.OId);
                        sParaTemp.Add("product_code", product_code);
                        sParaTemp.Add("total_fee", OrderF2F.Amoney.ToString("F2"));
                        sParaTemp.Add("seller_email", seller_email);

                        sParaTemp.Add("notify_url", NoticePath + "/PayCenter/AliPay/Notice.html");
                        //建立请求
                        string sHtmlText = Submit.BuildRequest(sParaTemp);
                        Utils.WriteLog(sHtmlText, "orderface");
                        try
                        {
                            XmlDocument xmlDoc = new XmlDocument();
                            xmlDoc.LoadXml(sHtmlText);
                            string is_success = xmlDoc.SelectSingleNode("/alipay/is_success").InnerText;
                            if (is_success == "T")
                            {
                                string result_code = xmlDoc.SelectSingleNode("/alipay/response/alipay/result_code").InnerText;
                                if (result_code == "SUCCESS")
                                {
                                    //成功
                                    string qr_code = xmlDoc.SelectSingleNode("/alipay/response/alipay/qr_code").InnerText;

                                    /*
                                     * voucher_type 凭证类型
                                     * qr_code 二维码码串
                                     * pic_url 二维码图片地址
                                     * small_pic_ur 二维码小图地址
                                     */
                                    OrderF2F.PayId = qr_code;
                                    Entity.SaveChanges();
                                    Orders.PayId = qr_code;
                                }
                                else
                                {
                                    Orders.TState       = 0;
                                    OrderF2F.OrderState = 0;
                                    Entity.SaveChanges();
                                }
                            }
                            else
                            {
                                Orders.TState       = 0;
                                OrderF2F.OrderState = 0;
                                Entity.SaveChanges();
                            }
                        }
                        catch (Exception)
                        {
                            //Utils.WriteLog(Ex.ToString());
                            Orders.TState       = 0;
                            OrderF2F.OrderState = 0;
                            Entity.SaveChanges();
                        }
                        #endregion
                    }
                    if (AlipayVer == "2.0")
                    {
                        #region 2.0新接口

                        ALF2FPAY ALF2FPAY = new ALF2FPAY();
                        ALF2FPAY.pid   = PayConfigArr[0];
                        ALF2FPAY.appId = PayConfigArr[2];
                        IAopClient    client = new DefaultAopClient(ALF2FPAY.serverUrl, ALF2FPAY.appId, ALF2FPAY.merchant_private_key, "json", ALF2FPAY.version, ALF2FPAY.sign_type, ALF2FPAY.alipay_public_key, ALF2FPAY.charset);
                        StringBuilder sb     = new StringBuilder();
                        sb.Append("{");
                        sb.Append("\"out_trade_no\":\"" + OrderF2F.OId + "\",");
                        sb.Append("\"total_amount\":\"" + OrderF2F.Amoney.ToMoney() + "\",");
                        sb.Append("\"timeout_express\":\"30m\",");
                        sb.Append("\"subject\":\"" + OrderF2F.OId + "\"");
                        sb.Append("}");
                        AlipayTradePrecreateRequest payRequst = new AlipayTradePrecreateRequest();

                        string notify_url = NoticePath + "/PayCenter/AliPay/Notice.html";
                        payRequst.SetNotifyUrl(notify_url);

                        payRequst.BizContent = sb.ToString();

                        Dictionary <string, string>  paramsDict  = (Dictionary <string, string>)payRequst.GetParameters();
                        AlipayTradePrecreateResponse payResponse = client.Execute(payRequst);

                        if (payResponse != null)
                        {
                            payResponse.SaveLog(Entity);    //保存记录
                            if (payResponse.Code == "10000")
                            {
                                OrderF2F.PayId = payResponse.QrCode;
                                Entity.SaveChanges();
                                Orders.PayId = payResponse.QrCode;
                            }
                            else
                            {
                                Orders.TState       = 0;
                                OrderF2F.OrderState = 0;
                                Entity.SaveChanges();
                            }
                        }
                        else
                        {
                            Orders.TState       = 0;
                            OrderF2F.OrderState = 0;
                            Entity.SaveChanges();
                        }
                        #endregion
                    }
                    #endregion
                }
                if (PayConfig.DllName == "WeiXin")
                {
                    #region 提交微信
                    //初始化支付配置
                    WxPayConfig WxPayConfig  = new WxPayConfig();
                    string[]    PayConfigArr = PayConfig.QueryArray.Split(new char[] { ',' }); //接口信息 appid,mchid,key,appsecret
                    if (PayConfigArr.Length != 4 && PayConfigArr.Length != 5)
                    {
                        DataObj.OutError("9999");
                        return;
                    }
                    string ServerIp     = ConfigurationManager.AppSettings["ServerIp"].ToString();
                    string Wx_Cert_Path = ConfigurationManager.AppSettings["Wx_Cert_Path"].ToString();
                    string Wx_Cert_PWD  = ConfigurationManager.AppSettings["Wx_Cert_PWD"].ToString();
                    WxPayConfig.IP        = ServerIp;
                    WxPayConfig.APPID     = PayConfigArr[0];
                    WxPayConfig.MCHID     = PayConfigArr[1];
                    WxPayConfig.KEY       = PayConfigArr[2];
                    WxPayConfig.APPSECRET = PayConfigArr[3];
                    if (PayConfigArr.Length == 5)
                    {
                        WxPayConfig.SubMCHID = PayConfigArr[4];
                    }
                    WxPayConfig.SSLCERT_PATH     = Wx_Cert_Path;
                    WxPayConfig.SSLCERT_PASSWORD = Wx_Cert_PWD;
                    //支付配置结束

                    WxPayData data = new WxPayData();
                    //data.SetValue("auth_code", OrderF2F.PayId);//授权码
                    data.SetValue("body", Orders.TName + ":" + OrderF2F.OId); //商品描述
                    string total_fee = (OrderF2F.Amoney * 100).ToString("F0");
                    data.SetValue("total_fee", total_fee);                    //总金额
                    data.SetValue("out_trade_no", OrderF2F.OId);              //产生随机的商户订单号
                    if (PayType == 2)
                    {
                        data.SetValue("trade_type", "JSAPI");    //交易类型
                        if (PayConfigArr.Length == 5)
                        {                                        //子商户模式
                            data.SetValue("sub_openid", OpenId); //用户OpenId
                        }
                        else
                        {
                            data.SetValue("openid", OpenId);    //用户OpenId
                        }
                    }
                    else
                    {
                        data.SetValue("trade_type", "NATIVE");    //交易类型
                    }

                    data.SetValue("notify_url", NoticePath + "/PayCenter/WeiXinPay/Notice.html"); //异步通知地址
                    WxPayData result = WxPayApi.UnifiedOrder(data, WxPayConfig, 10);              //调用统一下单接口
                    result.SaveLog(Entity);

                    if (!result.IsSet("return_code") || result.GetValue("return_code").ToString() == "FAIL")
                    {    //支付失败
                        Orders.TState       = 0;
                        OrderF2F.OrderState = 0;
                        Entity.SaveChanges();
                    }
                    else
                    {
                        if (!result.CheckSign(WxPayConfig.KEY))
                        {    //签名失败,取消订单
                            Orders.TState       = 0;
                            OrderF2F.OrderState = 0;
                            Entity.SaveChanges();
                        }
                        else
                        {
                            if (result.GetValue("return_code").ToString() == "SUCCESS" && result.GetValue("result_code").ToString() == "SUCCESS")
                            {
                                //获取支付字符串
                                if (PayType == 2)    //JSAPI
                                {
                                    string PayId = result.GetValue("prepay_id").ToString();
                                    OrderF2F.PayId = PayId;
                                }
                                else
                                {
                                    string PayId = result.GetValue("code_url").ToString();
                                    OrderF2F.PayId = PayId;
                                }
                                Entity.SaveChanges();
                                Orders.PayId = OrderF2F.PayId;
                            }
                            else
                            {
                                //业务明确失败
                                Orders.TState       = 0;
                                OrderF2F.OrderState = 0;
                                Entity.SaveChanges();
                            }
                        }
                    }
                    #endregion
                }


                #region 提交好付
                if (PayConfig.DllName == "HFAliPay" || PayConfig.DllName == "HFWeiXin")
                {
                    string NoticeUrl = "";
                    string Action    = "";
                    if (PayConfig.DllName == "HFAliPay")
                    {
                        NoticeUrl = NoticePath + "/PayCenter/HFAliPay/Notice.html";
                        Action    = "AliSao";
                    }
                    if (PayConfig.DllName == "HFWeiXin")
                    {
                        NoticeUrl = NoticePath + "/PayCenter/HFWeiXin/Notice.html";
                        if (PayType == 2)
                        {
                            Action = "WxJsApi";
                        }
                        else
                        {
                            Action = "WxSao";
                        }
                    }
                    string[] PayConfigArr = PayConfig.QueryArray.Split(',');
                    if (PayConfigArr.Length != 3)
                    {
                        DataObj.OutError("1000");
                        return;
                    }
                    //提交结算中心
                    string merId    = PayConfigArr[0]; //商户号
                    string merKey   = PayConfigArr[1]; //商户密钥
                    string JsPayWay = PayConfigArr[2]; //绑定通道

                    string  orderId    = Orders.TNum;  //商户流水号
                    decimal money      = Orders.Amoney * 100;
                    long    intmoney   = Int64.Parse(money.ToString("F0"));
                    string  OrderMoney = intmoney.ToString();//金额,以分为单

                    string OpenIdStr = "";
                    if (PayConfig.Id == 13)
                    {
                        //特殊处理通道
                        Action = "WxJsApi";
                        OpenId = "OpenId";
                    }
                    if (Action == "WxJsApi")
                    {
                        OpenIdStr = ",\"openid\":\"" + OpenId + "\"";
                    }

                    string PostJson = "{\"action\":\"" + Action + "\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"payway\":\"" + JsPayWay + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\"" + OpenIdStr + "}";

                    string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                    string Sign       = (DataBase64 + merKey).GetMD5();

                    DataBase64 = HttpUtility.UrlEncode(DataBase64);
                    string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);

                    string HF_Url = "https://api.zhifujiekou.com/api/mpgateway";

                    string Ret = Utils.PostRequest(HF_Url, PostData, "utf-8");

                    JObject JS = new JObject();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[Order_HF]:", "【PostData】" + PostData + "\n【Ret】" + Ret, Ex);
                        json = null;
                    }
                    if (JS == null)
                    {
                        DataObj.OutError("1000");
                        return;
                    }
                    string resp = JS["resp"].ToString();
                    Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[Order_HF]:", "【Ret2】" + Ret, Ex);
                        JS = null;
                    }
                    if (JS == null)
                    {
                        DataObj.OutError("1000");
                        return;
                    }
                    string respcode = JS["respcode"].ToString();
                    if (respcode != "00")
                    {
                        string respmsg = JS["respmsg"].ToString();
                        DataObj.OutError("1000");
                        Utils.WriteLog("[Order_HF_Err]:【" + respcode + "】" + respmsg, "orderface");
                        return;
                    }
                    if (JS["formaction"] == null)
                    {
                        Utils.WriteLog("[Order_HF_Err]:【formaction NULL】" + Ret, "orderface");
                        DataObj.OutError("2096");
                        return;
                    }
                    Orders.PayId = JS["formaction"].ToString();
                    if (PayConfig.Id == 13)
                    {
                        string myData = "{\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\",\"code\":\"" + Orders.PayId + "\"}";
                        DataBase64 = LokFuEncode.Base64Encode(myData, "utf-8");
                        Sign       = (DataBase64 + merKey).GetMD5();
                        DataBase64 = HttpUtility.UrlEncode(DataBase64);
                        string myUrl = string.Format("req={0}&sign={1}", DataBase64, Sign);
                        string Url   = "https://api.zhifujiekou.com/wxjsapi/gopay.html?" + myUrl;

                        OrderF2F.PayId = Url;
                        Entity.SaveChanges();
                        Orders.PayId = "http://api.kkapay.com/home/jump?tnum=" + Orders.TNum;
                    }
                }
                #endregion
                Orders.Cols  = "Id,TNum,PayId";
                DataObj.Data = Orders.OutJson();
                DataObj.Code = "0000";
                DataObj.OutString();
            }
            #endregion
            if (OrderF2F.Action == "GET")//获取订交易信息
            {
                //开始处理参数
                if (OrderF2F.OId.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
                Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == OrderF2F.OId && n.UId == baseUsers.Id);
                if (Orders == null)
                {
                    DataObj.OutError("1000");
                    return;
                }
                OrderF2F Orderf2f = Entity.OrderF2F.FirstOrDefault(n => n.OId == OrderF2F.OId && n.UId == baseUsers.Id);
                if (Orders.TState == 1 && Orders.PayState == 0)
                {
                    PayConfig PayConfig = Entity.PayConfig.FirstOrNew(n => n.Id == Orders.PayWay);
                    if (PayConfig.DllName == "AliPay")
                    {
                        #region 支付宝处理
                        string[] PayConfigArr = PayConfig.QueryArray.Split(new char[] { ',' });    //接口信息 商户号,密钥,支付宝号
                        if (PayConfigArr.Length != 3)
                        {
                            DataObj.OutError("9999");
                            return;
                        }
                        if (AlipayVer == "1.0")
                        {
                            #region 1.0老接口
                            string pid = PayConfigArr[0];
                            string key = PayConfigArr[1];

                            int queryTimes = 10;    //查询次数计数器
                            int Run        = 0;
                            while (queryTimes > 0 && Run != 1)
                            {
                                AliPayApi Api        = new AliPayApi();
                                int       succResult = Api.AliPayQuery(Orderf2f.OId, pid, key);
                                //如果需要继续查询,则等待2s后继续
                                if (succResult == 2)
                                {
                                    //Thread.Sleep(5000);
                                    //continue;
                                    Run = 1;    //跳出循环,20160420
                                }
                                //查询成功,返回订单查询接口返回的数据
                                else if (succResult == 1)
                                {
                                    //Orders.PayState = 1;//此处不保存支付状态,由通知返回再操作
                                    Orders = Orders.PaySuccess(Entity);
                                    Run    = 1;
                                }
                                //订单交易失败
                                else
                                {
                                    Orders.TState       = 0;
                                    Orderf2f.OrderState = 0;
                                    Entity.SaveChanges();
                                }
                                queryTimes--;
                            }
                            #endregion
                        }
                        if (AlipayVer == "2.0")
                        {
                            #region 2.0新接口
                            ALF2FPAY ALF2FPAY = new ALF2FPAY();
                            ALF2FPAY.pid   = PayConfigArr[0];
                            ALF2FPAY.appId = PayConfigArr[2];

                            IAopClient client = new DefaultAopClient(ALF2FPAY.serverUrl, ALF2FPAY.appId, ALF2FPAY.merchant_private_key, "json", ALF2FPAY.version, ALF2FPAY.sign_type, ALF2FPAY.alipay_public_key, ALF2FPAY.charset);

                            string      QueryStr = "{\"out_trade_no\":\"" + Orders.TNum + "\"}";
                            ALF2FPAYObj ObjQuery = new ALF2FPAYObj();
                            ObjQuery.BizCode = QueryStr;
                            ObjQuery.Client  = client;
                            ObjQuery.Entity  = Entity;
                            AliPayApi Api = new AliPayApi();
                            AlipayTradeQueryResponse queryResponse = Api.LoopAlipayQuery(ObjQuery, 1);
                            if (queryResponse != null)
                            {
                                if (queryResponse.Code == "10000")
                                {
                                    if (queryResponse.TradeStatus == "TRADE_FINISHED" || queryResponse.TradeStatus == "TRADE_SUCCESS")
                                    {
                                        //Orders.PayState = 1;//此处不保存支付状态,由通知返回再操作
                                        Orders = Orders.PaySuccess(Entity);
                                    }
                                }
                            }
                            #endregion
                        }
                        #endregion
                    }
                    if (PayConfig.DllName == "WeiXin")
                    {
                        #region 微信处理
                        //初始化支付配置
                        WxPayConfig WxPayConfig  = new WxPayConfig();
                        string[]    PayConfigArr = PayConfig.QueryArray.Split(new char[] { ',' }); //接口信息 appid,mchid,key,appsecret
                        if (PayConfigArr.Length != 4 && PayConfigArr.Length != 5)
                        {
                            DataObj.OutError("9999");
                            return;
                        }
                        string ServerIp     = ConfigurationManager.AppSettings["ServerIp"].ToString();
                        string Wx_Cert_Path = ConfigurationManager.AppSettings["Wx_Cert_Path"].ToString();
                        string Wx_Cert_PWD  = ConfigurationManager.AppSettings["Wx_Cert_PWD"].ToString();
                        WxPayConfig.IP        = ServerIp;
                        WxPayConfig.APPID     = PayConfigArr[0];
                        WxPayConfig.MCHID     = PayConfigArr[1];
                        WxPayConfig.KEY       = PayConfigArr[2];
                        WxPayConfig.APPSECRET = PayConfigArr[3];
                        if (PayConfigArr.Length == 5)
                        {
                            WxPayConfig.SubMCHID = PayConfigArr[4];
                        }
                        WxPayConfig.SSLCERT_PATH     = Wx_Cert_Path;
                        WxPayConfig.SSLCERT_PASSWORD = Wx_Cert_PWD;
                        //支付配置结束
                        int queryTimes = 10;    //查询次数计数器
                        int Run        = 0;
                        while (queryTimes > 0 && Run != 1)
                        {
                            int       succResult  = 0;//查询结果
                            MicroPay  MicroPay    = new MicroPay();
                            WxPayData queryResult = MicroPay.WXQuery(Orderf2f.OId, WxPayConfig, Entity, out succResult);
                            //如果需要继续查询,则等待2s后继续
                            if (succResult == 2)
                            {
                                //Thread.Sleep(5000);
                                //continue;
                                Run = 1;    //跳出循环,20160420
                            }
                            //查询成功,返回订单查询接口返回的数据
                            else if (succResult == 1)
                            {
                                Orderf2f.Trade_no = queryResult.GetValue("transaction_id").ToString();
                                int ret = Entity.SaveChanges();
                                //Orders.PayState = 1;//此处不保存支付状态,由通知返回再操作
                                Orders = Orders.PaySuccess(Entity);
                                Run    = 1;
                            }
                            //订单交易失败
                            else
                            {
                                Orders.TState       = 0;
                                Orderf2f.OrderState = 0;
                                Entity.SaveChanges();
                            }
                            queryTimes--;
                        }
                        #endregion
                    }
                    if (PayConfig.DllName == "HFAliPay" || PayConfig.DllName == "HFWeiXin")
                    {
                        #region 好付处理
                        string[] QueryArr = PayConfig.QueryArray.Split(',');
                        if (QueryArr.Length == 3)
                        {
                            //提交结算中心
                            string merId      = QueryArr[0]; //商户号
                            string merKey     = QueryArr[1]; //商户密钥
                            string orderId    = Orders.TNum; //商户流水号
                            string PostJson   = "{\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\"}";
                            string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                            string Sign       = (DataBase64 + merKey).GetMD5();
                            DataBase64 = HttpUtility.UrlEncode(DataBase64);
                            string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                            string HF_Url   = "https://api.zhifujiekou.com/api/query";
                            string Ret      = Utils.PostRequest(HF_Url, PostData, "utf-8");

                            JObject JS = new JObject();
                            try
                            {
                                JS = (JObject)JsonConvert.DeserializeObject(Ret);
                            }
                            catch (Exception Ex)
                            {
                                Log.Write("[Order_HFQuery]:", "【PostData】" + PostData + "\n【Ret】" + Ret, Ex);
                                JS = null;
                            }
                            if (JS == null)
                            {
                                DataObj.OutError("1000");
                                return;
                            }
                            if (JS["resp"] == null)
                            {
                                Utils.WriteLog("【Ret】" + Ret, "OrderQC_HFQuery");
                                DataObj.OutError("1000");
                                return;
                            }
                            string resp = JS["resp"].ToString();
                            Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                            try
                            {
                                JS = (JObject)JsonConvert.DeserializeObject(Ret);
                            }
                            catch (Exception Ex)
                            {
                                Log.Write("[Order_HFQuery]:", "【Ret2】" + Ret, Ex);
                                JS = null;
                            }
                            if (JS == null)
                            {
                                DataObj.OutError("1000");
                                return;
                            }
                            string respcode = JS["respcode"].ToString();
                            if (respcode != "00")
                            {
                                string respmsg = JS["respmsg"].ToString();
                                DataObj.OutError("1000");
                                Utils.WriteLog("[Order_HFQuery_Err]:【" + respcode + "】" + respmsg, "orderface");
                                return;
                            }
                            string resultcode = JS["resultcode"].ToString();
                            if (resultcode == "0000" || resultcode == "1002" || resultcode == "1004")
                            {
                                string txnamt    = JS["txnamt"].ToString();
                                int    factmoney = int.Parse(txnamt);
                                if (((int)(Orders.Amoney * 100)) == factmoney)
                                {
                                    //Orders.PayState = 1;//此处不保存支付状态,由通知返回再操作
                                    Orders = Orders.PaySuccess(Entity);
                                }
                            }
                        }
                        #endregion
                    }
                }
                DataObj.Data = Orders.OutJson();
                DataObj.Code = "0000";
                DataObj.OutString();
            }
        }
        /// <summary>
        /// 同步重新出款用户结算状态
        /// </summary>
        public ActionResult ResubmitSyncUserState(string STNum)
        {
            var FastOrderChange = Entity.FastOrderChange.FirstOrDefault(o => o.STNum == STNum);

            if (FastOrderChange == null)
            {
                ViewBag.ErrorMsg = "重新出款单不存在";
                return(View("Error"));
            }
            if (FastOrderChange.State != 2)
            {
                ViewBag.ErrorMsg = "只有用户结算失败才能使用该功能";
                return(View("Error"));
            }
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(o => o.TNum == FastOrderChange.TNum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "订单不存在";
                return(View("Error"));
            }
            string OldUserState = FastOrder.GetUserClearingState();

            FastPayWay  FastPayWay  = Entity.FastPayWay.FirstOrDefault(n => n.Id == FastOrder.PayWay);
            FastUserPay FastUserPay = Entity.FastUserPay.FirstOrDefault(n => n.PayWay == FastOrder.PayWay && n.UId == FastOrder.UId && n.CardState == 1);

            if (FastPayWay != null)
            {
                string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
                if (FastPayWay.DllName == "HFPay")
                {
                    string TNum = FastOrderChange.STNum;
                    #region
                    string HFCash_Url = "https://api.zhifujiekou.com/api/qcashgateway";

                    //不需要
                    string PayPath   = ConfigurationManager.AppSettings["PayPath"].ToString();
                    string NoticeUrl = PayPath + "/PayCenter/HFCash/FastNotice.html";

                    //提交结算中心
                    string merId  = PayConfigArr[0];                               //商户号
                    string merKey = PayConfigArr[1];                               //商户密钥

                    string orderId = TNum;                                         //商户流水号

                    string OrderMoney = (FastOrder.PayMoney * 100).ToString("F0"); //金额,以分为单

                    FastUser FastUser   = Entity.FastUser.FirstOrNew(n => n.UId == FastOrder.UId);
                    string   UserCardId = FastUser.CardId;
                    string   PostJson   = "{\"action\":\"QCash\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\",\"bin\":\"" + FastOrder.Bin + "\",\"accno\":\"" + FastOrder.Card + "\",\"accname\":\"" + FastOrder.CardName + "\",\"cardno\":\"" + UserCardId + "\"}";

                    //传送数据Base64
                    string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                    //获得签名
                    string Sign = (DataBase64 + merKey).GetMD5();
                    //传送数据UrlEnCode
                    DataBase64 = HttpUtility.UrlEncode(DataBase64);
                    //组装Post数据
                    string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                    //Post数据,获得结果
                    string Ret = Utils.PostRequest(HFCash_Url, PostData, "utf-8");

                    JObject JS = new JObject();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception)
                    {
                        Utils.WriteLog("处理代付[" + FastOrder.TNum + "]!" + Ret, "CashPay");
                        JS = null;
                    }
                    if (JS != null)
                    {
                        string resp = JS["resp"].ToString();
                        Ret = LokFuEncode.Base64Decode(resp, "utf-8");

                        try
                        {
                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                        }
                        catch (Exception Ex)
                        {
                            FastOrder.UserState = 0;//提交的时候报错,可重新提交
                            JS = null;
                            Utils.WriteLog("[CashPay]:JSON[" + Ret + "]" + Ex.ToString(), "FastOrder");
                            ViewBag.ErrorMsg = "返回数据错误";
                            return(View("Error"));
                        }
                        if (JS != null)
                        {
                            string respcode = JS["respcode"].ToString();
                            if (respcode == "00")
                            {
                                string resultcode = JS["resultcode"].ToString();
                                if (resultcode == "0000")
                                {
                                    FastOrder.UserState   = 1;
                                    FastOrderChange.State = 1;
                                }
                                else if (resultcode == "2002" || resultcode == "2003")
                                {
                                    FastOrder.UserState   = 2;
                                    FastOrderChange.State = 2;
                                }
                                else
                                {
                                    FastOrder.UserState   = 3;
                                    FastOrderChange.State = 3;
                                }
                                //======================================
                                PayLog PayLog = new PayLog();
                                PayLog.PId     = FastPayWay.Id;
                                PayLog.OId     = TNum;
                                PayLog.TId     = "";
                                PayLog.Amount  = 0;
                                PayLog.Way     = "FASTDF";
                                PayLog.AddTime = DateTime.Now;
                                PayLog.Data    = Ret;
                                PayLog.State   = 1;
                                Entity.PayLog.AddObject(PayLog);
                                //======================================
                                FastOrderChange.Data = Ret;
                                Entity.FastOrderChange.AddObject(FastOrderChange);
                                Entity.SaveChanges();
                            }
                        }
                    }
                    #endregion
                }
            }
            if (FastOrder.UserState == 1)
            {
                ViewBag.Msg = "订单已成功重新出款";
                return(View("Succeed"));
            }
            else
            {
                string NewUserState = FastOrder.GetUserClearingState();
                ViewBag.ErrorMsg = "用户结算状态从" + OldUserState + "->" + NewUserState;
                return(View("Error"));
            }
        }
        public ActionResult Resubmit(FastOrder FastOrder)
        {
            //1. 接口配置校验与规则校验
            //2. 米刷当天校验与处理
            //3. 检查之前重出情况
            //4. 创建重出单
            //5. 重出

            //1. 接口配置校验与规则校验
            var p = this.Entity.FastOrder.FirstOrDefault(o => o.TNum == FastOrder.TNum);

            if (p.UserState != 2)
            {
                ViewBag.ErrorMsg = "只有用户结算失败才能使用该功能";
                return(View("Error"));
            }
            var FastUser    = Entity.FastUser.FirstOrDefault(o => o.UId == p.UId);
            var FastPayWay  = this.Entity.FastPayWay.FirstOrDefault(o => o.Id == p.PayWay);
            var FastUserPay = Entity.FastUserPay.FirstOrDefault(o => o.PayWay == p.PayWay && o.CardState == 1 && o.UId == p.UId);

            if (FastPayWay == null)
            {
                ViewBag.ErrorMsg = "未能找到相关通道";
                return(View("Error"));
            }
            if (FastUserPay == null)
            {
                ViewBag.ErrorMsg = "用户银行卡未绑定或未通过第三方验证";
                return(View("Error"));
            }
            if (!AllowFastPayWay.Contains(FastPayWay.DllName))
            {
                ViewBag.ErrorMsg = "不支持相关通道";
                return(View("Error"));
            }


            //2. 米刷当天校验与处理
            var Today    = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
            var OrderDay = new DateTime(p.PayTime.Value.Year, p.PayTime.Value.Month, p.PayTime.Value.Day, 0, 0, 0);

            if ((FastPayWay.DllName == "MiPay" || FastPayWay.DllName == "MiShua") && Today != OrderDay)
            {
                ViewBag.Msg       = "请确认接口方是否出款成功?";
                ViewBag.ActionUrl = this.Url.Action("Resubmit", new { TNum = p.TNum, IsAjax = 1 });
                return(View("Confirm"));
            }

            //3. 检查之前重出情况
            var LastFastOrderChange = Entity.FastOrderChange.OrderByDescending(o => o.Id).FirstOrDefault(o => o.TNum == FastOrder.TNum);//最后一次重出

            if (LastFastOrderChange != null)
            {
                if (LastFastOrderChange.State == 1)
                {
                    ViewBag.ErrorMsg = "重新出款已成功";
                    return(View("Error"));
                }
                else if (LastFastOrderChange.State != 2)
                {
                    ViewBag.ErrorMsg = "已重新出款,请同步用户结算状态";
                    return(View("Error"));
                }
            }

            //4. 创建重出单
            var count           = Entity.FastOrderChange.Count(o => o.TNum == p.TNum); //重出次数
            var FastOrderChange = new FastOrderChange()                                //新重出单
            {
                TNum      = p.TNum,
                STNum     = p.TNum + "_" + (count + 1).ToString(),
                AddTime   = DateTime.Now,
                AdminId   = AdminUser.Id,
                AdminName = AdminUser.TrueName,
                State     = 0,
            };

            //4.1更新成最新的绑卡信息
            p.Card     = FastUserPay.Card;
            p.Bin      = FastUserPay.Bin;
            p.Bank     = FastUserPay.Bank;
            p.CardName = FastUserPay.CardName;

            string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
            if (FastPayWay.DllName == "HFPay")
            {
                #region
                var    TNum       = FastOrderChange.STNum;
                string HFCash_Url = "https://api.zhifujiekou.com/api/qcashgateway";

                //不需要
                string PayPath   = ConfigurationManager.AppSettings["PayPath"].ToString();
                string NoticeUrl = PayPath + "/PayCenter/HFCash/FastNotice.html";

                //提交结算中心
                string merId  = PayConfigArr[0];                       //商户号
                string merKey = PayConfigArr[1];                       //商户密钥

                string orderId = TNum;                                 //商户流水号

                string OrderMoney = (p.PayMoney * 100).ToString("F0"); //金额,以分为单

                string UserCardId = FastUser.CardId;
                string PostJson   = "{\"action\":\"QCash\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\",\"bin\":\"" + p.Bin + "\",\"accno\":\"" + p.Card + "\",\"accname\":\"" + p.CardName + "\",\"cardno\":\"" + UserCardId + "\"}";

                //传送数据Base64
                string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                //获得签名
                string Sign = (DataBase64 + merKey).GetMD5();
                //传送数据UrlEnCode
                DataBase64 = HttpUtility.UrlEncode(DataBase64);
                //组装Post数据
                string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                //Post数据,获得结果
                string Ret = Utils.PostRequest(HFCash_Url, PostData, "utf-8");

                JObject JS = new JObject();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(Ret);
                }
                catch (Exception)
                {
                    Utils.WriteLog("处理代付[" + p.TNum + "]!" + Ret, "CashPay");
                    JS = null;
                }
                if (JS != null)
                {
                    string resp = JS["resp"].ToString();
                    Ret = LokFuEncode.Base64Decode(resp, "utf-8");

                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception)
                    {
                        Utils.WriteLog("处理代付[" + p.TNum + "]!解密出错", "CashPay");
                        JS = null;
                    }
                    if (JS != null)
                    {
                        string respcode = JS["respcode"].ToString();
                        if (respcode == "00")
                        {
                            string resultcode = JS["resultcode"].ToString();
                            if (resultcode == "0000")
                            {
                                p.UserState           = 1;
                                FastOrderChange.State = 1;
                            }
                            else if (resultcode == "2002" || resultcode == "2003")
                            {
                                p.UserState           = 2;
                                FastOrderChange.State = 2;
                            }
                            else
                            {
                                p.UserState           = 3;
                                FastOrderChange.State = 3;
                            }
                            //======================================
                            PayLog PayLog = new PayLog();
                            PayLog.PId     = FastPayWay.Id;
                            PayLog.OId     = TNum;
                            PayLog.TId     = "";
                            PayLog.Amount  = 0;
                            PayLog.Way     = "FASTDF";
                            PayLog.AddTime = DateTime.Now;
                            PayLog.Data    = Ret;
                            PayLog.State   = 1;
                            Entity.PayLog.AddObject(PayLog);
                            //======================================
                            FastOrderChange.Data = Ret;
                            Entity.FastOrderChange.AddObject(FastOrderChange);
                            Entity.SaveChanges();
                        }
                        else
                        {
                            string message = JS["respmsg"].ToString();
                            //p.UserState = 0;//提交的时候报错,可重新提交
                            //p.Remark = message;
                            ViewBag.ErrorMsg = message;
                            return(View("Error"));
                        }
                    }
                    else
                    {
                        ViewBag.ErrorMsg = "接口服务器无响应";
                        return(View("Error"));
                    }
                }
                #endregion
            }
            if (p.UserState == 1)
            {
                ViewBag.Msg = "订单已成功重新出款";
                return(View("Succeed"));
            }
            else
            {
                ViewBag.ErrorMsg = "订单重新出款暂未成功,请稍后同步用户结算状态";
                return(View("Error"));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="shopid"></param>
        /// <param name="Amount"></param>
        /// <param name="payway">这里payway是SysConfig的ID</param>
        /// <returns></returns>
        public ActionResult GoPay(int shopid = 0, decimal Amount = 0, byte payway = 0)
        {
            if (shopid.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "商户信息有误,请核实!";
                return(View("Error"));
            }
            if (Amount.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "付款金额有误,请核实!";
                return(View("Error"));
            }
            Users baseUsers = Entity.Users.FirstOrNew(n => n.Id == shopid && n.State == 1 && n.CardStae == 2);

            if (baseUsers.Id.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "商户信息有误,请核实!";
                return(View("Error"));
            }
            if (Amount <= 0)
            {
                ViewBag.ErrorMsg = "付款金额有误![00]";
                return(View("Error"));
            }
            Amount = Amount.FormatMoney();

            #region 处理选择通道
            string Tag     = string.Empty;
            byte   PayType = 0;//订单类型
            if (IsWeiXinBrowser)
            {
                Tag = "WeiXin";
            }
            else if (IsAlipayBrowser)
            {
                Tag = "Alipay";
            }
            #region 获取系统支付配置
            SysControl SysControl = Entity.SysControl.FirstOrDefault(n => n.Id == payway);
            if (SysControl == null)
            {
                ViewBag.ErrorMsg = "接口维护中";
                return(View("Error"));
            }
            SysControl syscontrol = SysControl.ChkState();
            if (syscontrol.State != 1)
            {
                ViewBag.ErrorMsg = "接口维护中";
                return(View("Error"));
            }

            if (Amount < SysControl.SNum || Amount > SysControl.ENum)
            {
                ViewBag.ErrorMsg = "本付款方式限定金额为" + SysControl.SNum.ToString("f2") + "-" + SysControl.ENum.ToString("f2");
                return(View("Error"));
            }

            if (SysControl.Tag != Tag)//接口对应的"操作应用程序"
            {
                string tagname = "";
                if (SysControl.Tag == "WeiXin")
                {
                    tagname = "微信";
                }
                else if (SysControl.Tag == "Alipay")
                {
                    tagname = "支付宝";
                }
                else
                {
                    tagname = "银联";
                }
                ViewBag.ErrorMsg = "请使用" + tagname + "操作";
                return(View("Error"));
            }
            PayConfig PayConfig = Entity.PayConfig.FirstOrDefault(o => o.Id == SysControl.PayWay && o.State == 1);
            if (PayConfig == null)
            {
                ViewBag.ErrorMsg = "支付接口维护中,请使用其它支付通道!";
                return(View("Error"));
            }
            switch (PayConfig.GroupType)//从这里获取订单类型
            {
            case "AliPay":
                PayType = 7;
                break;

            case "WeiXin":
                PayType = 8;
                break;
            }
            if (PayType == 0)
            {
                ViewBag.ErrorMsg = "没有对应的支付配置";
                return(View("Error"));
            }
            #endregion
            #endregion

            #region 订单生成
            //获取用户支付配置
            UserPay UserPay = Entity.UserPay.FirstOrDefault(n => n.UId == baseUsers.Id && n.PId == SysControl.PayWay);
            if (UserPay == null)
            {
                ViewBag.ErrorMsg = "用户支付配置错误";
                return(View("Error"));
            }
            //获取分支机构信息
            SysAgent SysAgent = new SysAgent();
            if (!baseUsers.Agent.IsNullOrEmpty())
            {
                SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == baseUsers.Agent);
            }
            //获取系统配置
            SysSet SysSet = Entity.SysSet.FirstOrDefault();

            //TN判断
            int InType = SysControl.LagEntryNum > 0 ? 1 : 0;
            if (InType == 1)
            {
                //客户端传来T+N但是系统没开启时无效
                if (SysSet.LagEntry == 0)
                {
                    InType = 0;
                }
            }
            var OrderF2F = new OrderF2F()
            {
                PayWay  = SysControl.PayWay,
                AddTime = DateTime.Now,
                OType   = PayType,
                Amoney  = Amount,
            };
            if (InType == 1)
            {
                //手续费
                OrderF2F.Poundage = 0;
                //商户费率
                OrderF2F.UserRate = 0;
                //T+n时,代理佣金为 交易金额*费率
                decimal AgentPayGet = OrderF2F.Amoney * SysSet.AgentGet;
                OrderF2F.AgentPayGet = (Double)AgentPayGet;
                //佣金舍位
                OrderF2F.AgentPayGet = OrderF2F.AgentPayGet.Floor();
            }
            else
            {
                //手续费
                OrderF2F.Poundage = OrderF2F.Amoney * (decimal)UserPay.Cost;
                //手续费取进
                OrderF2F.Poundage = OrderF2F.Poundage.Ceiling();
                //商户费率
                OrderF2F.UserRate = UserPay.Cost;
                //分支机构佣金设置为0,待分润计算后再写入
                OrderF2F.AgentPayGet = 0;
            }
            OrderF2F.UId = baseUsers.Id;
            //到帐金额=支付金额-手续费
            OrderF2F.PayMoney = OrderF2F.Amoney - OrderF2F.Poundage;
            //第三方支付通道率
            OrderF2F.SysRate = (double)PayConfig.Cost;
            //这里是利润计算==========
            //利润=总金额-到帐-支付手续费
            decimal GetAll = OrderF2F.Amoney - OrderF2F.PayMoney - OrderF2F.Amoney * (decimal)OrderF2F.SysRate;
            //利润舍位
            GetAll = GetAll.Floor();
            //总利润
            OrderF2F.AIdPayGet = (double)GetAll;

            OrderF2F.Agent      = SysAgent.Id;//分支机构Id
            OrderF2F.AId        = baseUsers.AId;
            OrderF2F.FId        = 0;
            OrderF2F.OrderState = 1;
            OrderF2F.PayState   = 0;
            OrderF2F.AgentState = 0;
            OrderF2F.AddTime    = DateTime.Now;
            OrderF2F.PayId      = string.Empty;
            OrderF2F.PayType    = PayType;

            //写入订单总表
            Orders Orders = new Orders();
            Orders.UId   = OrderF2F.UId;
            Orders.TName = baseUsers.NeekName;

            Orders.PayType = PayType;
            Orders.PayName = "收银台-" + PayConfig.Name;;

            Orders.RUId     = 0;
            Orders.RName    = string.Empty;
            Orders.TType    = OrderF2F.OType;
            Orders.TState   = 1;
            Orders.Amoney   = OrderF2F.Amoney;
            Orders.Poundage = OrderF2F.Poundage;
            Orders.AddTime  = DateTime.Now;
            Orders.PayState = 0;
            Orders.PayWay   = SysControl.PayWay;

            Orders.Agent      = OrderF2F.Agent;
            Orders.AgentState = 0;
            Orders.AId        = OrderF2F.AId;
            Orders.FId        = 0;
            Orders.ComeWay    = 2;//收银台订单的标识 1:APP订单 2:收银台订单

            if (InType == 1)
            {
                Orders.LagEntryDay = SysControl.LagEntryDay;
                Orders.LagEntryNum = SysControl.LagEntryNum;
            }
            else
            {
                Orders.LagEntryDay = 0;
                Orders.LagEntryNum = 0;
            }

            Entity.Orders.AddObject(Orders);
            Entity.SaveChanges();
            Entity.Refresh(RefreshMode.StoreWins, Orders);

            OrderF2F.OId = Orders.TNum;
            Entity.OrderF2F.AddObject(OrderF2F);
            Entity.SaveChanges();

            //=======================================
            UserTrack UserTrack = new UserTrack();
            UserTrack.ENo        = baseUsers.ENo;
            UserTrack.OPType     = Orders.PayName;
            UserTrack.UserName   = Orders.TNum;
            UserTrack.GPSAddress = "";
            UserTrack.GPSX       = "";
            UserTrack.GPSY       = "";
            UserTrack.IP         = Utils.GetIP();
            Orders.SeavGPSLog(UserTrack, Entity);
            //=======================================

            #endregion

            #region 提交结算中心
            if (PayConfig.DllName == "HFAliPay" || PayConfig.DllName == "HFWeiXin")
            {
                string NoticeUrl = "";
                string Action    = "";
                if (PayConfig.DllName == "HFAliPay")
                {
                    NoticeUrl = NoticePath + "/PayCenter/HFAliPay/Notice.html";
                    Action    = "AliSao";
                }
                if (PayConfig.DllName == "HFWeiXin")
                {
                    NoticeUrl = NoticePath + "/PayCenter/HFWeiXin/Notice.html";
                    Action    = "WxJsApi";
                }
                string[] PayConfigArr = PayConfig.QueryArray.Split(',');
                if (PayConfigArr.Length != 3)
                {
                    ViewBag.ErrorMsg = "参数错误!";
                    return(View("Error"));
                }
                //提交结算中心
                string merId    = PayConfigArr[0]; //商户号
                string merKey   = PayConfigArr[1]; //商户密钥
                string JsPayWay = PayConfigArr[2]; //绑定通道

                string  orderId    = Orders.TNum;  //商户流水号
                decimal money      = Orders.Amoney * 100;
                long    intmoney   = Int64.Parse(money.ToString("F0"));
                string  OrderMoney = intmoney.ToString();//金额,以分为单

                string PostJson = "{\"action\":\"" + Action + "\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"payway\":\"" + JsPayWay + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\"}";

                string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                string Sign       = (DataBase64 + merKey).GetMD5();

                DataBase64 = HttpUtility.UrlEncode(DataBase64);
                string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);

                //本通道支持直联公众号
                if (IsWeiXinBrowser && Action == "WxJsApi")
                {
                    Orders.PayId = "公众号支付";
                    Entity.SaveChanges();
                    string gateway_url = "https://api.zhifujiekou.com/apis/wxjspaygateway";
                    string GoUrl       = gateway_url + "?" + PostData;
                    Response.Redirect(GoUrl);
                    return(View("Null"));
                }

                string  HF_Url = "https://api.zhifujiekou.com/api/mpgateway";
                string  Ret    = Utils.PostRequest(HF_Url, PostData, "utf-8");
                JObject JS     = new JObject();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(Ret);
                }
                catch (Exception)
                {
                    Utils.WriteLog("[Order_HF_Err]:【PostData】" + PostData + "\n【Ret】" + Ret, "ShopErr");
                    ViewBag.ErrorMsg = "返回数据异常!";
                    return(View("Error"));
                }
                string resp = JS["resp"].ToString();
                Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(Ret);
                }
                catch (Exception)
                {
                    Utils.WriteLog("[Order_HF_Err]:【Ret】" + Ret, "ShopErr");
                    ViewBag.ErrorMsg = "返回结果异常!";
                    return(View("Error"));
                }
                string respcode = JS["respcode"].ToString();
                if (respcode != "00")
                {
                    string respmsg = JS["respmsg"].ToString();
                    Utils.WriteLog("[Order_HF_Err]:【" + respcode + "】" + respmsg, "ShopErr");
                    ViewBag.ErrorMsg = respmsg;
                    return(View("Error"));
                }
                if (JS["formaction"] == null)
                {
                    Utils.WriteLog("[Order_HF_Err]:【formaction NULL】" + Ret, "ShopErr");
                    ViewBag.ErrorMsg = "未能生成二维码";
                    return(View("Error"));
                }
                Orders.PayId = JS["formaction"].ToString();
            }
            #endregion

            this.ViewBag.Orders = Orders;
            return(View());
        }
        /// <summary>
        /// 查询订单状态
        /// </summary>
        /// <param name="code">订单号</param>
        /// <returns></returns>
        public string PayState(string code)
        {
            string TNum   = LokFuEncode.Base64Decode(code);
            Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == TNum);

            if (Orders == null)
            {
                return("E1");
            }
            if (Orders.PayState == 1)
            {
                return("S");
            }
            if (Orders.TState != 1)
            {
                return("E0");
            }
            PayConfig PayConfig = Entity.PayConfig.FirstOrNew(n => n.Id == Orders.PayWay);

            if (PayConfig == null)
            {
                return("E2");
            }
            if (Orders.TState == 1 && Orders.PayState == 0)
            {
                if (PayConfig.DllName == "HFAliPay" || PayConfig.DllName == "HFWeiXin")
                {
                    #region 查询结算中心
                    string[] QueryArr = PayConfig.QueryArray.Split(',');
                    if (QueryArr.Length == 3)
                    {
                        //提交结算中心
                        string merId      = QueryArr[0]; //商户号
                        string merKey     = QueryArr[1]; //商户密钥
                        string orderId    = Orders.TNum; //商户流水号
                        string PostJson   = "{\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\"}";
                        string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                        string Sign       = (DataBase64 + merKey).GetMD5();
                        DataBase64 = HttpUtility.UrlEncode(DataBase64);
                        string  PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                        string  HF_Url   = "https://api.zhifujiekou.com/api/query";
                        string  Ret      = Utils.PostRequest(HF_Url, PostData, "utf-8");
                        JObject JS       = new JObject();
                        try
                        {
                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                        }
                        catch (Exception)
                        {
                            Utils.WriteLog("[Query_HF_Err]:【PostData】" + PostData + "\n【Ret】" + Ret, "ShopErr");
                            return("ER");
                        }
                        string resp = JS["resp"].ToString();
                        Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                        try
                        {
                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                        }
                        catch (Exception)
                        {
                            Utils.WriteLog("[Query_HF_Err]:", "【Ret】" + Ret, "ShopErr");
                            return("ER");
                        }

                        string respcode = JS["respcode"].ToString();
                        if (respcode != "00")
                        {
                            string respmsg = JS["respmsg"].ToString();
                            Utils.WriteLog("[Query_HF_Err]:【" + respcode + "】" + respmsg, "PayState");
                            return("ER");
                        }
                        string resultcode = JS["resultcode"].ToString();
                        if (resultcode == "0000" || resultcode == "1002" || resultcode == "1004")
                        {
                            string txnamt    = JS["txnamt"].ToString();
                            int    factmoney = int.Parse(txnamt);
                            if (((int)(Orders.Amoney * 100)) == factmoney)
                            {
                                Orders = Orders.PaySuccess(Entity);
                            }
                        }
                    }
                    #endregion
                }
            }
            if (Orders.PayState == 1)
            {
                return("S");
            }
            if (Orders.TState == 0)
            {
                return("E100");
            }
            return("G");
        }
Exemplo n.º 13
0
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[IPay]:", "【Data】" + Data, Ex);
                json = null;
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            Orders Orders = new Orders();

            Orders = JsonToObject.ConvertJsonToModel(Orders, json);
            if (Orders.TNum.IsNullOrEmpty() || Orders.Token.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            #region 处理用户信息
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == Orders.Token);
            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            #endregion
            Orders BaseOrders = Entity.Orders.FirstOrDefault(n => n.TNum == Orders.TNum);
            if (BaseOrders == null)
            {
                DataObj.OutError("1001");
                return;
            }
            if (baseUsers.Id != BaseOrders.UId)//禁止代付
            {
                DataObj.OutError("6021");
                return;
            }
            if (BaseOrders.TType != 6 && BaseOrders.TType != 10)
            {
                DataObj.OutError("6022");
                return;
            }
            if (BaseOrders.TState != 1)
            {
                DataObj.OutError("6024");
                return;
            }
            if (BaseOrders.PayState != 0)
            {
                //已支付
                DataObj.OutError("6025");
                return;
            }
            #region 处理选择通道
            PayConfig PayConfig = null;
            if (!BaseOrders.PayWay.IsNullOrEmpty())
            {
                PayConfig = Entity.PayConfig.FirstOrDefault(n => n.State == 1 && n.Id == BaseOrders.PayWay);
                if (Orders.PayName != PayConfig.GroupType)
                {
                    DataObj.OutError("1008");
                    return;
                }
            }
            else
            {
                if (Orders.PayName.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
                //获取最佳支付通道
                IList <PayConfig>  PayConfigList  = Entity.PayConfig.Where(n => n.State == 1 && n.GroupType == Orders.PayName).ToList();
                IList <SysControl> SysControlList = Entity.SysControl.OrderBy(n => n.Sort).ToList();//SysControl
                IList <SysControl> SCList         = new List <SysControl>();
                IList <PayConfig>  PCList         = new List <PayConfig>();
                foreach (var p in SysControlList)
                {
                    SysControl T = p.ChkState();
                    if (T.State == 1)
                    {
                        SCList.Add(p);
                    }
                }
                foreach (var p in PayConfigList)
                {
                    SysControl T = SCList.FirstOrDefault(n => n.PayWay == p.Id);
                    if (T != null)
                    {
                        if (BaseOrders.Amoney >= (decimal)T.SNum && BaseOrders.Amoney <= (decimal)T.ENum)
                        {
                            PCList.Add(p);
                        }
                    }
                }
                PayConfig = PCList.OrderBy(n => n.Cost).FirstOrDefault();
                if (PayConfig == null)
                {
                    DataObj.OutError("1000");
                    return;;
                }
                if (BaseOrders.TType == 6)
                {
                    //PayConfigOrder PayConfigOrder = Entity.PayConfigOrder.FirstOrDefault(n => n.OId == BaseOrders.TNum);
                    //PayConfigOrder.SysRate = 0;
                    //PayConfigOrder.Poundage = PayConfigOrder.Amoney * (decimal)PayConfigOrder.SysRate;
                    //BaseOrders.Poundage = PayConfigOrder.Poundage;
                    BaseOrders.PayWay = PayConfig.Id;
                }
                else if (BaseOrders.TType == 10)
                {
                    BaseOrders.PayWay = PayConfig.Id;
                }
                Entity.SaveChanges();
            }
            if (PayConfig == null)
            {
                DataObj.OutError("1000");
                return;
            }
            if (PayConfig.GroupType != "AliPay" && PayConfig.GroupType != "WeiXin")
            {
                DataObj.OutError("1007");
                return;
            }
            #endregion
            string DataRet = "", Trade = "";
            #region 提交好付
            if (PayConfig.DllName == "HFAliPay" || PayConfig.DllName == "HFWeiXin")
            {
                string NoticeUrl = NoticePath + "/PayCenter/HFPay/Notice.html";;
                string Action    = "";
                if (PayConfig.DllName == "HFAliPay")
                {
                    Action = "AliSao";
                }
                if (PayConfig.DllName == "HFWeiXin")
                {
                    Action = "WxSao";
                }
                string[] PayConfigArr = PayConfig.QueryArray.Split(',');
                if (PayConfigArr.Length != 3)
                {
                    DataObj.OutError("1000");
                    return;
                }
                //提交结算中心
                string merId    = PayConfigArr[0];    //商户号
                string merKey   = PayConfigArr[1];    //商户密钥
                string JsPayWay = PayConfigArr[2];    //绑定通道

                string  orderId    = BaseOrders.TNum; //商户流水号
                decimal money      = BaseOrders.Amoney * 100;
                long    intmoney   = Int64.Parse(money.ToString("F0"));
                string  OrderMoney = intmoney.ToString();//金额,以分为单

                string PostJson = "{\"action\":\"" + Action + "\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"payway\":\"" + JsPayWay + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\"}";

                string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                string Sign       = (DataBase64 + merKey).GetMD5();

                DataBase64 = HttpUtility.UrlEncode(DataBase64);
                string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);

                string HF_Url = "https://api.zhifujiekou.com/api/mpgateway";

                DataRet = Utils.PostRequest(HF_Url, PostData, "utf-8");

                JObject JS = new JObject();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(DataRet);
                }
                catch (Exception Ex)
                {
                    Log.Write("[Order_HF]:", "【PostData】" + PostData + "\n【DataRet】" + DataRet, Ex);
                    json = null;
                }
                if (JS == null)
                {
                    DataObj.OutError("1000");
                    return;
                }
                string resp = JS["resp"].ToString();
                DataRet = LokFuEncode.Base64Decode(resp, "utf-8");
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(DataRet);
                }
                catch (Exception Ex)
                {
                    Log.Write("[Order_HF]:", "【DataRet2】" + DataRet, Ex);
                    JS = null;
                }
                if (JS == null)
                {
                    DataObj.OutError("1000");
                    return;
                }
                string respcode = JS["respcode"].ToString();
                if (respcode != "00")
                {
                    string respmsg = JS["respmsg"].ToString();
                    DataObj.OutError("1000");
                    Utils.WriteLog("[Order_HF_Err]:【" + respcode + "】" + respmsg, "orderface");
                    return;
                }
                if (JS["formaction"] == null)
                {
                    Utils.WriteLog("[Order_HF_Err]:【formaction NULL】" + DataRet, "orderface");
                    DataObj.OutError("2096");
                    return;
                }
                BaseOrders.PayId = JS["formaction"].ToString();
                Trade            = JS["queryid"].ToString();
            }
            #endregion
            //================================================
            //这里记录日志
            PayLog PayLog = new PayLog();
            PayLog.PId     = PayConfig.Id;
            PayLog.OId     = BaseOrders.TNum;
            PayLog.TId     = Trade;
            PayLog.Amount  = BaseOrders.Amoney;
            PayLog.Way     = "GET";
            PayLog.AddTime = DateTime.Now;
            PayLog.Data    = Data;
            PayLog.State   = 1;
            Entity.PayLog.AddObject(PayLog);
            Entity.SaveChanges();
            //================================================
            BaseOrders.Cols = "TNum,PayId,Amount,PayState";
            DataObj.Data    = BaseOrders.OutJson();
            DataObj.Code    = "0000";
            DataObj.OutString();
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[GetPayPassByBank]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }


            Users    Users = new Users();
            UserAuth UA    = new UserAuth();

            Users = JsonToObject.ConvertJsonToModel(Users, json);
            UA    = JsonToObject.ConvertJsonToModel(UA, json);

            if (Users.UserName.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            if (Users.X.IsNullOrEmpty() || Users.Y.IsNullOrEmpty())
            {
                //DataObj.OutError("1000");
                //return;
            }
            ////手机号码黑名单验证
            //if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == Users.UserName && UBL.State == 1) != null)
            //{
            //    //提示暂不支持您手机号入网
            //    DataObj.OutError("2026");
            //    return;
            //}
            //if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == Users.CardId && UBL.State == 2) != null)
            //{
            //    //提示暂不支持您手机号入网
            //    DataObj.OutError("2027");
            //    return;
            //}
            Users BaseUsers = Entity.Users.FirstOrDefault(n => n.UserName == Users.UserName);

            if (BaseUsers == null)//用户不存在
            {
                DataObj.OutError("2001");
                return;
            }
            if (BaseUsers.State != 1)
            {
                DataObj.OutError("2003");
                return;
            }
            if (BaseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (BaseUsers.MiBao != 1)
            {
                DataObj.OutError("2008");
                return;
            }

            SysSet SysSet = Entity.SysSet.FirstOrNew();

            if (SysSet.AuthType != 3 && SysSet.AuthType != 2)
            {
                DataObj.OutError("2061");//----------------
                return;
            }
            if (BaseUsers.Amount < SysSet.AuthPrice)
            {
                DataObj.OutError("6026");
                return;
            }

            UserAuth UserAuth = new UserAuth();

            UserAuth.UId          = BaseUsers.Id;
            UserAuth.AccountName  = Users.TrueName;
            UserAuth.IdentityCode = Users.CardId;
            UserAuth.BankAccount  = Users.CardNum;
            UserAuth.Mobile       = Users.Mobile;
            UserAuth.CVV          = UA.CVV;
            UserAuth.EndDate      = UA.EndDate;
            UserAuth.AddTime      = DateTime.Now;

            UserTrack UserTrack = new UserTrack();

            UserTrack = JsonToObject.ConvertJsonToModel(UserTrack, json);

            //处理走的通道及支持验证类型
            string HaoFu_Auth_Open = ConfigurationManager.AppSettings["HaoFu_Auth_Open"].ToString();
            byte   CardItemNum     = 0;

            if (Equipment.RqType == "Apple")
            {
                CardItemNum = SysSet.IosSet10;
            }
            else
            {
                CardItemNum = SysSet.ApkSet10;
            }
            if (HaoFu_Auth_Open != "true")
            {
                CardItemNum = 6;//兼容直连六要素接口
            }
            if (CardItemNum == 6)
            {
                if (UserAuth.BankAccount.IsNullOrEmpty() || UserAuth.AccountName.IsNullOrEmpty() || UserAuth.IdentityCode.IsNullOrEmpty() || UserAuth.Mobile.IsNullOrEmpty() || UserAuth.CVV.IsNullOrEmpty() || UserAuth.EndDate.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
            }
            else if (CardItemNum == 4)
            {
                if (UserAuth.BankAccount.IsNullOrEmpty() || UserAuth.AccountName.IsNullOrEmpty() || UserAuth.IdentityCode.IsNullOrEmpty() || UserAuth.Mobile.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
            }
            else if (CardItemNum == 3)
            {
                if (UserAuth.BankAccount.IsNullOrEmpty() || UserAuth.AccountName.IsNullOrEmpty() || UserAuth.IdentityCode.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
            }
            else
            {
                DataObj.OutError("1000");
                return;
            }

            //实名信息验证,支付密码密段是实名认证的
            if (Users.TrueName != BaseUsers.TrueName)
            {
                DataObj.OutError("2011");//2011	真实姓名不正确
                return;
            }
            if (Users.CardId != BaseUsers.CardId)
            {
                DataObj.OutError("2012");//2012	身份证不正确
                return;
            }

            if (!UserAuth.EndDate.IsNullOrEmpty())
            {
                //处理年月问题传上来是MMYY
                //20151112调整成YYMM
                if (UserAuth.EndDate.Length == 4)
                {
                    string MM = UserAuth.EndDate.Substring(0, 2);
                    string YY = UserAuth.EndDate.Substring(2, 2);
                    UserAuth.EndDate = YY + MM;
                }
            }
            UserAuth.AuthType  = 1;
            UserAuth.AuthPrice = SysSet.AuthPrice;
            UserAuth.IsCharge  = 0;
            Entity.UserAuth.AddObject(UserAuth);
            Entity.SaveChanges();
            Entity.Refresh(RefreshMode.StoreWins, UserAuth);

            int     USERSID  = UserAuth.UId.GetValueOrDefault();
            string  TNUM     = UserAuth.OId;
            decimal PAYMONEY = UserAuth.AuthPrice;
            string  SP_Ret   = Entity.SP_UsersMoney(USERSID, TNUM, PAYMONEY, 2, "鉴权取回支付密码");

            if (SP_Ret != "3")
            {
                DataObj.OutError("8888");
                return;
            }

            string ret_code = "";
            string ret_msg  = "";
            string isCharge = "";

            string CONTENT = "";

            if (HaoFu_Auth_Open == "true")
            {
                //提交到结算中心去认证
                string HaoFu_Auth_MerId  = ConfigurationManager.AppSettings["HaoFu_Auth_MerId"].ToString();
                string HaoFu_Auth_MerKey = ConfigurationManager.AppSettings["HaoFu_Auth_MerKey"].ToString();
                string HaoFu_Auth_Url    = ConfigurationManager.AppSettings["HaoFu_Auth_Url"].ToString();

                string data       = "{\"action\":\"authuser\",\"merid\":\"" + HaoFu_Auth_MerId + "\",\"orderid\":\"" + UserAuth.OId + "\",\"bankaccount\":\"" + UserAuth.BankAccount + "\",\"accountname\":\"" + UserAuth.AccountName + "\",\"identitycode\":\"" + UserAuth.IdentityCode + "\",\"mobile\":\"" + UserAuth.Mobile + "\",\"cvv\":\"" + UserAuth.CVV + "\",\"enddate\":\"" + UserAuth.EndDate + "\"}";
                string DataBase64 = LokFuEncode.Base64Encode(data, "utf-8");
                string Sign       = (DataBase64 + HaoFu_Auth_MerKey).GetMD5();

                DataBase64 = HttpUtility.UrlEncode(DataBase64, Encoding.UTF8);
                string postdata = "req=" + DataBase64 + "&sign=" + Sign;

                CONTENT = Utils.PostRequest(HaoFu_Auth_Url, postdata, "utf-8");

                JObject JS = new JObject();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
                }
                catch (Exception Ex)
                {
                    Log.Write("[UsersTrueNameByAPI]:", "【CONTENT】" + CONTENT, Ex);
                }
                if (JS == null)
                {
                    DataObj.OutError("2021");
                    return;
                }
                string resp = JS["resp"].ToString();
                CONTENT = LokFuEncode.Base64Decode(resp, "utf-8");
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
                }
                catch (Exception Ex)
                {
                    Log.Write("[UsersTrueNameByAPI]:", "【CONTENT2】" + CONTENT, Ex);
                }
                if (JS == null)
                {
                    DataObj.OutError("2021");
                    return;
                }
                ret_code = JS["respcode"].ToString();
                ret_msg  = JS["respmsg"].ToString();
                if (ret_code == "0000")
                {
                    isCharge = JS["ischarge"].ToString();
                }
                if (isCharge == "1")
                {
                    UserAuth.IsCharge = 1;
                }
                else
                {
                    UserAuth.IsCharge = 0;
                }
            }
            UserAuth.RetCode = ret_code;
            UserAuth.RetMsg  = ret_msg;
            UserAuth.RetLog  = CONTENT;

            if (ret_code != "0000")
            {
                DataObj.OutError("2021");
                return;
            }
            //=======================================
            UserTrack.ENo        = DataObj.ENo;
            UserTrack.OPType     = "鉴权取回支付密码";
            UserTrack.GPSAddress = Users.RegAddress;
            UserTrack.GPSX       = Users.X;
            UserTrack.GPSY       = Users.Y;
            BaseUsers.SeavGPSLog(UserTrack, Entity);
            //=======================================
            Entity.SaveChanges();

            DateTime now   = DateTime.Now;
            Guid     Gid   = Guid.NewGuid();
            string   mdstr = Users.Id + "|" + Users.UserName + "|" + Gid.ToString() + "|" + now.ToString();
            string   taken = mdstr.GetMD5();

            BaseUsers.Token = "pppp" + taken;

            Entity.SaveChanges();
            BaseUsers.Cols = "Token";
            DataObj.Data   = BaseUsers.OutJson();
            DataObj.Code   = "0000";
            DataObj.OutString();
        }
Exemplo n.º 15
0
        public void Execute(IJobExecutionContext context)
        {
            string JobName = "FastCash";
            string CanRun  = ConfigurationManager.AppSettings["Run" + JobName].ToString();

            if (CanRun == "true")
            {
                if (!IsRun)
                {
                    LokFuEntity Entity = new LokFuEntity();
                    IsRun = true;
                    try
                    {
                        Log.Write(JobName + "任务开始执行!");
                        //-------------------------------------------------------
                        #region 任务主体
                        //查询所有已支付但未代付订单
                        DateTime          CanPayTime = DateTime.Now.AddSeconds(-300);//20秒前支付订单可付
                        IList <FastOrder> List       = Entity.FastOrder.Where(n => n.State == 1 && n.PayState == 1 && n.UserState == 0 && n.PayTime < CanPayTime).ToList();
                        //UserState 0未付 1已付 2失败 3结果未明 4付起中
                        //foreach (var p in List.Where(n=>n.PayWay==16 && n.))
                        //List = List.Where(n => n.PayWay != 16 || (n.PayWay == 16 && n.PayTime < CanPayTime2)).ToList();
                        foreach (var p in List)
                        {
                            p.UserTime  = DateTime.Now;
                            p.UserState = 4;
                        }
                        Entity.SaveChanges();
                        foreach (var p in List)
                        {
                            Users Users = Entity.Users.FirstOrDefault(n => n.Id == p.UId);
                            if (Users.StopPayState == 0)
                            {
                                FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == p.PayWay && n.State == 1);
                                if (FastPayWay != null)
                                {
                                    string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
                                    if (FastPayWay.DllName == "HFPay")
                                    {
                                        #region 结算中心代付

                                        string HFCash_Url = "https://api.zhifujiekou.com/api/qcashgateway";

                                        //不需要
                                        string NoticePath = ConfigurationManager.AppSettings["NoticePath"].ToString();
                                        string NoticeUrl  = NoticePath + "/PayCenter/HFCash/FastNotice.html";

                                        //提交结算中心
                                        string merId  = PayConfigArr[0];                       //商户号
                                        string merKey = PayConfigArr[1];                       //商户密钥

                                        string orderId = p.TNum;                               //商户流水号

                                        string OrderMoney = (p.PayMoney * 100).ToString("F0"); //金额,以分为单

                                        string UserCardId = Users.CardId;
                                        string PostJson   = "{\"action\":\"QCash\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\",\"bin\":\"" + p.Bin + "\",\"accno\":\"" + p.Card + "\",\"accname\":\"" + p.CardName + "\",\"cardno\":\"" + UserCardId + "\"}";

                                        //传送数据Base64
                                        string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                                        //获得签名
                                        string Sign = (DataBase64 + merKey).GetMD5();
                                        //传送数据UrlEnCode
                                        DataBase64 = HttpUtility.UrlEncode(DataBase64);
                                        //组装Post数据
                                        string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                                        //Post数据,获得结果
                                        string  Ret = Utils.PostRequest(HFCash_Url, PostData, "utf-8");
                                        JObject JS  = new JObject();
                                        try
                                        {
                                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                        }
                                        catch (Exception)
                                        {
                                            Utils.WriteLog("处理代付[" + p.TNum + "]!" + Ret, "CashPay");
                                            JS = null;
                                        }
                                        if (JS != null)
                                        {
                                            string resp = JS["resp"].ToString();
                                            Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                                            try
                                            {
                                                JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                            }
                                            catch (Exception)
                                            {
                                                Utils.WriteLog("处理代付[" + p.TNum + "]!解密出错", "CashPay");
                                                JS = null;
                                            }
                                            if (JS != null)
                                            {
                                                string respcode = JS["respcode"].ToString();
                                                if (respcode == "00")
                                                {
                                                    string resultcode = JS["resultcode"].ToString();
                                                    if (resultcode == "0000")
                                                    {
                                                        p.UserState = 1;
                                                    }
                                                    else if (resultcode == "2002" || resultcode == "2003")
                                                    {
                                                        p.UserState = 2;
                                                    }
                                                    else
                                                    {
                                                        p.UserState = 3;
                                                    }
                                                }
                                                else
                                                {
                                                    string respmsg = JS["respmsg"].ToString();
                                                    Utils.WriteLog("处理代付[" + p.TNum + "]!" + respmsg, "CashPay");
                                                }
                                            }
                                        }
                                        //======================================
                                        PayLog PayLog = new PayLog();
                                        PayLog.PId     = FastPayWay.Id;
                                        PayLog.OId     = p.TNum;
                                        PayLog.TId     = "";
                                        PayLog.Amount  = 0;
                                        PayLog.Way     = "FASTDF";
                                        PayLog.AddTime = DateTime.Now;
                                        PayLog.Data    = Ret;
                                        PayLog.State   = 1;
                                        Entity.PayLog.AddObject(PayLog);
                                        //======================================
                                        Entity.SaveChanges();
                                        #endregion
                                    }
                                    if (FastPayWay.DllName == "HFJSPay")
                                    {
                                        #region 结算系统
                                        //不需要
                                        #endregion
                                    }
                                }
                                Log.WriteLog("处理代付[" + p.TNum + "]!", JobName);
                            }
                            else
                            {
                                Log.WriteLog("处理代付[" + p.TNum + "]!商户止付", JobName);
                            }
                        }
                        #endregion
                        //-------------------------------------------------------
                        Log.Write(JobName + "任务执行结束![共计" + List.Count + "条]");
                    }
                    catch (Exception Ex)
                    {
                        Log.Write(JobName + "任务执行过程出错!", Ex);
                    }
                    IsRun = false;
                }
                else
                {
                    Log.Write(JobName + "任务还在执行中!");
                }
            }
        }
Exemplo n.º 16
0
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[FastOrderController]:", "【Data】" + Data, Ex);
                json = null;
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }

            FastOrder InFastOrder = new FastOrder();

            InFastOrder = JsonToObject.ConvertJsonToModel(InFastOrder, json);

            UserTrack UserTrack = new UserTrack();

            UserTrack = JsonToObject.ConvertJsonToModel(UserTrack, json);

            if (InFastOrder.Id == 99999)
            {
                DataObj.Msg = "当前通道维护中,建议您开通收款到银行卡功能,享受更多收款通道";
                DataObj.OutError("1000");
                return;
            }

            if (InFastOrder.CashType.IsNullOrEmpty())
            {
                InFastOrder.CashType = "D0";
                //DataObj.OutError("1000");
                //return;
            }
            decimal Amount = InFastOrder.Amoney;
            byte    payway = InFastOrder.OType;

            if (Amount <= 0)
            {
                DataObj.OutError("1000");
                return;
            }
            if (payway != 1 && payway != 2 && payway != 3)
            {
                DataObj.Msg = "你当前版本不支持该交易,请等待新版本发布及升级!";
                DataObj.OutError("1000");
                return;
            }

            Users Users = Entity.Users.FirstOrDefault(n => n.Token == InFastOrder.Token);

            #region 用户
            if (Users == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (Users.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (Users.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (Amount.IsNullOrEmpty() || payway.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            #endregion

            FastUser FastUser = Entity.FastUser.FirstOrDefault(o => o.UId == Users.Id);
            if (FastUser == null)
            {
                DataObj.OutError("2070");
                return;
            }
            #region 取通道
            IList <FastPayWay> FastPayWayList = null;
            if (InFastOrder.Id.IsNullOrEmpty())
            {
                //这是旧逻辑,有一些旧版还在用
                if (payway == 1)
                {
                    FastPayWayList = Entity.FastPayWay.Where(n => n.State == 1 && n.SNum2 < Amount && n.ENum2 >= Amount && n.HasAliPay == 1).OrderBy(n => n.Sort).ToList();
                }
                else if (payway == 2)
                {
                    FastPayWayList = Entity.FastPayWay.Where(n => n.State == 1 && n.SNum < Amount && n.ENum >= Amount && n.HasWeiXin == 1).OrderBy(n => n.Sort).ToList();
                }
                else if (payway == 3)
                {
                    FastPayWayList = Entity.FastPayWay.Where(n => n.State == 1 && n.BankSNum < Amount && n.BankENum >= Amount && n.HasBank == 1).OrderBy(n => n.Sort).ToList();
                }
                else
                {
                    DataObj.OutError("1000");
                    return;
                }
            }
            else
            {
                var query = Entity.FastPayWay.Where(n => n.Id == InFastOrder.Id && n.State == 1);
                if (payway == 1)
                {
                    query = query.Where(o => o.HasAliPay == 1 && o.SNum2 <= Amount && o.ENum2 >= Amount);
                }
                else if (payway == 2)
                {
                    query = query.Where(o => o.HasWeiXin == 1 && o.SNum <= Amount && o.ENum >= Amount);
                }
                else if (payway == 3)
                {
                    query = query.Where(o => o.HasBank == 1 && o.BankSNum <= Amount && o.BankENum >= Amount);
                }
                FastPayWayList = query.ToList();
            }
            #endregion
            if (FastPayWayList.Count < 1)
            {
                DataObj.OutError("2079");
                return;
            }
            #region 通道验证及商户进件信息验证
            FastPayWay         FastPayWay  = null;
            FastUserPay        FastUserPay = null;
            IList <FastPayWay> PayWayList  = new List <FastPayWay>();
            foreach (var p in FastPayWayList)
            {
                if (p.TimeType == 1)//限制时间,模式1
                {
                    DateTime STime    = p.STime;
                    DateTime ETime    = p.ETime;
                    DateTime NowSTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " " + STime.ToString("HH:mm:ss"));
                    DateTime NowETime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " " + ETime.ToString("HH:mm:ss"));
                    if (NowSTime <= DateTime.Now && DateTime.Now <= NowETime)
                    {
                        //当前时间允许交易
                        PayWayList.Add(p);
                    }
                }
                else
                {
                    PayWayList.Add(p);
                }
            }
            if (PayWayList.Count < 1)
            {
                DataObj.OutError("2071");
                return;
            }
            foreach (var p in PayWayList)
            {
                FastUserPay temp = Entity.FastUserPay.FirstOrDefault(n => n.UId == Users.Id && n.PayWay == p.Id && n.MerState == 1 && n.CardState == 1 && n.BusiState == 1);
                if (temp != null)
                {
                    FastPayWay  = p;
                    FastUserPay = temp;
                    break;
                }
            }
            if (FastUserPay == null)
            {
                DataObj.OutError("2072");
                return;
            }
            if (FastPayWay == null)
            {
                DataObj.OutError("2073");
                return;
            }
            #endregion
            string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
            #region 验证配置
            if (FastPayWay.DllName == "HFPay")
            {
                if (PayConfigArr.Length != 3)
                {
                    DataObj.OutError("2074");
                    return;
                }
            }
            if (FastPayWay.DllName == "HFJSPay")
            {
                if (PayConfigArr.Length != 3)
                {
                    DataObj.OutError("2074");
                    return;
                }
            }
            #endregion

            decimal UserCost  = 0;//用户
            decimal BankCost  = 0;
            decimal BankMin   = 0;
            decimal BankMax   = 0;
            decimal AgentCost = 0; //代理
            if (payway == 1)
            {                      //支付宝
                UserCost  = FastUserPay.UserCost2;
                BankCost  = FastPayWay.BankCost2;
                BankMin   = FastPayWay.MinCost2;
                BankMax   = FastPayWay.MaxCost2;
                AgentCost = FastPayWay.Cost2;
            }
            if (payway == 2)//微信
            {
                UserCost  = FastUserPay.UserCost;
                BankCost  = FastPayWay.BankCost;
                BankMin   = FastPayWay.MinCost;
                BankMax   = FastPayWay.MaxCost;
                AgentCost = FastPayWay.Cost;
            }
            if (payway == 3)//银联
            {
                UserCost  = FastUserPay.UserCost3;
                BankCost  = FastPayWay.BankCost3;
                BankMin   = FastPayWay.MinCost3;
                BankMax   = FastPayWay.MaxCost3;
                AgentCost = FastPayWay.Cost3;
            }
            #region 创建交易
            //=======================生成订单===========================
            SysAgent         SysAgent     = Entity.SysAgent.FirstOrNew(n => n.Id == Users.Agent);
            IList <SysAgent> SysAgentList = SysAgent.GetAgentsById(Entity);
            SysAgent         TopAgent     = SysAgentList.FirstOrNew();

            FastOrder FastOrder = new FastOrder();
            FastOrder.ComeWay = 1;
            FastOrder.UId     = Users.Id;
            FastOrder.Agent   = SysAgent.Id;

            FastOrder.PayId = string.Empty;

            FastOrder.OType    = payway;
            FastOrder.PayWay   = FastPayWay.Id;
            FastOrder.CashType = InFastOrder.CashType;
            FastOrder.Amoney   = Amount;

            //用户手续费
            decimal Poundage = Amount * UserCost + FastUserPay.UserCash;
            Poundage           = Poundage.Ceiling();
            FastOrder.Poundage = Poundage;
            //用户最终金额
            FastOrder.PayMoney = FastOrder.Amoney - FastOrder.Poundage;

            if (FastOrder.PayMoney < 0)
            {
                DataObj.OutError("2076");
                return;
            }
            FastOrder.UserRate  = UserCost;
            FastOrder.AgentRate = AgentCost;
            FastOrder.SysRate   = BankCost;
            FastOrder.UserCash  = FastUserPay.UserCash;
            FastOrder.SysCash   = FastPayWay.Cash;
            FastOrder.SameGet   = 0;
            //计算手续费差
            SysMoneySet SysMoneySet = Entity.SysMoneySet.FirstOrNew();
            decimal     PaySplit    = 0;//代理商费率
            PaySplit = SysAgent.GetSplit(TopAgent.Tier, Entity);
            decimal PayGet = Amount * PaySplit;
            PayGet = PayGet.Floor();
            //一级代理利润
            decimal AgentPayGet = PayGet;
            AgentPayGet           = AgentPayGet.Floor();
            FastOrder.AgentPayGet = 0;
            string  AgentPath = "|";
            string  Split     = "|";
            decimal MyGet     = PayGet;
            foreach (var p in SysAgentList)
            {
                PaySplit   = SysAgent.GetSplit(p.Tier, Entity);
                AgentPath += p.Id + "|";
                MyGet      = Amount * PaySplit;//各级代理分润
                MyGet      = MyGet.Floor();
                Split     += MyGet.ToString("F2") + "|";
            }
            FastOrder.AgentPath = AgentPath;
            FastOrder.Split     = Split;

            decimal BankMoney = Amount * BankCost;
            if (BankMoney < BankMin)
            {
                BankMoney = BankMin;
            }
            if (BankMoney > BankMax)
            {
                BankMoney = BankMax;
            }
            BankMoney = BankMoney.Floor();
            //用户手续费(含代付手续费)-代付分润-银行手续费-银行代付成本
            decimal HFGet = Poundage - AgentPayGet - BankMoney - FastPayWay.Cash;
            FastOrder.HFGet = HFGet;

            FastOrder.State   = 1;
            FastOrder.AddTime = DateTime.Now;

            FastOrder.PayState   = 0;
            FastOrder.AgentState = 0;
            FastOrder.UserState  = 0;

            FastOrder.CardName = FastUserPay.CardName;
            FastOrder.Bank     = FastUserPay.Bank;
            FastOrder.Card     = FastUserPay.Card;
            FastOrder.Bin      = FastUserPay.Bin;

            Entity.FastOrder.AddObject(FastOrder);
            Entity.SaveChanges();
            Entity.Refresh(RefreshMode.StoreWins, FastOrder);
            #endregion

            //=======================================
            UserTrack.ENo      = DataObj.ENo;
            UserTrack.OPType   = "到银行卡交易";
            UserTrack.UserName = FastOrder.TNum;
            UserTrack.UId      = FastOrder.UId;
            UserTrack.SeavGPSLog(Entity);
            //=======================================

            //=======================分润记录===========================
            MyGet = PayGet;
            int tier = 1;
            foreach (var p in SysAgentList)
            {
                PaySplit = SysAgent.GetSplit(p.Tier, Entity);
                MyGet    = Amount * PaySplit;//各级代理分润
                MyGet    = MyGet.Floor();
                FastSplit FastSplit = new FastSplit();
                FastSplit.Tnum    = FastOrder.TNum;
                FastSplit.Profit  = MyGet;
                FastSplit.AgentId = p.Id;
                FastSplit.Tier    = p.Tier;
                FastSplit.AddTime = DateTime.Now;
                Entity.FastSplit.AddObject(FastSplit);
                tier++;
            }
            Entity.SaveChanges();
            //=======================请求接口开始===========================
            if (FastOrder.OType == 1 || FastOrder.OType == 2)
            {
                if (FastPayWay.DllName == "HFPay")
                {
                    string NoticeUrl = NoticePath + "/PayCenter/HFPay/FastNotice.html";//后台通过地址
                    #region 微信&支付宝
                    string Action = "";
                    if (FastOrder.OType == 1)
                    {
                        Action = "AliSao";
                    }
                    else if (FastOrder.OType == 2)
                    {
                        Action = "WxSao";
                    }
                    //提交结算中心
                    string merId  = PayConfigArr[0]; //商户号
                    string merKey = PayConfigArr[1]; //商户密钥
                    string PayWay = PayConfigArr[2]; //绑定通道

                    decimal money      = FastOrder.Amoney * 100;
                    string  OrderMoney = money.ToString("F0");//金额,以分为单

                    string PostJson = "{\"action\":\"" + Action + "\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"payway\":\"" + PayWay + "\",\"orderid\":\"" + FastOrder.TNum + "\",\"backurl\":\"" + NoticeUrl + "\"}";

                    string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                    string Sign       = (DataBase64 + merKey).GetMD5();

                    DataBase64 = HttpUtility.UrlEncode(DataBase64);
                    string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);

                    string HF_Url = "https://api.zhifujiekou.com/api/mpgateway";

                    string Ret = Utils.PostRequest(HF_Url, PostData, "utf-8");

                    JObject JS = new JObject();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception)
                    {
                        FastOrder.State  = 0;
                        FastOrder.Remark = "数据请求出错";
                        Entity.SaveChanges();
                        JS = null;
                    }
                    if (JS != null)
                    {
                        string resp = JS["resp"].ToString();
                        Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                        try
                        {
                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                        }
                        catch (Exception Ex)
                        {
                            FastOrder.State  = 0;
                            FastOrder.Remark = "JSON加载出错";
                            Entity.SaveChanges();
                            JS = null;
                        }
                        if (JS != null)
                        {
                            string respcode = JS["respcode"].ToString();
                            if (respcode != "00")
                            {
                                string respmsg = JS["respmsg"].ToString();
                                FastOrder.State  = 0;
                                FastOrder.Remark = respmsg;
                                Entity.SaveChanges();
                            }
                            else
                            {
                                if (JS["formaction"] == null)
                                {
                                    FastOrder.State  = 0;
                                    FastOrder.Remark = "接口没有返回二维码";
                                    Entity.SaveChanges();
                                }
                                else
                                {
                                    string BankNum = JS["queryid"].ToString();
                                    string qr_code = JS["formaction"].ToString();
                                    FastOrder.PayId = qr_code;
                                    FastOrder.Trade = BankNum;
                                    Entity.SaveChanges();
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
            else if (FastOrder.OType == 3)
            {
                if (FastPayWay.DllName == "HFPay" || FastPayWay.DllName == "HFJSPay")
                {
                    #region
                    //银联不用请求第三方,直接生成链接
                    FastOrder.PayId = PayPath + "/paycenter/pay-" + FastOrder.Id + ".html?sign=" + ((FastOrder.Id * 100 + 99) + "Pay").GetMD5().Substring(8, 8);
                    Entity.SaveChanges();
                    #endregion
                }
            }
            if (FastOrder.State == 1)
            {
                if (FastOrder.PayState == 1)
                {
                    if (FastOrder.UserState == 1)
                    {
                        FastOrder.State = 3;
                    }
                    else
                    {
                        FastOrder.State = 2;
                    }
                }
                else
                {
                    FastOrder.State = 1;
                }
            }
            else
            {
                FastOrder.State = 0;
                DataObj.OutError("1005");
                return;
            }
            FastOrder.Cols = "TNum,PayId,Amoney,Poundage,State";

            DataObj.Data = FastOrder.OutJson();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
Exemplo n.º 17
0
        public ActionResult AddCard(string etnum, string Card = "", string Mobile = "", string code = "")
        {
            string    tnum      = LokFuEncode.LokFuAPIDecode(etnum, DllName);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "订单有误!";
                return(View("Error"));
            }
            Users Users = Entity.Users.FirstOrDefault(n => n.Id == FastOrder.UId);

            if (Users == null)
            {
                ViewBag.ErrorMsg = "商户信息有误!";
                return(View("Error"));
            }

            ViewBag.FastOrder = FastOrder;
            ViewBag.Users     = Users;
            ViewBag.etnum     = etnum;

            if (!Card.IsNullOrEmpty() && !Mobile.IsNullOrEmpty() && !code.IsNullOrEmpty())
            {
                if (Card.Length > 20)
                {
                    ViewBag.ErrorMsg = "卡号长度超限!";
                    return(View("Error"));
                }
                if (Mobile.Length > 20)
                {
                    ViewBag.ErrorMsg = "手机号码长度超限!";
                    return(View("Error"));
                }
                if (code.ToUpper() != Session.GetCheckCode())
                {
                    ViewBag.ErrorMsg = "验证码错误!";
                    return(View("Error"));
                }
                Session.ClearCheckCode();
                //绑卡前验证是否有鉴权权限
                UsersPayCard UsersPayCard = Entity.UsersPayCard.FirstOrDefault(n => n.Card == Card && n.Mobile == Mobile && n.UId == FastOrder.UId);
                if (UsersPayCard == null)//不存在则绑卡
                {
                    UserBlackList UserBlackList = Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == Card && UBL.State == 3);
                    if (UserBlackList != null)
                    {
                        ViewBag.ErrorMsg = "暂不支持该银行卡绑卡";
                        return(View("Error"));
                    }

                    string HaoFu_Auth_MerId  = ConfigurationManager.AppSettings["HaoFu_Auth_MerId"].ToString();
                    string HaoFu_Auth_MerKey = ConfigurationManager.AppSettings["HaoFu_Auth_MerKey"].ToString();
                    string HaoFu_Auth_Url    = ConfigurationManager.AppSettings["HaoFu_Auth_Url"].ToString();

                    string data       = "{\"action\":\"authuser\",\"merid\":\"" + HaoFu_Auth_MerId + "\",\"orderid\":\"" + FastOrder.TNum + "\",\"bankaccount\":\"" + Card + "\",\"accountname\":\"" + Users.TrueName + "\",\"identitycode\":\"" + Users.CardId + "\",\"mobile\":\"" + Mobile + "\"}";
                    string DataBase64 = LokFuEncode.Base64Encode(data, "utf-8");
                    string Sign       = (DataBase64 + HaoFu_Auth_MerKey).GetMD5();

                    DataBase64 = HttpUtility.UrlEncode(DataBase64, Encoding.UTF8);
                    string postdata = "req=" + DataBase64 + "&sign=" + Sign;

                    string CONTENT = Utils.PostRequest(HaoFu_Auth_Url, postdata, "utf-8");

                    JObject JS = new JObject();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
                    }
                    catch (Exception)
                    {
                        ViewBag.ErrorMsg = "请求银联鉴权失败!【00】";
                        return(View("Error"));
                    }
                    string resp = JS["resp"].ToString();
                    CONTENT = LokFuEncode.Base64Decode(resp, "utf-8");
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
                    }
                    catch (Exception)
                    {
                        ViewBag.ErrorMsg = "请求银联鉴权失败!【01】";
                        return(View("Error"));
                    }
                    string ret_code = JS["respcode"].ToString();

                    if (ret_code == "0000")
                    {
                        string BankNumLeft = Card.Substring(0, 6);
                        //获取卡Bin
                        BasicCardBin BasicCardBin = Entity.BasicCardBin.FirstOrDefault(n => n.BIN == BankNumLeft);
                        string       bankName     = "银联卡";
                        byte         CardType     = 0;
                        if (BasicCardBin != null)
                        {
                            bankName = BasicCardBin.BankName;
                            CardType = (byte)BasicCardBin.CardType;
                        }
                        else
                        {
                        }
                        UsersPayCard         = new UsersPayCard();
                        UsersPayCard.UId     = FastOrder.UId;
                        UsersPayCard.Type    = CardType;
                        UsersPayCard.Bank    = bankName;
                        UsersPayCard.Name    = Users.TrueName;
                        UsersPayCard.Card    = Card;
                        UsersPayCard.Mobile  = Mobile;
                        UsersPayCard.State   = 1;
                        UsersPayCard.AddTime = DateTime.Now;
                        Entity.UsersPayCard.AddObject(UsersPayCard);
                        Entity.SaveChanges();
                        Response.Redirect("GoPay.html?BankId=" + UsersPayCard.Id + "&etnum=" + HttpUtility.UrlEncode(etnum));
                    }
                    else
                    {
                        string ret_msg = JS["respmsg"].ToString();
                        ViewBag.ErrorMsg = "银行卡认证失败!";
                        return(View("Error"));
                    }
                }
                else
                {
                    if (UsersPayCard.State == 0)
                    {
                        UsersPayCard.State = 1;
                        Entity.SaveChanges();
                    }
                    Response.Redirect("GoPay.html?BankId=" + UsersPayCard.Id + "&etnum=" + HttpUtility.UrlEncode(etnum));
                }
            }
            return(View());
        }
        public ActionResult GoPay(int shopid = 0, decimal Amount = 0, byte payway = 0)
        {
            if (shopid.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "商户信息有误,请核实!";
                return(View("Error"));
            }
            if (Amount.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "付款金额有误,请核实!";
                return(View("Error"));
            }
            if (payway.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "请选择支付方式!";
                return(View("Error"));
            }
            if (payway == 3 && shopid != 26)
            {
                ViewBag.ErrorMsg = "暂不开放!";
                return(View("Error"));
            }
            Users Users = Entity.Users.FirstOrNew(n => n.Id == shopid && n.State == 1 && n.CardStae == 2);

            if (Users.Id.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "商户信息有误,请核实!";
                return(View("Error"));
            }
            ViewBag.Users = Users;
            if (Amount <= 0)
            {
                ViewBag.ErrorMsg = "付款金额有误![00]";
                return(View("Error"));
            }
            IList <FastPayWay> FastPayWayList = null;

            if (payway == 1)
            {
                FastPayWayList = Entity.FastPayWay.Where(n => n.State == 1 && n.SNum2 < Amount && n.ENum2 >= Amount && n.HasAliPay == 1).OrderBy(n => n.Sort).ToList();
            }
            else if (payway == 2)
            {
                FastPayWayList = Entity.FastPayWay.Where(n => n.State == 1 && n.SNum < Amount && n.ENum >= Amount && n.HasWeiXin == 1).OrderBy(n => n.Sort).ToList();
            }
            else
            {
                ViewBag.ErrorMsg = "支付方式有误!";
                return(View("Error"));
            }
            if (FastPayWayList.Count < 1)
            {
                ViewBag.ErrorMsg = "当前没有可用的渠道!";
                return(View("Error"));
            }
            FastPayWay         FastPayWay  = null;
            FastUserPay        FastUserPay = null;
            IList <FastPayWay> PayWayList  = new List <FastPayWay>();

            foreach (var p in FastPayWayList)
            {
                if (p.TimeType == 1)//限制时间,模式1
                {
                    DateTime STime    = p.STime;
                    DateTime ETime    = p.ETime;
                    DateTime NowSTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " " + STime.ToString("HH:mm:ss"));
                    DateTime NowETime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " " + ETime.ToString("HH:mm:ss"));
                    if (NowSTime <= DateTime.Now && DateTime.Now <= NowETime)
                    {
                        //当前时间允许交易
                        PayWayList.Add(p);
                    }
                }
                else
                {
                    PayWayList.Add(p);
                }
            }
            if (PayWayList.Count < 1)
            {
                ViewBag.ErrorMsg = "请在可交易时间内进行交易!";
                return(View("Error"));
            }
            foreach (var p in PayWayList)
            {
                FastUserPay temp = Entity.FastUserPay.FirstOrDefault(n => n.UId == Users.Id && n.PayWay == p.Id && n.MerState == 1 && n.CardState == 1);
                if (temp != null)
                {
                    FastPayWay  = p;
                    FastUserPay = temp;
                    break;
                }
            }
            if (FastUserPay == null)
            {
                ViewBag.ErrorMsg = "渠道未开通!";
                return(View("Error"));
            }
            if (FastPayWay == null)
            {
                ViewBag.ErrorMsg = "通道未开通!";
                return(View("Error"));
            }
            decimal UserCost  = 0;//用户
            decimal BankCost  = 0;
            decimal BankMin   = 0;
            decimal BankMax   = 0;
            decimal AgentCost = 0; //代理

            if (payway == 1)       //支付宝
            {
                UserCost  = FastUserPay.UserCost2;
                BankCost  = FastPayWay.BankCost2;
                BankMin   = FastPayWay.MinCost2;
                BankMax   = FastPayWay.MaxCost2;
                AgentCost = FastPayWay.Cost2;
            }
            if (payway == 2)//微信
            {
                UserCost  = FastUserPay.UserCost;
                BankCost  = FastPayWay.BankCost;
                BankMin   = FastPayWay.MinCost;
                BankMax   = FastPayWay.MaxCost;
                AgentCost = FastPayWay.Cost;
            }
            if (payway == 3)//银联
            {
                UserCost  = FastUserPay.UserCost3;
                BankCost  = FastPayWay.BankCost3;
                BankMin   = FastPayWay.MinCost3;
                BankMax   = FastPayWay.MaxCost3;
                AgentCost = FastPayWay.Cost3;
            }
            //=======================生成订单===========================
            SysAgent         SysAgent     = Entity.SysAgent.FirstOrNew(n => n.Id == Users.Agent);
            IList <SysAgent> SysAgentList = SysAgent.GetAgentsById(Entity);
            SysAgent         TopAgent     = SysAgentList.FirstOrNew(n => n.Tier == 1);

            FastOrder FastOrder = new FastOrder();

            FastOrder.ComeWay = 2;
            FastOrder.UId     = Users.Id;
            FastOrder.Agent   = SysAgent.Id;

            FastOrder.PayId = string.Empty;

            FastOrder.OType    = payway;
            FastOrder.PayWay   = FastPayWay.Id;
            FastOrder.CashType = FastPayWay.GroupType;
            FastOrder.Amoney   = Amount;

            //用户手续费
            decimal Poundage = Amount * UserCost + FastUserPay.UserCash;

            Poundage           = Poundage.Ceiling();
            FastOrder.Poundage = Poundage;
            //用户最终金额
            FastOrder.PayMoney = FastOrder.Amoney - FastOrder.Poundage;

            if (FastOrder.PayMoney < 0)
            {
                ViewBag.ErrorMsg = "结算金额出现负数!";
                return(View("Error"));
            }

            FastOrder.UserRate = UserCost;

            FastOrder.AgentRate = AgentCost;
            FastOrder.SysRate   = BankCost;

            FastOrder.UserCash = FastUserPay.UserCash;
            FastOrder.SysCash  = FastPayWay.Cash;

            //计算手续费差
            decimal PayGet = Amount * (UserCost - AgentCost);

            PayGet = PayGet.Floor();
            //一级代理利润
            decimal AgentPayGet = PayGet * (decimal)TopAgent.PayGet;

            AgentPayGet = AgentPayGet.Floor();

            FastOrder.AgentPayGet = AgentPayGet;

            string  AgentPath = "|";
            string  Split     = "|";
            decimal MyGet     = PayGet;

            foreach (var p in SysAgentList)
            {
                AgentPath += p.Id + "|";
                MyGet      = MyGet * (decimal)p.PayGet;//各级代理分润
                MyGet      = MyGet.Floor();
                Split     += MyGet.ToString("F2") + "|";
            }
            FastOrder.AgentPath = AgentPath;
            FastOrder.Split     = Split;

            decimal BankMoney = Amount * BankCost;

            if (BankMoney < BankMin)
            {
                BankMoney = BankMin;
            }
            if (BankMoney > BankMax)
            {
                BankMoney = BankMax;
            }
            //用户手续费(含代付手续费)-代付分润-银行手续费-银行代付成本
            decimal HFGet = Poundage - AgentPayGet - BankMoney - FastPayWay.Cash;

            FastOrder.HFGet = HFGet;

            FastOrder.State   = 1;
            FastOrder.AddTime = DateTime.Now;

            FastOrder.PayState   = 0;
            FastOrder.AgentState = 0;
            FastOrder.UserState  = 0;

            FastOrder.CardName = FastUserPay.CardName;
            FastOrder.Bank     = FastUserPay.Bank;
            FastOrder.Card     = FastUserPay.Card;
            FastOrder.Bin      = FastUserPay.Bin;

            Entity.FastOrder.AddObject(FastOrder);
            Entity.SaveChanges();
            Entity.Refresh(RefreshMode.StoreWins, FastOrder);
            //=======================分润记录===========================
            MyGet = PayGet;
            foreach (var p in SysAgentList)
            {
                MyGet = MyGet * (decimal)p.PayGet;//各级代理分润
                MyGet = MyGet.Floor();
                FastSplit FastSplit = new FastSplit();
                FastSplit.Tnum    = FastOrder.TNum;
                FastSplit.Profit  = MyGet;
                FastSplit.AgentId = p.Id;
                FastSplit.Tier    = p.Tier;
                FastSplit.AddTime = DateTime.Now;
                Entity.FastSplit.AddObject(FastSplit);
            }
            Entity.SaveChanges();
            //RespObj.queryId = Orders.TNum;
            string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
            //=======================请求接口开始===========================
            if (FastPayWay.DllName == "HFPay")
            {
                string NoticeUrl = NoticePath + "/PayCenter/HFPay/FastNotice.html";//后台通过地址
                #region 微信&支付宝
                string Action = "";
                if (FastOrder.OType == 1)
                {
                    Action = "AliSao";
                }
                else if (FastOrder.OType == 2)
                {
                    Action = "WxSao";
                }
                //提交结算中心
                string merId  = PayConfigArr[0]; //商户号
                string merKey = PayConfigArr[1]; //商户密钥
                string PayWay = PayConfigArr[2]; //绑定通道

                decimal money      = FastOrder.Amoney * 100;
                string  OrderMoney = money.ToString("F0");//金额,以分为单

                string PostJson = "{\"action\":\"" + Action + "\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"payway\":\"" + PayWay + "\",\"orderid\":\"" + FastOrder.TNum + "\",\"backurl\":\"" + NoticeUrl + "\"}";

                string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                string Sign       = (DataBase64 + merKey).GetMD5();

                DataBase64 = HttpUtility.UrlEncode(DataBase64);
                string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);

                string HF_Url = "https://api.zhifujiekou.com/api/mpgateway";

                string Ret = Utils.PostRequest(HF_Url, PostData, "utf-8");

                JObject JS = new JObject();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(Ret);
                }
                catch (Exception)
                {
                    FastOrder.State  = 0;
                    FastOrder.Remark = "数据请求出错";
                    Entity.SaveChanges();
                    JS = null;
                }
                if (JS != null)
                {
                    string resp = JS["resp"].ToString();
                    Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception Ex)
                    {
                        FastOrder.State  = 0;
                        FastOrder.Remark = "JSON加载出错";
                        Entity.SaveChanges();
                        JS = null;
                    }
                    if (JS != null)
                    {
                        string respcode = JS["respcode"].ToString();
                        if (respcode != "00")
                        {
                            string respmsg = JS["respmsg"].ToString();
                            FastOrder.State  = 0;
                            FastOrder.Remark = respmsg;
                            Entity.SaveChanges();
                        }
                        else
                        {
                            if (JS["formaction"] == null)
                            {
                                FastOrder.State  = 0;
                                FastOrder.Remark = "接口没有返回二维码";
                                Entity.SaveChanges();
                            }
                            else
                            {
                                string BankNum = JS["queryid"].ToString();
                                string qr_code = JS["formaction"].ToString();
                                FastOrder.PayId = qr_code;
                                FastOrder.Trade = BankNum;
                                Entity.SaveChanges();
                            }
                        }
                    }
                }
                #endregion
            }
            ViewBag.FastOrder = FastOrder;
            if (IsAlipayBrowser)
            {
                if (!FastOrder.PayId.IsNullOrEmpty())
                {
                    Response.Redirect(FastOrder.PayId);
                    return(View("Null"));
                }
            }
            return(View());
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[UsersTrueNameByAPI]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            UserAuth UserAuth = new UserAuth();

            UserAuth = JsonToObject.ConvertJsonToModel(UserAuth, json);

            SysSet SysSet = this.Entity.SysSet.FirstOrNew();

            if (!UserAuth.IdentityCode.IsNullOrEmpty())
            {
                var y        = UserAuth.IdentityCode.Substring(6, 4);
                var m        = UserAuth.IdentityCode.Substring(10, 2);
                var d        = UserAuth.IdentityCode.Substring(12, 2);
                var birthday = new DateTime(int.Parse(y), int.Parse(m), int.Parse(d));
                var now      = DateTime.Now;
                int age      = now.Year - birthday.Year;
                if (now.Month < birthday.Month || (now.Month == birthday.Month && now.Day < birthday.Day))
                {
                    age--;
                }
                if (age > SysSet.AuthMaxAge || age < SysSet.AuthMinAge)
                {
                    DataObj.OutError("1104");
                    return;
                }
            }

            Users Users = new Users();

            Users = JsonToObject.ConvertJsonToModel(Users, json);

            UserTrack UserTrack = new UserTrack();

            UserTrack = JsonToObject.ConvertJsonToModel(UserTrack, json);

            if (UserAuth.Token.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            if (UserAuth.NeekName.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            if (Users.X.IsNullOrEmpty() || Users.Y.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }

            string HaoFu_Auth_Open = ConfigurationManager.AppSettings["HaoFu_Auth_Open"].ToString();
            //SysSet SysSet = Entity.SysSet.FirstOrNew();

            byte CardItemNum  = 0;
            byte CardType     = 0;
            byte UsedCardType = 0;

            if (Equipment.RqType == "Apple")
            {
                CardItemNum = SysSet.IosSet10;
                if (SysSet.IosSet11 == 0)
                {
                    CardType = 0;
                }
                if (SysSet.IosSet11 == 1)
                {
                    CardType = 2;
                }
                if (SysSet.IosSet11 == 2)
                {
                    CardType = 1;
                }
            }
            else
            {
                CardItemNum = SysSet.ApkSet10;
                if (SysSet.ApkSet11 == 0)
                {
                    CardType = 0;
                }
                if (SysSet.ApkSet11 == 1)
                {
                    CardType = 2;
                }
                if (SysSet.ApkSet11 == 2)
                {
                    CardType = 1;
                }
            }
            if (HaoFu_Auth_Open != "true")
            {
                CardItemNum = 6;//兼容直连六要素接口
            }
            if (CardItemNum == 6)
            {
                if (UserAuth.BankAccount.IsNullOrEmpty() || UserAuth.AccountName.IsNullOrEmpty() || UserAuth.IdentityCode.IsNullOrEmpty() || UserAuth.Mobile.IsNullOrEmpty() || UserAuth.CVV.IsNullOrEmpty() || UserAuth.EndDate.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
                CardType = 2;//六要素一定是信用卡
            }
            else if (CardItemNum == 4)
            {
                if (UserAuth.BankAccount.IsNullOrEmpty() || UserAuth.AccountName.IsNullOrEmpty() || UserAuth.IdentityCode.IsNullOrEmpty() || UserAuth.Mobile.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
            }
            else if (CardItemNum == 3)
            {
                if (UserAuth.BankAccount.IsNullOrEmpty() || UserAuth.AccountName.IsNullOrEmpty() || UserAuth.IdentityCode.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
            }
            else
            {
                DataObj.OutError("1000");
                return;
            }
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == UserAuth.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae == 2)   //已实名认证
            {
                DataObj.OutError("2007");
                return;
            }
            int CardIdCount = Entity.Users.Count(n => n.CardId == UserAuth.IdentityCode && n.CardStae == 2);

            if (CardIdCount > 0) //身份证已用过
            {
                DataObj.OutError("2020");
                return;
            }
            //验证账号是否被限制
            if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == baseUsers.UserName && UBL.State == 1) != null)
            {
                //提示暂不支持您入网
                DataObj.OutError("2027");
                return;
            }
            //验证身份证是否被限制
            if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == UserAuth.IdentityCode && UBL.State == 2) != null)
            {
                //提示暂不支持您入网
                DataObj.OutError("2027");
                return;
            }
            //验证银行卡是否被限制
            if (Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == UserAuth.BankAccount && UBL.State == 3) != null)
            {
                //提示暂不支持您入网
                DataObj.OutError("2027");
                return;
            }
            //2016-10-07 非法关键词限制
            if (!SysSet.NoWord.IsNullOrEmpty())
            {
                string NeekName = Users.NeekName;
                NeekName = NeekName.Replace(" ", "").Replace(" ", "");
                string[] NoWord    = SysSet.NoWord.Split('|');
                bool     hasNoWord = false;
                string   noword    = "";
                foreach (var p in NoWord)
                {
                    if (NeekName.Contains(p))
                    {
                        hasNoWord = true;
                        noword    = p;
                        break;
                    }
                }
                if (hasNoWord)
                {
                    DataObj.Msg = "禁止使用关键词“" + noword + "”";
                    DataObj.OutError("2025");
                    return;
                }
            }

            //2016-09-30 限制重名提交
            Users tempUsers = Entity.Users.FirstOrDefault(n => n.NeekName == Users.NeekName && n.State == 1 && (n.CardStae == 2 || n.CardStae == 1));

            if (tempUsers != null)
            {
                DataObj.OutError("2024");
                return;
            }

            int Count = Entity.UserAuth.Count(n => n.UId == baseUsers.Id && n.IsCharge == 1);

            if (Count >= SysSet.AuthTimes)
            {
                DataObj.OutError("2022");
                return;
            }

            if (!UserAuth.EndDate.IsNullOrEmpty())
            {
                //处理年月问题传上来是MMYY
                //20151112调整成YYMM
                if (UserAuth.EndDate.Length == 4)
                {
                    string MM = UserAuth.EndDate.Substring(0, 2);
                    string YY = UserAuth.EndDate.Substring(2, 2);
                    UserAuth.EndDate = YY + MM;
                }
            }

            UserAuth.AddTime  = DateTime.Now;
            UserAuth.UId      = baseUsers.Id;
            UserAuth.IsCharge = 0;
            Entity.UserAuth.AddObject(UserAuth);
            Entity.SaveChanges();
            Entity.Refresh(RefreshMode.StoreWins, UserAuth);

            #region 贴牌配置
            int ApkSet3   = SysSet.ApkSet3;
            int IosSet3   = SysSet.IosSet3;
            var vSysAgent = Entity.SysAgent.FirstOrDefault(o => o.Id == baseUsers.Agent);
            if (vSysAgent == null)
            {
                DataObj.OutError("1000");
                return;
            }
            var topSysAgent = vSysAgent.GetTopAgent(Entity);
            if (topSysAgent != null && topSysAgent.IsTeiPai == 1)
            {
                ApkSet3 = topSysAgent.Set3;
                IosSet3 = topSysAgent.Set3;
            }
            #endregion

            #region 激活码逻辑
            Card Card        = null;
            bool IsCheckCard = false;
            //必填
            if ((ApkSet3 == 1 && this.Equipment.RqType == "Android") || (IosSet3 == 1 && this.Equipment.RqType == "Apple"))
            {
                IsCheckCard = true;
                if (UserAuth.CardNum.IsNullOrEmpty() || UserAuth.CardPWD.IsNullOrEmpty())
                {
                    DataObj.OutError("1000");
                    return;
                }
            }

            //选填
            if ((ApkSet3 == 3 && this.Equipment.RqType == "Android") || (IosSet3 == 3 && this.Equipment.RqType == "Apple"))
            {
                if (!UserAuth.CardNum.IsNullOrEmpty() && !UserAuth.CardPWD.IsNullOrEmpty())
                {
                    IsCheckCard = true;
                }
            }

            if (IsCheckCard)
            {
                Card = Entity.Card.FirstOrDefault(n => n.Code == UserAuth.CardNum && n.PasWd == UserAuth.CardPWD && n.Auto == 1);
                if (Card == null)
                {
                    DataObj.OutError("5001");
                    return;
                }
                if (Card.State != 1)
                {
                    string StateStr = string.Empty;
                    switch (Card.State)
                    {
                    case 2:
                        StateStr = "已授权";
                        break;

                    case 3:
                        StateStr = "已使用";
                        break;

                    case 0:
                        StateStr = "已失效";
                        break;
                    }

                    DataObj.Msg = "激活码" + StateStr;
                    DataObj.OutError("5001");
                    return;
                }
                if (Card.AId.IsNullOrEmpty())
                {
                    DataObj.OutError("5002");
                    return;
                }
                if (Card.AdminId.IsNullOrEmpty())
                {
                    DataObj.OutError("5002");
                    return;
                }
                Card.State        = 3;//使用中
                baseUsers.CardNum = Card.Code;
            }
            #endregion

            string ret_code = "";
            string ret_msg  = "";
            string isCharge = "";

            string CONTENT = "";

            #region 第三方接口查询
            if (HaoFu_Auth_Open == "true")
            {
                if (CardItemNum != 6)
                {
                    UsedCardType = GetCardType(UserAuth.BankAccount);
                    if (CardType == 1)//要求借记卡
                    {
                        if (UsedCardType != 1)
                        {
                            DataObj.OutError("2023");
                            Utils.WriteLog(CardType + "===" + UsedCardType + "无法查询的卡:" + UserAuth.BankAccount, "bankcard");
                            return;
                        }
                    }
                    if (CardType == 2)//要求信用卡
                    {
                        if (UsedCardType != 2)
                        {
                            DataObj.OutError("2023");
                            Utils.WriteLog(CardType + "===" + UsedCardType + "无法查询的卡:" + UserAuth.BankAccount, "bankcard");
                            return;
                        }
                    }
                }
                else
                {
                    UsedCardType = 2;
                }

                string HaoFu_Auth_MerId  = ConfigurationManager.AppSettings["HaoFu_Auth_MerId"].ToString();
                string HaoFu_Auth_MerKey = ConfigurationManager.AppSettings["HaoFu_Auth_MerKey"].ToString();
                string HaoFu_Auth_Url    = ConfigurationManager.AppSettings["HaoFu_Auth_Url"].ToString();

                string data       = "{\"action\":\"authuser\",\"merid\":\"" + HaoFu_Auth_MerId + "\",\"orderid\":\"" + UserAuth.OId + "\",\"bankaccount\":\"" + UserAuth.BankAccount + "\",\"accountname\":\"" + UserAuth.AccountName + "\",\"identitycode\":\"" + UserAuth.IdentityCode + "\",\"mobile\":\"" + UserAuth.Mobile + "\",\"cvv\":\"" + UserAuth.CVV + "\",\"enddate\":\"" + UserAuth.EndDate + "\"}";
                string DataBase64 = LokFuEncode.Base64Encode(data, "utf-8");
                string Sign       = (DataBase64 + HaoFu_Auth_MerKey).GetMD5();

                DataBase64 = HttpUtility.UrlEncode(DataBase64, Encoding.UTF8);
                string postdata = "req=" + DataBase64 + "&sign=" + Sign;

                CONTENT = Utils.PostRequest(HaoFu_Auth_Url, postdata, "utf-8");

                JObject JS = new JObject();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
                }
                catch (Exception Ex)
                {
                    Log.Write("[UsersTrueNameByAPI]:", "【CONTENT】" + CONTENT, Ex);
                }
                if (JS == null)
                {
                    DataObj.OutError("2021");
                    return;
                }
                string resp = JS["resp"].ToString();
                CONTENT = LokFuEncode.Base64Decode(resp, "utf-8");
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
                }
                catch (Exception Ex)
                {
                    Log.Write("[UsersTrueNameByAPI]:", "【CONTENT2】" + CONTENT, Ex);
                }
                if (JS == null)
                {
                    DataObj.OutError("2021");
                    return;
                }
                ret_code = JS["respcode"].ToString();
                ret_msg  = JS["respmsg"].ToString();
                if (JS["ischarge"] != null)
                {
                    isCharge = JS["ischarge"].ToString();
                }
                if (isCharge == "1")
                {
                    UserAuth.IsCharge = 1;
                }
                else
                {
                    UserAuth.IsCharge = 0;
                }
            }
            #endregion

            #region 审核处理
            UserAuth.RetCode = ret_code;
            UserAuth.RetMsg  = ret_msg;
            UserAuth.RetLog  = CONTENT;

            baseUsers.TrueName = UserAuth.AccountName;
            baseUsers.NeekName = UserAuth.NeekName;
            baseUsers.CardId   = UserAuth.IdentityCode;

            baseUsers.CardFace = "";

            baseUsers.CardType = 1;
            if (UsedCardType == 2)
            {
                baseUsers.HasT0 = 1;
            }
            else
            {
                baseUsers.HasT0 = 0;
            }

            string Code = "0000";
            if (ret_code == "0000")
            {
                baseUsers.CardStae = 2;//直接审核通过
                //=======================================
                string GPSAddress = Users.RegAddress;
                if (GPSAddress.IsNullOrEmpty())
                {
                    GPSAddress = Utils.GetAddressByGPS(Users.X, Users.Y);
                }
                if (!GPSAddress.IsNullOrEmpty())
                {
                    baseUsers.RegAddress = GPSAddress;
                    baseUsers.X          = Users.X;
                    baseUsers.Y          = Users.Y;
                }
                //=======================================
                UserTrack.ENo        = DataObj.ENo;
                UserTrack.OPType     = "自动认证";
                UserTrack.GPSAddress = GPSAddress;
                UserTrack.GPSX       = Users.X;
                UserTrack.GPSY       = Users.Y;
                baseUsers.SeavGPSLog(UserTrack, Entity);
                //=======================================

                //20151125需要对有绑卡的用户验证是否是来源与推广,增加抽奖次数
                #region  人推广
                if (!baseUsers.MyPId.IsNullOrEmpty())
                {
                    if (baseUsers.ShareType == 2)
                    {
                        //支付通道升级推广
                        PayConfigChange PCC = Entity.PayConfigChange.FirstOrDefault(n => n.Id == baseUsers.PayConfigId && n.State == 1 && n.ShareNumber > 0);
                        if (PCC != null)
                        {
                            int count = Entity.Users.Count(n => n.CardStae == 2 && n.State == 1 && n.MyPId == baseUsers.MyPId && n.PayConfigId == baseUsers.PayConfigId && n.Id != baseUsers.Id);

                            count++;                      //这里统计会漏掉当前用户的,需要增加1个。

                            if (count == PCC.ShareNumber) //相等的那一次调整,避免超出了还一直调整
                            {
                                Users UP = Entity.Users.FirstOrDefault(n => n.Id == baseUsers.MyPId);
                                if (PCC.CState == 1)
                                {
                                    if (UP.Cash0 > PCC.Cash0)
                                    {
                                        UP.Cash0 = PCC.Cash0;
                                    }
                                    if (UP.ECash0 > PCC.ECash0)
                                    {
                                        UP.ECash0 = PCC.ECash0;
                                    }
                                }
                                if (PCC.EState == 1)
                                {
                                    if (UP.Cash1 > PCC.Cash1)
                                    {
                                        UP.Cash1 = PCC.Cash1;
                                    }
                                    if (UP.ECash1 > PCC.ECash1)
                                    {
                                        UP.ECash1 = PCC.ECash1;
                                    }
                                }
                                IList <UserPay> List = Entity.UserPay.Where(n => n.UId == baseUsers.MyPId).ToList();//获取用户配置
                                foreach (var p in List)
                                {
                                    PayConfigTemp PCT = Entity.PayConfigTemp.FirstOrDefault(n => n.PId == p.PId && n.PCCId == PCC.Id);
                                    //获取套餐配置
                                    if (PCT != null)
                                    {
                                        if (PCT.State == 1)
                                        {
                                            if (p.Cost > PCT.Cost)
                                            {
                                                p.Cost = PCT.Cost;
                                            }
                                        }
                                    }
                                }
                                string UserPayCashName = "UserPay_" + UP.Id.ToString() + "_" + Equipment.RqType;
                                CacheBuilder.EntityCache.Remove(UserPayCashName, null);
                                string PayConfigChangeCashName = "PayConfigChange_" + UP.Agent + "_" + UP.Id;
                                CacheBuilder.EntityCache.Remove(PayConfigChangeCashName, null);
                                //Utils.WriteLog("UserPayCashName:" + UserPayCashName + " PayConfigChangeCashName:" + PayConfigChangeCashName, "ClearCache");
                            }
                        }
                    }
                    if (baseUsers.ShareType == 1)
                    {
                        //增加推广抽奖次数
                        TurnUsers TurnUsers = Entity.TurnUsers.FirstOrNew(n => n.UId == baseUsers.MyPId);
                        if (!TurnUsers.Id.IsNullOrEmpty())
                        {
                            TurnUsers.Times++;
                        }
                    }
                    #region 分享统计数
                    //===================================增加分享统计数===================================
                    //获取用户所属各级分润配置
                    // IList<UserPromoteGet> UserPromoteGetList = Entity.UserPromoteGet.Where(n => n.AgentID == baseUsers.Agent).OrderBy(n => n.PromoteLevel).ToList();
                    int MaxLevel = SysSet.GlobaPromoteMaxLevel;
                    //获取用户各级关系,最大级不超过用户配置级数。返回数据包含当前用户,当前用户级数标识Tier为0
                    IList <Users> UsersList = baseUsers.GetUsersById(Entity, MaxLevel);
                    foreach (var U in UsersList.Where(n => n.Tier > 0))
                    {
                        ShareTotal ShareTotal = Entity.ShareTotal.FirstOrDefault(n => n.UId == U.Id && n.Tier == U.Tier);
                        if (ShareTotal == null)
                        {
                            ShareTotal          = new ShareTotal();
                            ShareTotal.UId      = U.Id;
                            ShareTotal.AddTime  = DateTime.Now;
                            ShareTotal.ShareNum = 1;
                            ShareTotal.Amount   = 0;
                            ShareTotal.Profit   = 0;
                            ShareTotal.Tier     = U.Tier;
                            Entity.ShareTotal.AddObject(ShareTotal);
                        }
                        else
                        {
                            ShareTotal.ShareNum += 1;
                        }
                        Entity.SaveChanges();
                    }
                    //===================================增加分享统计数 End===================================
                    #endregion
                }
                #endregion

                if (Card != null)
                {
                    //代理商信息
                    baseUsers.Agent = Card.AId;
                    baseUsers.AId   = Card.AdminId;
                    //推广信息
                    if (!Card.PUId.IsNullOrEmpty())
                    {
                        if (baseUsers.MyPId.IsNullOrEmpty())
                        {
                            //不是费率升级推广才有效
                            baseUsers.MyPId       = Card.PUId;
                            baseUsers.PayConfigId = 0;
                            baseUsers.ShareType   = 1;
                        }
                    }
                    Card.State = 2;
                }
            }
            else
            {
                Code = "2021";
                baseUsers.CardStae = 3;//审核失败
                baseUsers.CardNum  = "";
                if (Card != null)
                {
                    Card.State = 1;
                }
            }
            Entity.SaveChanges();
            #endregion
            DataObj.Data = UserAuth.OutJson();
            DataObj.Code = Code;
            DataObj.OutString();
        }
        public string PayState(string code)
        {
            string    TNum      = LokFuEncode.Base64Decode(code);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == TNum);

            if (FastOrder == null)
            {
                return("E1");
            }
            if (FastOrder.PayState == 1)
            {
                return("S");
            }
            if (FastOrder.State != 1)
            {
                return("E0");
            }
            FastPayWay FastPayWay = Entity.FastPayWay.FirstOrNew(n => n.Id == FastOrder.PayWay);

            if (FastPayWay == null)
            {
                return("E2");
            }
            string[] PayConfigArr = FastPayWay.QueryArray.Split(new char[] { ',' });//接口信息
            if (FastPayWay.DllName == "HFPay")
            {
                #region 结算中心
                if (PayConfigArr.Length == 3)
                {
                    string HF_Url     = "https://api.zhifujiekou.com/api/query";
                    string MerId      = PayConfigArr[0];
                    string MerKey     = PayConfigArr[1];
                    string orderId    = FastOrder.TNum;//商户流水号
                    string PostJson   = "{\"merid\":\"" + MerId + "\",\"orderid\":\"" + orderId + "\"}";
                    string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                    string Sign       = (DataBase64 + MerKey).GetMD5();
                    DataBase64 = HttpUtility.UrlEncode(DataBase64);
                    string  PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                    string  Ret      = Utils.PostRequest(HF_Url, PostData, "utf-8");
                    JObject JS       = new JObject();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception)
                    {
                        JS = null;
                    }
                    if (JS != null)
                    {
                        if (JS["resp"] != null)
                        {
                            string resp = JS["resp"].ToString();
                            Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                            try
                            {
                                JS = (JObject)JsonConvert.DeserializeObject(Ret);
                            }
                            catch (Exception)
                            {
                                JS = null;
                            }
                            if (JS != null)
                            {
                                string respcode = JS["respcode"].ToString();
                                if (respcode == "00")
                                {
                                    string resultcode = JS["resultcode"].ToString();
                                    if (resultcode == "0000" || resultcode == "1002" || resultcode == "1004")
                                    {
                                        string queryid = JS["queryid"].ToString();
                                        FastOrder.Trade = queryid;
                                        Entity.SaveChanges();
                                        string txnamt    = JS["txnamt"].ToString();
                                        int    factmoney = int.Parse(txnamt);
                                        if (((int)(FastOrder.Amoney * 100)) == factmoney)
                                        {
                                            FastOrder = FastOrder.PaySuccess(Entity);
                                        }
                                    }
                                }
                                //================================================
                                //这里记录日志
                                PayLog PayLog = new PayLog();
                                PayLog.PId     = (int)FastOrder.PayWay;
                                PayLog.OId     = FastOrder.TNum;
                                PayLog.TId     = FastOrder.Trade;
                                PayLog.Amount  = FastOrder.Amoney;
                                PayLog.Way     = "Query";
                                PayLog.AddTime = DateTime.Now;
                                PayLog.Data    = Ret;
                                PayLog.State   = 1;
                                Entity.PayLog.AddObject(PayLog);
                                Entity.SaveChanges();
                                //================================================
                            }
                        }
                    }
                }
                #endregion
            }
            if (FastOrder.PayState == 1)
            {
                return("S");
            }
            if (FastOrder.State == 0)
            {
                return("E100");
            }
            return("G");
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[FastOrderQueryController]:", "【Data】" + Data, Ex);
                json = null;
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }

            FastOrder InFastOrder = new FastOrder();

            InFastOrder = JsonToObject.ConvertJsonToModel(InFastOrder, json);
            if (InFastOrder.TNum.IsNullOrEmpty() || InFastOrder.Token.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }

            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == InFastOrder.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }

            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == InFastOrder.TNum && n.UId == baseUsers.Id);

            if (FastOrder == null)
            {
                DataObj.OutError("1000");
                return;
            }
            if (FastOrder.State == 1 && FastOrder.PayState == 0)
            {
                FastPayWay FastPayWay = Entity.FastPayWay.FirstOrNew(n => n.Id == FastOrder.PayWay);
                if (FastPayWay == null)
                {
                    DataObj.OutError("2079");
                    return;
                }
                string[] PayConfigArr = FastPayWay.QueryArray.Split(new char[] { ',' });//接口信息
                if (FastPayWay.DllName == "HFPay")
                {
                    #region 结算中心
                    if (PayConfigArr.Length == 3)
                    {
                        string HF_Url     = "https://api.zhifujiekou.com/api/query";
                        string MerId      = PayConfigArr[0];
                        string MerKey     = PayConfigArr[1];
                        string orderId    = FastOrder.TNum;//商户流水号
                        string PostJson   = "{\"merid\":\"" + MerId + "\",\"orderid\":\"" + orderId + "\"}";
                        string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                        string Sign       = (DataBase64 + MerKey).GetMD5();
                        DataBase64 = HttpUtility.UrlEncode(DataBase64);
                        string  PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                        string  Ret      = Utils.PostRequest(HF_Url, PostData, "utf-8");
                        JObject JS       = new JObject();
                        try
                        {
                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                        }
                        catch (Exception)
                        {
                            JS = null;
                        }
                        if (JS != null)
                        {
                            if (JS["resp"] != null)
                            {
                                string resp = JS["resp"].ToString();
                                Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                                try
                                {
                                    JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                }
                                catch (Exception)
                                {
                                    JS = null;
                                }
                                if (JS != null)
                                {
                                    string respcode = JS["respcode"].ToString();
                                    if (respcode == "00")
                                    {
                                        string resultcode = JS["resultcode"].ToString();
                                        if (resultcode == "0000" || resultcode == "1002" || resultcode == "1004")
                                        {
                                            string queryid = JS["queryid"].ToString();
                                            FastOrder.Trade = queryid;
                                            Entity.SaveChanges();
                                            string txnamt    = JS["txnamt"].ToString();
                                            int    factmoney = int.Parse(txnamt);
                                            if (((int)(FastOrder.Amoney * 100)) == factmoney)
                                            {
                                                FastOrder = FastOrder.PaySuccess(Entity);
                                            }
                                        }
                                    }
                                    //================================================
                                    //这里记录日志
                                    PayLog PayLog = new PayLog();
                                    PayLog.PId     = (int)FastOrder.PayWay;
                                    PayLog.OId     = FastOrder.TNum;
                                    PayLog.TId     = FastOrder.Trade;
                                    PayLog.Amount  = FastOrder.Amoney;
                                    PayLog.Way     = "Query";
                                    PayLog.AddTime = DateTime.Now;
                                    PayLog.Data    = Ret;
                                    PayLog.State   = 1;
                                    Entity.PayLog.AddObject(PayLog);
                                    Entity.SaveChanges();
                                    //================================================
                                }
                            }
                        }
                    }
                    #endregion
                }
                if (FastPayWay.DllName == "HFJSPay")
                {
                    #region 结算中心
                    if (PayConfigArr.Length == 3)
                    {
                        FastUserPay          FastUserPay          = Entity.FastUserPay.FirstOrDefault(n => n.PayWay == FastOrder.PayWay && n.UId == baseUsers.Id && n.MerState == 1);
                        fastordersqueryModel fastordersqueryModel = new fastordersqueryModel()
                        {
                            merid   = FastUserPay.MerId,
                            orderid = "",
                            queryid = FastOrder.TNum
                        };
                        fastordersqueryResult fastordersqueryResult = HFJSTools.fastordersquery(fastordersqueryModel, FastUserPay.MerKey);
                        //================================================
                        //记录通知信息
                        PayLog PayLog = new PayLog();
                        PayLog.PId     = FastOrder.PayWay.Value;
                        PayLog.OId     = FastOrder.TNum;
                        PayLog.TId     = fastordersqueryResult.queryid;
                        PayLog.Amount  = FastOrder.Amoney;
                        PayLog.Way     = "Query";
                        PayLog.AddTime = DateTime.Now;
                        PayLog.Data    = HFJSTools.MyObjectToJson(fastordersqueryResult);
                        PayLog.State   = 1;
                        Entity.PayLog.AddObject(PayLog);
                        Entity.SaveChanges();
                        //================================================
                        if (fastordersqueryResult.respcode == "00")
                        {
                            if (fastordersqueryResult.resultcode == "0000" || fastordersqueryResult.resultcode == "1002")
                            {
                                FastOrder.Trade = fastordersqueryResult.queryid;
                                Entity.SaveChanges();
                                FastOrder = FastOrder.PaySuccess(Entity);
                                if (FastOrder.PayState == 1)
                                {
                                    if (fastordersqueryResult.resultcode == "0000")
                                    {
                                        FastOrder.UserState = 1;
                                    }
                                    if (fastordersqueryResult.resultcode == "1002")
                                    {
                                        FastOrder.UserState = 3;
                                    }
                                    FastOrder.UserTime = DateTime.Now;
                                    Entity.SaveChanges();
                                }
                            }
                            else if (fastordersqueryResult.resultcode == "1004")
                            {
                                FastOrder.State = 0;
                                Entity.SaveChanges();
                            }
                            else
                            {
                            }
                            Entity.SaveChanges();
                        }
                        else
                        {
                            string resp_desc = fastordersqueryResult.respmsg;
                            Utils.WriteLog("HFJS[Query][" + FastOrder.TNum + "]:" + resp_desc, "JobHFJS");
                        }
                    }
                    #endregion
                }
            }
            if (FastOrder.State == 1)
            {
                if (FastOrder.PayState == 1)
                {
                    if (FastOrder.UserState == 1)
                    {
                        FastOrder.State = 3;
                    }
                    else
                    {
                        FastOrder.State = 2;
                    }
                }
                else
                {
                    FastOrder.State = 1;
                }
            }
            else
            {
                FastOrder.State = 0;
            }
            FastOrder.Cols = "TNum,PayId,Amoney,Poundage,State";
            DataObj.Data   = FastOrder.OutJson();
            DataObj.Code   = "0000";
            DataObj.OutString();
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[IPayQuery]:", "【Data】" + Data, Ex);
                json = null;
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            Orders Orders = new Orders();

            Orders = JsonToObject.ConvertJsonToModel(Orders, json);
            if (Orders.TNum.IsNullOrEmpty() || Orders.Token.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            #region 处理用户信息
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == Orders.Token);
            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            #endregion
            Orders BaseOrders = Entity.Orders.FirstOrDefault(n => n.TNum == Orders.TNum);
            if (BaseOrders == null)
            {
                DataObj.OutError("1001");
                return;
            }
            if (baseUsers.Id != BaseOrders.UId)//禁止代付
            {
                DataObj.OutError("6021");
                return;
            }
            if (BaseOrders.TType != 6 && BaseOrders.TType != 10)
            {
                DataObj.OutError("6022");
                return;
            }
            if (BaseOrders.PayState != 1)
            {
                PayConfig PayConfig = Entity.PayConfig.FirstOrNew(n => n.Id == BaseOrders.PayWay);
                //开始处理参数
                string DataRet = "", Trade = "";
                if (PayConfig.DllName == "HFAliPay" || PayConfig.DllName == "HFWeiXin")
                {
                    #region 好付处理
                    string[] QueryArr = PayConfig.QueryArray.Split(',');
                    if (QueryArr.Length == 3)
                    {
                        //提交结算中心
                        string merId      = QueryArr[0];     //商户号
                        string merKey     = QueryArr[1];     //商户密钥
                        string orderId    = BaseOrders.TNum; //商户流水号
                        string PostJson   = "{\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\"}";
                        string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                        string Sign       = (DataBase64 + merKey).GetMD5();
                        DataBase64 = HttpUtility.UrlEncode(DataBase64);
                        string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                        string HF_Url   = "https://api.zhifujiekou.com/api/query";
                        DataRet = Utils.PostRequest(HF_Url, PostData, "utf-8");

                        JObject JS = new JObject();
                        try
                        {
                            JS = (JObject)JsonConvert.DeserializeObject(DataRet);
                        }
                        catch (Exception Ex)
                        {
                            Log.Write("[Order_HFQuery]:", "【PostData】" + PostData + "\n【DataRet】" + DataRet, Ex);
                            JS = null;
                        }
                        if (JS == null)
                        {
                            DataObj.OutError("1000");
                            return;
                        }
                        if (JS["resp"] == null)
                        {
                            Utils.WriteLog("【DataRet】" + DataRet, "OrderQC_HFQuery");
                            DataObj.OutError("1000");
                            return;
                        }
                        string resp = JS["resp"].ToString();
                        DataRet = LokFuEncode.Base64Decode(resp, "utf-8");
                        try
                        {
                            JS = (JObject)JsonConvert.DeserializeObject(DataRet);
                        }
                        catch (Exception Ex)
                        {
                            Log.Write("[Order_HFQuery]:", "【DataRet2】" + DataRet, Ex);
                            JS = null;
                        }
                        if (JS == null)
                        {
                            DataObj.OutError("1000");
                            return;
                        }
                        string respcode = JS["respcode"].ToString();
                        if (respcode != "00")
                        {
                            string respmsg = JS["respmsg"].ToString();
                            DataObj.OutError("1000");
                            Utils.WriteLog("[Order_HFQuery_Err]:【" + respcode + "】" + respmsg, "orderface");
                            return;
                        }
                        string resultcode = JS["resultcode"].ToString();
                        string queryid    = JS["queryid"].ToString();
                        if (resultcode == "0000" || resultcode == "1002" || resultcode == "1004")
                        {
                            string txnamt    = JS["txnamt"].ToString();
                            int    factmoney = int.Parse(txnamt);
                            if (((int)(BaseOrders.Amoney * 100)) == factmoney)
                            {
                                BaseOrders = BaseOrders.PaySuccess(Entity);
                            }
                        }
                    }
                    #endregion
                }
                //================================================
                //这里记录日志
                PayLog PayLog = new PayLog();
                PayLog.PId     = BaseOrders.PayWay;
                PayLog.OId     = BaseOrders.TNum;
                PayLog.TId     = Trade;
                PayLog.Amount  = BaseOrders.Amoney;
                PayLog.Way     = "GET";
                PayLog.AddTime = DateTime.Now;
                PayLog.Data    = DataRet;
                PayLog.State   = 1;
                Entity.PayLog.AddObject(PayLog);
                Entity.SaveChanges();
                //================================================
            }
            BaseOrders.Cols = "TNum,Amount,PayState";
            DataObj.Data    = BaseOrders.OutJson();
            DataObj.Code    = "0000";
            DataObj.OutString();
        }