public void Stop()
        {
            LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Stop");
            Stream       inputStream = Request.GetBufferedInputStream();
            StopRealTime real        = RealTimeAnalysis.analysisStop(inputStream);

            if (RealTimeThread.dic.ContainsKey(real.TerminalId))
            {
                CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo;
                if (info != null)
                {
                    info.Power       = int.Parse(real.Power);
                    info.Voltage     = int.Parse(real.Voltage);
                    info.Current     = int.Parse(real.Current);
                    info.Temperature = int.Parse(real.Temperature);
                    RealTimeThread.dic[real.TerminalId] = info;
                }
            }
            else
            {
                CarInfo c = new CarInfo();
                c.Power       = int.Parse(real.Power);
                c.Voltage     = int.Parse(real.Voltage);
                c.Current     = int.Parse(real.Current);
                c.Temperature = int.Parse(real.Temperature);
                RealTimeThread.dic.Add(real.TerminalId, c);
            }

            if (real != null)
            {
                orderbll.uploadStopRealTime(real);
            }
        }
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            string log = this.ToLog4Start();

            base.OnAuthorization(filterContext);
            LogerHelper.DefaultInfo(log);
        }
 //1.add priviledges according to types
 //2.add to db and local memory
 public void addPrivilege(UserLogin bases)
 {
     //  DbTransaction tran = null;
     // DbConnection conn = null;
     //Privileges pri = null;
     try
     {
         if (bases != null)
         {//普通用户
          //if (Commons.NORMAL_USER.Equals(bases))
          //{
          //    pri = new Privileges() { ID = Guid.NewGuid(), UserId = bases.ID, Privilege = Common.Commons.NORMAL_USER };
          //    HashOperator.getInstance().Set<Privileges>("Privileges", bases.ID, pri);
          //    MsgQueueManager.SendPriMessage(pri);
          //}
             ////公司用户
             //else if (Common.Commons.COMPANY_USER.Equals(Convert.ToInt32(bases)))
             //{
             //    pri = new Privileges() { ID = System.Guid.NewGuid(), UserId = bases.ID, Privilege = Common.Commons.COMPANY_USER };
             //    HashOperator.getInstance().Set<Privileges>("Privileges", bases.ID, pri);
             //    MsgQueueManager.SendPriMessage(pri);
             //}
             //else
             //{
             //    //其他用户
             //}
         }
     }
     catch (Exception ex)
     {
         LogerHelper.DefaultInfo(ex.Source + ":" + ex.ToString());
     }
 }
        public void Authorization()
        {
            try
            {
                LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 收到终端授权请求");
                Stream inputStream        = Request.GetBufferedInputStream();
                Stream outputStream       = Response.OutputStream;
                AuthorizationRequest real = RealTimeAnalysis.analysisAuthorizationReq(inputStream);
                if (RealTimeThread.dic.ContainsKey(real.TerminalId))
                {
                    CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo;
                    if (info == null)
                    {
                        info.Power       = int.Parse(real.Power);
                        info.Voltage     = int.Parse(real.Voltage);
                        info.Current     = int.Parse(real.Current);
                        info.Temperature = int.Parse(real.Temperature);
                        RealTimeThread.dic[real.TerminalId] = info;
                    }
                }
                else
                {
                    CarInfo c = new CarInfo();
                    c.Power       = int.Parse(real.Power);
                    c.Voltage     = int.Parse(real.Voltage);
                    c.Current     = int.Parse(real.Current);
                    c.Temperature = int.Parse(real.Temperature);
                    RealTimeThread.dic.Add(real.TerminalId, c);
                }

                if (real != null)
                {
                    byte[] outs = orderbll.uploadAuthorization(real);
                    Thread.Sleep(1000);
                    if (outs != null)
                    {
                        outputStream.WriteByte(0xd3);
                        outputStream.WriteByte(0xd3);
                        outputStream.Write(outs, 0, outs.Length);
                        LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 下发终端授权响应" + ByteUtils.byteToHexStr(outs));
                        //修改订单状态为已使用
                        outputStream.Flush();
                    }
                }
                outputStream.Close();
                inputStream.Close();
            }catch (Exception e) {
                LogerHelper.exception("error occured!", e);
            }
        }
        public ActionResult PayNotifyUrl()
        {
            try
            {
                string[] strs   = Request.RawUrl.ToString().Split("/".ToCharArray());
                string   userID = strs[strs.Length - 1];
                LogerHelper.DefaultInfo(strs[strs.Length - 1]);
                NotifyHandler resHandler = new NotifyHandler(Request.InputStream);
                Hashtable     table      = resHandler.Parameters;
                ArrayList     akeys      = new ArrayList(table.Keys);
                akeys.Sort();
                foreach (string k in akeys)
                {
                    string v = (string)table[k];
                    LogerHelper.DefaultInfo(v);
                }
                string openid       = resHandler.GetParameter("openid");
                string total_fee    = resHandler.GetParameter("total_fee");
                string out_trade_no = resHandler.GetParameter("out_trade_no");
                LogerHelper.DefaultInfo("total_fee:    " + total_fee);
                LogerHelper.DefaultInfo("out_trade_no:    " + out_trade_no);
                resHandler.SetKey(Mch_Id);
                //验证请求是否从微信发过来(安全)
                //  if (resHandler.IsTenpaySign())
                // {
                //正确的订单处理
                LogerHelper.DefaultInfo("nofify     ok");
                //此处userid是回调url最后一个参数
                if (paymentbll.chargePayment(userID, Convert.ToInt32(total_fee), out_trade_no, (int)Commons.PayType.RECHARGE))
                {
                    LogerHelper.debug("微信支付成功!");
                }
                // WebHelper.Post(LocalContext.platformUrl + "/Pay/Recharge", "UserID=" + (Common.GlobalMap[openid] as UserInformation).userid + "Amount=" + total_fee + "PayOrderID=" + out_trade_no + "Type=1");
                //  }
                // else
                // {
                //错误的订单处理
                // LogerHelper.DefaultInfo("nofify     no");
                //  }
            }
            catch (Exception ex)
            {
                LogerHelper.DefaultInfo("ex:    " + ex.ToString());
            }

            return(Content("success"));
        }
Exemple #6
0
        public Order SelectOrder(string userId, string orderId)
        {
            LogerHelper.DefaultInfo(string.Format("SelectOrder:{0}---{1}", userId, orderId));
            if (!String.IsNullOrWhiteSpace(userId) && !String.IsNullOrWhiteSpace(orderId))
            {
                using (DataContext db = new SqlserverContext())
                {
                    Table <Order> T_Order = db.GetTable <Order>();
                    //Order orders = (from c in T_Order where c.UserID == userId && c.ID == orderId select c) as Order;
                    Order orders = T_Order.FirstOrDefault <Order>(x => x.UserID.Equals(userId) && x.ID.Equals(orderId));
                    if (orders != null)
                    {
                        LogerHelper.DefaultInfo(string.Format("SelectOrder11:{0}", orders.ID));
                        return(orders);
                    }
                }
            }

            return(null);
        }
        public CarStat addCarStat(OrderLog order)
        {
            LogerHelper.DefaultInfo("addCarStat:" + order.OrderID);
            //增加车状态
            using (DataContext db = new SqlserverContext())
            {
                Table <CarStat> T_PILE = db.GetTable <CarStat>();
                CarStat         stat   = new CarStat();

                CarStat c = (from m in T_PILE where m.CarID == order.CarID select m).FirstOrDefault();
                stat.id         = Guid.NewGuid().ToString().Replace("-", "");
                stat.stat       = (int)Commons.CatStatus.idle;
                stat.UserID     = order.UserID;
                stat.CarID      = order.CarID;
                stat.PilesID    = c.PilesID;
                stat.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                T_PILE.InsertOnSubmit(stat);
                db.SubmitChanges();
                LogerHelper.debug("还车 Add CarStat 成功!");
                return(stat);
            }
        }
        // GET: /Pay/
        /**充值或消费或付款**/
        //IOS侧微信支付回调
        //192.168.0.5:8787/Pay/Recharge
        public ActionResult Charge(string UserID, int?Amount, string PayOrderID, int?Type)
        {
            string response = Request.Params.ToString();

            LogerHelper.DefaultInfo("微信回调");
            LogerHelper.DefaultInfo(response);
            string rrr = Request.Form.ToString();

            LogerHelper.DefaultInfo("POST:" + rrr);
            if (paymentbll.chargePayment(UserID, Amount, PayOrderID, Type))
            {
                LogerHelper.debug("微信支付成功!");
            }
            return(Content("cccc"));

            //if (!String.IsNullOrWhiteSpace(UserID) && !String.IsNullOrWhiteSpace(UserID)
            //    &&!String.IsNullOrWhiteSpace(UserID) && !String.IsNullOrWhiteSpace(UserID))
            //{

            //}
            //return null;
        }
        public void Run()
        {
            LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " RUN");
            Stream      inputStream = Request.GetBufferedInputStream();
            RunRealTime real        = RealTimeAnalysis.analysisRun(inputStream);

            real.sampleTime = string.Format("{0:yyyyMMddHHmmssfff}", DateTime.Now);
            if (RealTimeThread.dic.ContainsKey(real.TerminalId))
            {
                CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo;
                if (info != null)
                {
                    info.Power     = real.batteryInfo;
                    info.Voltage   = real.voltage;
                    info.Speed     = real.speed;
                    info.Mile      = real.mile;
                    info.Longitude = real.longitude;
                    info.Latitude  = real.latitude;
                    RealTimeThread.dic[real.TerminalId] = info;
                }
            }
            else
            {
                CarInfo c = new CarInfo();
                c.Power     = real.batteryInfo;
                c.Voltage   = real.voltage;
                c.Speed     = real.speed;
                c.Mile      = real.mile;
                c.Longitude = real.longitude;
                c.Latitude  = real.latitude;
                RealTimeThread.dic.Add(real.TerminalId, c);
            }

            if (real != null)
            {
                orderbll.uploadRunRealTime(real);
            }
        }
 public void OpenCloseGate()
 {
     LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 收到终端开门请求");
     try
     {
         Stream inputStream = Request.GetBufferedInputStream();
         //byte[] src = new byte[42];
         //int offset = 0;
         //int result = 0;
         //int cnt = 0;
         //while ((result = inputStream.ReadByte()) != -1)
         //{
         //    cnt++;
         //    src[offset] = (byte)result;
         //    offset++;
         //}
         // LogerHelper.debug("平台收到数据:"+ByteUtils.byteToHexStr(src));
         OpenOrCloseGateRequest opens = RealTimeAnalysis.openOrCloseGate(inputStream);
         opens.CreateTime = DateTime.Now;
         orderbll.uploadOpenOrCloseGate(opens);
     }catch (Exception e) {
         LogHelper.Exception(this.Url.RequestContext, e);
     }
 }
Exemple #11
0
 //出参方法
 public static void OutPut(System.Web.Routing.RequestContext requestContext, object obj)
 {
     LogerHelper.DefaultInfo(string.Format("输出:{0}/{1}  {2}", requestContext.RouteData.Values["controller"], requestContext.RouteData.Values["action"], "", ObjectToJson(obj)));
 }
        public ActionResult AppConsume(string txnAmt, string orderDesc)
        {
            LogerHelper.DefaultInfo(Request.ToString());
            Dictionary <string, string> param = new Dictionary <string, string>();
            // 随机构造一个订单号(演示用)
            Random rnd     = new Random();
            string orderID = DateTime.Now.ToString("yyyyMMddHHmmss") + (rnd.Next(900) + 100).ToString().Trim();

            //填写参数

            param["version"]      = "5.0.0";                                                 //版本号
            param["encoding"]     = "UTF-8";                                                 //编码方式
            param["certId"]       = CertUtil.GetSignCertId();                                //证书ID
            param["txnType"]      = "01";                                                    //交易类型
            param["txnSubType"]   = "01";                                                    //交易子类
            param["bizType"]      = "000201";                                                //业务类型
            param["frontUrl"]     = "http://localhost:8080/demo/utf8/FrontRcvResponse.aspx"; //前台通知地址 ,控件接入方式无作用
            param["backUrl"]      = "http://weixin.mandelaauto.com/Pay/CupComplete";         //后台通知地址
            param["signMethod"]   = "01";                                                    //签名方法
            param["channelType"]  = "08";                                                    //渠道类型,07-PC,08-手机
            param["accessType"]   = "0";                                                     //接入类型
            param["merId"]        = Properties.getHost();                                    //商户号,请改成自己的商户号
            param["orderId"]      = orderID;                                                 //商户订单号
            param["txnTime"]      = DateTime.Now.ToString("yyyyMMddHHmmss");                 //订单发送时间
            param["txnAmt"]       = txnAmt;                                                  //交易金额,单位分
            param["currencyCode"] = "156";                                                   //交易币种
            param["orderDesc"]    = orderDesc;                                               //订单描述,可不上送,上送时控件中会显示该信息
            param["reqReserved"]  = "透传信息";                                                  //请求方保留域,透传字段,查询、通知、对账文件中均会原样出现
            SDKUtil.Sign(param, Encoding.UTF8);                                              // 签名
            Response.Write("\n" + "请求报文=[" + SDKUtil.PrintDictionaryToString(param) + "]\n");

            // 初始化通信处理类
            HttpClient hc = new HttpClient(SDKConfig.AppRequestUrl);
            //// 发送请求获取通信应答
            int status = hc.Send(param, Encoding.UTF8);
            // 返回结果
            string result = hc.Result;

            if (status == 200)
            {
                Response.Write("返回报文=[" + result + "]\n");
                LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + result);
                Dictionary <string, string> resData = SDKUtil.CoverstringToDictionary(result);
                foreach (var x in resData.Keys)
                {
                    LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + x);
                }
                string respcode = resData["respCode"];
                if (SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    Response.Write("商户端验证返回报文签名成功\n");
                }
                else
                {
                    Response.Write("商户端验证返回报文签名失败\n");
                }
            }
            else
            {
                Response.Write("请求失败\n");
                Response.Write("返回报文=[" + result + "]\n");
            }
            return(Content("success"));
        }
        //银联支付结果回调接口
        public ActionResult CupComplete(Cup cup)
        {
            LogerHelper.DefaultInfo(Request.ToString());
            if (Request.HttpMethod == "POST")
            {
                // 使用Dictionary保存参数
                Dictionary <string, string> resData = new Dictionary <string, string>();

                NameValueCollection coll = Request.Form;

                string[] requestItem = coll.AllKeys;

                for (int i = 0; i < requestItem.Length; i++)
                {
                    resData.Add(requestItem[i], Request.Form[requestItem[i]]);
                }
                // 返回报文中不包含UPOG,表示Server端正确接收交易请求,则需要验证Server端返回报文的签名
                if (SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    cup.accNo            = resData["accNo"];
                    cup.bindId           = resData["bindId"];
                    cup.bizType          = resData["bizType"];
                    cup.cupParams        = coll.ToString();
                    cup.id               = resData["id"];
                    cup.merId            = resData["merId"];
                    cup.orderId          = resData["orderId"];
                    cup.payCardIssueName = resData["payCardIssueName"];
                    cup.payCardNo        = resData["payCardNo"];
                    cup.payCardType      = resData["payCardType"];
                    cup.payType          = resData["payType"];
                    cup.queryId          = resData["queryId"];
                    cup.respCode         = resData["respCode"];
                    cup.respMsg          = resData["respMsg"];
                    cup.settleAmt        = Convert.ToInt32(resData["settleAmt"]);
                    cup.settleDate       = resData["settleDate"];
                    cup.txnAmt           = Convert.ToInt32(resData["txnAmt"]);
                    cup.txnTime          = resData["txnTime"];
                    cup.txnType          = resData["txnType"];
                    string respcode = resData["respCode"];
                    //Response.Write("商户端验证返回报文签名成功\n");

                    //商户端根据返回报文内容处理自己的业务逻辑 ,DEMO此处只输出报文结果
                    //StringBuilder builder = new StringBuilder();

                    //builder.Append("<tr><td align=\"center\" colspan=\"2\"><b>商户端接收银联返回报文并按照表格形式输出结果</b></td></tr>");

                    //for (int i = 0; i < requestItem.Length; i++)
                    //{
                    //    builder.Append("<tr><td width=\"30%\" align=\"right\">" + requestItem[i] + "</td><td style='word-break:break-all'>" + Request.Form[requestItem[i]] + "</td></tr>");
                    //}

                    //builder.Append("<tr><td width=\"30%\" align=\"right\">商户端验证银联返回报文结果</td><td>验证签名成功.</td></tr>");
                    //Response.Write(builder.ToString());
                    cup.cupParams = coll.ToString();
                    cup.id        = Guid.NewGuid().ToString().Replace("-", "");
                    if (paymentbll.cupPayment(cup))
                    {
                        LogerHelper.debug("银联支付成功");
                        return(Content("success"));
                    }
                }
                else
                {
                    LogerHelper.debug("银联支付失败");
                    // Response.Write("<tr><td width=\"30%\" align=\"right\">商户端验证银联返回报文结果</td><td>验证签名失败.</td></tr>");
                }
            }
            return(Content("fail"));
        }
        public ActionResult AlipayComplete()
        {
            LogerHelper.DefaultInfo("支付宝回调");
            //SortedDictionary<string, string> sPara = GetRequestPost();
            //LogerHelper.DefaultInfo("" + sPara.Count());
            //if (sPara.Count > 0)//判断是否有带返回参数
            //{
            //    Notify aliNotify = new Notify();
            //    bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);
            //    LogerHelper.DefaultInfo(""+verifyResult);
            //    if (verifyResult)//验证成功
            //    {
            //        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //        //请在这里加上商户的业务逻辑程序代码


            //        //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
            //        //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

            //        //商户订单号

            //        string out_trade_no = Request.Form["out_trade_no"];

            //        //支付宝交易号

            //        string trade_no = Request.Form["trade_no"];

            //        //交易状态
            //        string trade_status = Request.Form["trade_status"];


            //        if (Request.Form["trade_status"] == "TRADE_FINISHED")
            //        {
            //            LogerHelper.DefaultInfo("TRADE_FINISHED");
            //            //判断该笔订单是否在商户网站中已经做过处理
            //            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
            //            //如果有做过处理,不执行商户的业务程序

            //            //注意:
            //            //该种交易状态只在两种情况下出现
            //            //1、开通了普通即时到账,买家付款成功后。
            //            //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。
            //        }
            //        else if (Request.Form["trade_status"] == "TRADE_SUCCESS")
            //        {
            //            LogerHelper.DefaultInfo("TRADE_SUCCESS");
            //            //判断该笔订单是否在商户网站中已经做过处理
            //            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
            //            //如果有做过处理,不执行商户的业务程序

            //            //注意:
            //            //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。
            //        }
            //        else
            //        {
            //        }

            //        //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

            //        Response.Write("success");  //请不要修改或删除

            //        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //    }
            //    else//验证失败
            //    {
            //        Response.Write("fail");
            //    }
            //}
            //else
            //{
            //    Response.Write("无通知参数");
            //}
            return(Content("success"));
        }