예제 #1
0
        /// <summary>
        /// 锁车指令
        /// </summary>
        /// <param name="vehicleid"></param>
        /// <returns></returns>
        public bool Close(string vehicleid)
        {
            try
            {
                bool           result     = false;
                VehicleManager vm         = new VehicleManager();
                Hashtable      vehicle_ht = vm.GetVehicleInfoByID(vehicleid);

                Dictionary <string, string> dict = new Dictionary <string, string>();
                dict.Add("carId", SiteHelper.GetHashTableValueByKey(vehicle_ht, "VehicleGPSNum"));
                dict.Add("cmd", "doorControl");
                dict.Add("type ", "8");
                dict.Add("directRt", "true");

                string sign = ZCloudSignUtil.getSign(dict, ZCloudConfig.md5_key);
                dict.Add("sign", sign);

                string  postData = ZCloudCore.createLinkString(dict);
                string  retstr   = HttpUtil.Post(ZCloudConfig.api_url, postData, "utf-8");
                dynamic retObj   = DynamicJson.Parse(retstr);
                if (retObj.sysCode == "suc" && retObj.rtCode == "0")
                {
                    result = true;
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.CacheControl = "no-cache";
            context.Response.AddHeader("Pragma", "no-cache");
            context.Response.ContentType = "text/plain";

            Hashtable clientData = new Hashtable();
            string    cmd        = null;

            try
            {
                if (context.Request.HttpMethod.ToLower() != "post")
                {
                    throw new Exception("调用方式错误");
                }

                clientData = GetRequestData(context);
                if (clientData != null && clientData.Keys.Count > 0)
                {
                    if (!ZCloudSignUtil.verify(ZCloudCore.hashtableToDictionary(clientData), ZCloudConfig.md5_key))
                    {
                        throw new Exception("验签失败");
                    }

                    if (clientData["cmd"] != null)
                    {
                        cmd = clientData["cmd"].ToString();
                    }
                    if (string.IsNullOrEmpty(cmd))
                    {
                        throw new Exception("收到网关发来的通知,但是没有找到命令字");
                    }
                    Assembly   assembly = Assembly.GetExecutingAssembly();
                    string     typeName = cmd.Substring(0, 1).ToUpper() + cmd.Substring(1, cmd.Length - 1) + "Action";
                    object     obj      = assembly.CreateInstance("YR.Web.api.zcloud.service." + typeName);
                    IApiAction action   = (IApiAction)obj;
                    //if (action == null)
                    //    return;

                    //调用相对应的接口方法
                    ApiResp result = action.Execute(clientData);

                    if (!Not_Response_Cmd.Contains(cmd))
                    {
                        Hashtable result_ht = new Hashtable();
                        result_ht.Add("rtCode", "0");
                        string sign = ZCloudSignUtil.getSign(ZCloudCore.hashtableToDictionary(result_ht), ZCloudConfig.md5_key);
                        result_ht.Add("sign", sign);
                        context.Response.Write(JsonConvert.SerializeObject(result_ht));
                    }
                    Logger.Info("自由box接口网关上报数据(成功),访问ip:" + context.Request.UserHostAddress + ",参数:" + JsonConvert.SerializeObject(clientData) + ",返回值:" + result);
                }
                else
                {
                    throw new Exception("请求参数为空");
                }
            }
            catch (Exception e)
            {
                if (!Not_Response_Cmd.Contains(cmd))
                {
                    Hashtable result_ht = new Hashtable();
                    result_ht.Add("rtCode", "1");
                    string sign = ZCloudSignUtil.getSign(ZCloudCore.hashtableToDictionary(result_ht), ZCloudConfig.md5_key);
                    result_ht.Add("sign", sign);
                    context.Response.Write(JsonConvert.SerializeObject(result_ht));
                }
                Logger.Error("自由box接口网关上报数据(失败),访问ip:" + context.Request.UserHostAddress + ",参数:" + JsonConvert.SerializeObject(clientData) + ",异常:" + e.Message);
            }
        }