Beispiel #1
0
        /// <summary>
        /// 读取门禁钥匙
        /// </summary>
        private string LoadKeyDoor(DataRow row)
        {
            if (!row.Table.Columns.Contains("CommunityId") || string.IsNullOrEmpty(row["CommunityId"].ToString()))
            {
                return(JSONHelper.FromString(false, "小区编号不能为空"));
            }
            if (!row.Table.Columns.Contains("UserId") || string.IsNullOrEmpty(row["UserId"].ToString()))
            {
                return(JSONHelper.FromString(false, "用户编号不能为空"));
            }

            string communityId = row["CommunityId"].AsString();
            string userId      = row["UserId"].AsString();

            //查询小区
            Tb_Community Community = new MobileSoft.BLL.Unified.Bll_Tb_Community().GetModel(communityId);

            //构造链接字符串
            if (Community == null)
            {
                return(JSONHelper.FromString(false, "该小区不存在"));
            }

            if (string.IsNullOrEmpty(Community.ModuleRights) || Community.ModuleRights == "否")
            {
                return(JSONHelper.FromString(false, "该小区暂未开通门禁功能"));
            }

            string strcon = GetConnectionStringStr(Community);
            string mobile = null;

            // 读取用户手机号
            using (IDbConnection conn = new SqlConnection(PubConstant.UnifiedContionString))
            {
                mobile = conn.Query(@"SELECT Mobile FROM Tb_User WHERE Id=@UserID", new { UserID = userId }).FirstOrDefault();
            }

            string productKey    = "0f4a878bc9f1d8e900dad0ccba569225";
            string productSecret = "21734b3545b48672991305f64fd2e56abd612b6b";
            string baseUrl       = "https://api-iot.tslsmart.com/";
            string token         = AppGlobal.getMd5Hash(productKey + productSecret).ToLower();

            string parameter = string.Format("mobile={0}&token={1}{2}", mobile, token, productKey).ToLower();
            string signData  = AppGlobal.getMd5Hash(parameter).ToLower();

            string accessTokenUrl = string.Format(@"{0}OpenApi/User/Login?{1}&SignData={2}&ProductKey={3}", baseUrl, parameter, signData, productKey);

            string  data = SendHttp(accessTokenUrl, "GET", null);
            dynamic obj  = JsonConvert.DeserializeObject <dynamic>(data);

            if (obj.ErrorCode != 0)
            {
                return(JSONHelper.FromString(false, "您暂未有门禁授权"));
            }

            // 当前用户的授权AccessToken
            string accessToken = obj.Data.AccessToken;

            string userAuthUrl = string.Format(@"{0}/OpenApi/Authorization/GetUserAuth?AccessToken={1}", baseUrl, accessToken);

            data = SendHttp(accessTokenUrl, "GET", null);
            obj  = JsonConvert.DeserializeObject <dynamic>(data);

            if (obj.ErrorCode != 0 || ((Array)obj.Data).Length == 0)
            {
                return(JSONHelper.FromString(false, "您暂未有门禁授权"));
            }

            return(new ApiResult(true, obj.Data).toJson());
        }
Beispiel #2
0
        /// <summary>
        /// 实地单点登录接口
        /// </summary>
        /// <returns></returns>
        public static bool SDLogin(string loginCode, string loginPwd)
        {
            try
            {
                // 是否启用单点登录
                if (!"1".Equals(WebConfigurationManager.AppSettings.Get("SD_SSO_Enabled")))
                {
                    return(false);
                }
                string Api        = WebConfigurationManager.AppSettings.Get("SD_SSO_API");
                string SystemCode = WebConfigurationManager.AppSettings.Get("SD_SSO_SystemCode");
                string Key        = WebConfigurationManager.AppSettings.Get("SD_SSO_Key");

                string data = string.Format("systemCode={0}&userCode={1}&password={2}&sign={3}", SystemCode, loginCode, loginPwd, AppGlobal.getMd5Hash(loginCode + loginPwd + Key).ToUpper());
                DotNet4.Utilities.HttpHelper http     = new DotNet4.Utilities.HttpHelper();
                DotNet4.Utilities.HttpItem   httpItem = new DotNet4.Utilities.HttpItem()
                {
                    URL              = Api,    //URL     必需项
                    Method           = "POST", //URL     可选项 默认为Get
                    Timeout          = 3000,   //连接超时时间     可选项默认为100000
                    ReadWriteTimeout = 3000,   //写入Post数据超时时间     可选项默认为30000
                    IsToLower        = false,  //得到的HTML代码是否转成小写     可选项默认转小写
                    ContentType      = "application/x-www-form-urlencoded",
                    PostEncoding     = Encoding.UTF8,
                    Postdata         = data,
                    ResultType       = DotNet4.Utilities.ResultType.String,//返回数据类型,是Byte还是String
                };
                DotNet4.Utilities.HttpResult result = http.GetHtml(httpItem);
                JObject jObj = JsonConvert.DeserializeObject <JObject>(result.Html);
                if (!(bool)jObj["success"])
                {
                    GetLog().Error(JsonConvert.SerializeObject(jObj));
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                GetLog().Error(ex.Message + Environment.CommandLine + ex.StackTrace);
                return(false);
            }
        }