Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }