Example #1
0
        /// <summary>取消授权</summary>
        /// <param name="memberId"></param>
        public static KeyFreeResult CancelEquipmentAuthorization(string memberId)
        {
            var r = new KeyFreeResult();

            r.result     = 500;
            r.resultInfo = "-1";
            for (int i = 0; i < 5; i++)
            {
                if (!(r.result == 200 || r.result == 201))
                {
                    try
                    {
                        var url  = string.Format("{0}/api/auth/cancelGrant", Host);
                        var dict = new Dictionary <string, string>();
                        var json = string.Format("{{\"deviceCode\":\"\",\"deviceGroupNo\":\"{0}\",\"memberId\":{1},\"ruleId\":{2}}}", DeviceGroupNo, memberId, RuleId);
                        dict.Add("data", json);
                        dict.Add("accessToken", AccesToken);
                        r = JsonConvert.DeserializeObject <KeyFreeResult>(HttpHelper.Post(url, dict));
                        break;
                    }
                    catch (Exception ex)
                    {
                        r.result     = 500;
                        r.resultInfo = "-1";
                        r.data       = ex.Message;
                    }
                }
            }
            return(r);
        }
Example #2
0
        /// <summary>远程开门</summary>
        /// <param name="mac"></param>
        public static KeyFreeResult OpenDoor(string mac)
        {
            var r = new KeyFreeResult();

            r.result     = 500;
            r.resultInfo = "-1";
            for (int i = 0; i < 5; i++)
            {
                if (!(r.result == 200 || r.result == 201))
                {
                    try
                    {
                        var url  = string.Format("{0}/api/remote/openDoor", Host);
                        var dict = new Dictionary <string, string>();
                        var json = string.Format("{{\"cmpId\":{0},\"proId\":{1},\"mac\":\"{2}\"}}", CmpId, ProId, mac);
                        dict.Add("data", json);
                        dict.Add("accessToken", AccesToken);
                        r = JsonConvert.DeserializeObject <KeyFreeResult>(HttpHelper.Post(url, dict));
                        break;
                    }
                    catch (Exception ex)
                    {
                        r.result     = 500;
                        r.resultInfo = "-1";
                        r.data       = ex.Message;
                    }
                }
            }
            return(r);
        }
Example #3
0
        /// <summary>人员设备授权</summary>
        /// <param name="phone"></param>
        /// <param name="mac"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        public static KeyFreeResult EquipmentAuthorization(string memberId, DateTime startTime)
        {
            var r = new KeyFreeResult();

            r.result     = 500;
            r.resultInfo = "-1";
            for (int i = 0; i < 5; i++)
            {
                if (!(r.result == 200 || r.result == 201))
                {
                    var url  = string.Format("{0}/api/auth/grant", Host);
                    var dict = new Dictionary <string, string>();
                    var json = string.Format("{{\"deviceCode\":\"\",\"deviceGroupNo\":\"{0}\",\"memberId\":{1},\"ruleId\":{2},\"startDate\":\"{3}\",\"endDate\":\"{4}\"}}", DeviceGroupNo, memberId, RuleId, startTime.ToString("yyyy-MM-dd HH:mm"), startTime.AddYears(10).ToString("yyyy-MM-dd HH:mm"));
                    dict.Add("data", json);
                    dict.Add("accessToken", AccesToken);
                    try
                    {
                        r = JsonConvert.DeserializeObject <KeyFreeResult>(HttpHelper.Post(url, dict));
                        Logger.LogToDb(string.Format("门禁系统:授权成功。Result:{0},JsonData:{1}", JsonConvert.SerializeObject(r), json));
                        break;
                    }
                    catch (Exception ex)
                    {
                        r.result     = 500;
                        r.resultInfo = "-1";
                        r.data       = ex.Message;
                        Logger.LogToDb(string.Format("门禁系统:授权失败。Result:{0},JsonData:{1}", ex.Message, json));
                    }
                }
            }
            return(r);
        }
Example #4
0
        /// <summary>查询设备开启记录</summary>
        /// <param name="phone">手机号码  必</param>
        /// <param name="mac">设备mac 选</param>
        /// <param name="startTime">必</param>
        /// <param name="endTime">必</param>
        public static KeyFreeResult QueryEquipmentOpenHistory(string phone, DateTime startTime, DateTime endTime)
        {
            var r = new KeyFreeResult();

            r.result     = 500;
            r.resultInfo = "-1";
            for (int i = 0; i < 5; i++)
            {
                if (!(r.result == 200 || r.result == 201))
                {
                    try
                    {
                        var url  = string.Format("{0}/api/openHistory/query", Host);
                        var dict = new Dictionary <string, string>();
                        var json = string.Format("{{\"cmpId\":{0},\"proId\":{1},\"phone\":\"{2}\",\"mac\":\"{3}\",\"startTime\":\"{4}\",\"endTime\":\"{5}\"}}", CmpId, ProId, phone, "", startTime.ToString("yyyy-MM-dd HH:mm:ss"), endTime.ToString("yyyy-MM-dd HH:mm:ss"));
                        dict.Add("data", json);
                        dict.Add("accessToken", AccesToken);
                        r = JsonConvert.DeserializeObject <KeyFreeResult>(HttpHelper.Post(url, dict));
                        break;
                    }
                    catch (Exception e)
                    {
                        r.result     = 500;
                        r.resultInfo = "-1";
                        r.data       = e.Message;
                    }
                }
            }
            return(r);
        }
Example #5
0
        /// <summary>获取用户信息(输出json字符串,未反,需要时再做)</summary>
        /// <param name="phone">KeyFree中的用户联系电话(Phone字段)</param>
        public static KeyFreeResult QueryByPhone(string phone)
        {
            var r = new KeyFreeResult();

            r.result     = 500;
            r.resultInfo = "-1";
            for (int i = 0; i < 5; i++)
            {
                if (!(r.result == 200 || r.result == 201))
                {
                    try
                    {
                        var url  = string.Format("{0}/api/member/queryByPhone", Host);
                        var dict = new Dictionary <string, string>();
                        var user = new KeyFreeUser();
                        user.phone = phone;
                        user.proId = ProId;
                        user.cmpId = CmpId;
                        dict.Add("data", JsonConvert.SerializeObject(user));
                        dict.Add("accessToken", AccesToken);
                        r = JsonConvert.DeserializeObject <KeyFreeResult>(HttpHelper.Post(url, dict));
                        break;
                    }
                    catch
                    {
                        r.result     = 500;
                        r.resultInfo = "-1";
                    }
                }
            }
            return(r);
        }
Example #6
0
        /// <summary>修改人员</summary>
        /// <param name="memberId">人员id,必填</param>
        /// <param name="realname">真实姓名,必填</param>
        /// <param name="gender">性别,(男是0,女是1),选填</param>
        /// <param name="address">地址,选填</param>
        /// <param name="floor">楼层,选填</param>
        /// <param name="disabled">是否停用,(false为不停用,true为停用),选填</param>
        /// <param name="visitor">是否受访,(flase为不受访,true为受访),选填</param>
        /// <param name="groupIds">人员组id数组,选填</param>
        /// <param name="roleIds">角色id数组,选填</param>
        public static KeyFreeResult UpdateById(string memberId, string realname, int gender = -1, string address = "", int floor = -1, bool disabled = false, bool visitor = false, int[] groupIds = null, int[] roleIds = null)
        {
            var r = new KeyFreeResult();

            r.result     = 500;
            r.resultInfo = "-1";
            for (int i = 0; i < 5; i++)
            {
                if (!(r.result == 200 || r.result == 201))
                {
                    try
                    {
                        var url  = string.Format("{0}/api/member/updateById", Host);
                        var user = new KeyFreeUser();
                        user.memberId = int.Parse(memberId);
                        user.cmpId    = CmpId;
                        user.deptId   = DeptId;
                        user.proId    = ProId;
                        user.realname = realname;
                        user.address  = address;
                        user.disabled = disabled;
                        user.visitor  = visitor;
                        user.groupIds = groupIds;
                        user.roleIds  = roleIds;
                        if (gender != -1)
                        {
                            user.gender = gender;
                        }
                        if (floor != -1)
                        {
                            user.floor = floor;
                        }
                        var dict = new Dictionary <string, string>();
                        dict.Add("data", JsonConvert.SerializeObject(user));
                        dict.Add("accessToken", AccesToken);
                        r = JsonConvert.DeserializeObject <KeyFreeResult>(HttpHelper.Post(url, dict));
                        break;
                    }
                    catch
                    {
                        r.result     = 500;
                        r.resultInfo = "-1";
                    }
                }
            }
            return(r);
        }
Example #7
0
        //------------------------------------------------------------------------
        // KeyFree Api调用
        //------------------------------------------------------------------------
        /// <summary>注册人员Api</summary>
        /// <param name="phone">手机号码</param>
        /// <param name="realName">真实姓名</param>
        /// <param name="gender">性别, 0:男, 1:女</param>
        public static KeyFreeResult Register(string phone, string realName, int gender)
        {
            var r = new KeyFreeResult();

            r.result     = 500;
            r.resultInfo = "-1";
            for (int i = 0; i < 5; i++)
            {
                if (!(r.result == 200 || r.result == 201))
                {
                    var url  = string.Format("{0}/api/member/register", Host);
                    var user = new KeyFreeUser();
                    user.cmpId    = CmpId;
                    user.deptId   = DeptId;
                    user.proId    = ProId;
                    user.phone    = phone;
                    user.realName = phone;//realName不用了 直接传phone
                    user.gender   = gender;
                    var dict = new Dictionary <string, string>();
                    dict.Add("data", JsonConvert.SerializeObject(user));
                    dict.Add("accessToken", AccesToken);
                    try
                    {
                        r = JsonConvert.DeserializeObject <KeyFreeResult>(HttpHelper.Post(url, dict));
                        Logger.LogToDb(string.Format("门禁系统:注册成功。Result:{0},JsonData:{1}", JsonConvert.SerializeObject(r), JsonConvert.SerializeObject(user)));
                        break;
                    }
                    catch (Exception e)
                    {
                        Logger.LogToDb(string.Format("门禁系统:注册失败。Message:{0},JsonData:{1}", e.Message, JsonConvert.SerializeObject(user)));
                        r.result     = 500;
                        r.resultInfo = "-1";
                    }
                }
            }
            return(r);
        }