///// <summary> ///// 登录验证 ///// </summary> ///// <param name="account"></param> ///// <param name="password"></param> ///// <returns></returns> //public hsf_owner CheckLogin(string account, string password) //{ // hsf_owner ownerEntity = null; // using (HsfDBContext hsfDBContext = new HsfDBContext()) // { // using (RedisHashService service = new RedisHashService()) // { // string _password = service.GetValueFromHash("Login", account); // if (string.IsNullOrEmpty(_password)) // { // ownerEntity = hsfDBContext.hsf_owner.Where(t => t.telphone == account && t.deletemark == 0).FirstOrDefault(); // if (ownerEntity != null) // { // service.SetEntryInHash("Login", account, ownerEntity.password); // if (ownerEntity.password == password) // { // return ownerEntity; // } // else // { // return null; // } // } // else // { // return null; // } // } // else // { // if (_password == password) // { // string _Owner = service.GetValueFromHash("Owner", account); // if (string.IsNullOrEmpty(_Owner)) // { // ownerEntity = hsfDBContext.hsf_owner.Where(t => t.telphone == account && t.deletemark == 0).FirstOrDefault(); // if (ownerEntity != null) // { // service.SetEntryInHash("Owner", ownerEntity.telphone, JsonConvert.SerializeObject(ownerEntity)); // return ownerEntity; // } // else // { // return null; // } // } // else // { // return JsonConvert.DeserializeObject<hsf_owner>(_Owner); // } // } // else // { // return null; // } // } // } // } //} /// <summary> /// 新风登录验证:t_customer_user表unionid(补充手机号,一个公众号对应一个),得到id作为网关id,缓存手机号-网关 /// </summary> /// <param name="account"></param> /// <param name="password"></param> /// <returns>返回用户实体</returns> public string CheckLogin(string account, string password) { using (NewiotDBContext newiotDBContext = new NewiotDBContext()) { using (RedisHashService service = new RedisHashService()) { string password_redis = service.GetValueFromHash("Host", account);//redis值 //string password_md5 = PasswordHelper.MD5Encoding("123456","huiquan");//不知道salt多少盐值得到=77d3b7ed9db7d236b9eac8262d27f6a5 if (string.IsNullOrEmpty(password_redis)) { t_customer_user ownerEntity = newiotDBContext.t_customer_user.Where(t => t.unionid == account).FirstOrDefault(); if (ownerEntity != null) { service.SetEntryInHash("Host", account, ownerEntity.id.ToString()); return(ownerEntity.id.ToString()); } else { return(null); } } else { return(password_redis); } } } }
/// <summary> /// 设备发现方法 /// {"header":{"payloadVersion":"1","name":"DiscoverAppliancesRequest","namespace":"DuerOS.ConnectedHome.Discovery","messageId":"_Smarthome_5e15736fecca90.99201862"},"payload":{"accessToken":"UXUlOvDAj314-oHtP3VDcAW7zOfIEycjTQQf6emki4uKfDJ83iFyl4cPCyfGVJH2Pgy_fgi_F3vMDPIkTwcMmrXZoyDqMxVPEHzGsmMlQfvm10Hg9cFe9apFco14SXDN5lew3XAeIZnPMJwXA2DOv8cA9g5rMJjrwcPAhOUXUTScM2IJNaJPWxjFqke7tuNwRo__iTBVHA4t4LogvoUQ8TByPcpONGXptxJApSkn8M8","openUid":"ee65663a03e810214acc0ac1c18260e7"}} /// </summary> /// <param name="commonModel"></param> /// <param name="tokenModel"></param> /// <returns></returns> private object Discove(CommonReceiveModel commonModel, IntelligentHostCacheModel tokenModel) { //IntelligentHostCacheModel cacheModel = CacheData.GetAccessTokenCache(receiveObj.payload.accessToken); //CacheData.SetOpenUid(cacheModel.AccessToken, cacheModel, commonModel.payload.openUid); try { using (RedisHashService service = new RedisHashService()) { string hostId = tokenModel.HostId;//账号 string openUid = commonModel.payload.openUid; //设置设备与OpenUid的绑定关系 service.SetEntryInHash("DuerOSOpenUid_Host", hostId, openUid); //拼装返回消息格式 DiscoveReturnModel resModel = new DiscoveReturnModel() { header = new Dueros.Models.CommonModel.Head() { messageId = commonModel.header.messageId, name = commonModel.header.name.Replace("Request", "Response"), @namespace = commonModel.header.@namespace, payloadVersion = commonModel.header.payloadVersion }, payload = new DiscoverPayload() { discoveredGroups = new List <DiscoveredGroup>(), discoveredAppliances = new List <DiscoveredAppliance>() } }; //获取当前百度账号的设备列表,先找缓存 string discoverPayloadJson = service.GetValueFromHash("DuerOS_DiscoverPayload", hostId); if (!string.IsNullOrEmpty(discoverPayloadJson)) { resModel.payload = JsonConvert.DeserializeObject <DiscoverPayload>(discoverPayloadJson); } else { List <t_device_team> roomList = null; //房间区域列表 List <t_device_team_item> roomDeviceList = null; //区域设备列表 //1.找当前账号的房间列表区域 string roomListJson = service.GetValueFromHash("Room", hostId); if (!string.IsNullOrEmpty(roomListJson)) { roomList = JsonConvert.DeserializeObject <List <t_device_team> >(roomListJson); } else { using (NewiotDBContext hsfDBContext = new NewiotDBContext()) { //默认房间为0,查询当前账号所有设备列表 roomList = hsfDBContext.t_device_team.Where(t => t.createUserId.ToString() == hostId && t.status == 0).OrderBy(t => t.createTime).ToList(); //缓存当前房间的设备列表,不包括状态,不管空与否都缓存,防止第二次还查数据库RoomDevices service.SetEntryInHash("Room", hostId, JsonConvert.SerializeObject(roomList)); } } //2.组装区域列表 if (roomList.Count > 0) { //房间列表不为空,则拼装区域json foreach (var item in roomList) { //获取当前区域的设备列表 roomDeviceList = GetDeviceListByRoom(service, hostId, item.id); if (roomDeviceList != null) { List <string> applianceIds = new List <string>(); foreach (var dev in roomDeviceList) { applianceIds.Add(dev.cachekey); } DiscoveredGroup discoveredGroup = new DiscoveredGroup() { groupName = item.chinaname, applianceIds = applianceIds, groupNotes = item.chinaname + "分组控制", additionalGroupDetails = { } }; resModel.payload.discoveredGroups.Add(discoveredGroup); } } } //调用逻辑获取缓存中0房间所有的设备 List <host_device> allDeviceList = GetDeviceListByRoom(service, hostId, "0"); foreach (var item in allDeviceList) { //类型对照表 List <string> applianceTypes = null; List <string> actions = null; //根据对照,获取百度的设备类型type,操作action GetDuerOSDveType(item.devtype, out applianceTypes, out actions); //拼装发给百度的设备信息 if (applianceTypes != null && actions != null) { DiscoveredAppliance discoveredAppliance = new DiscoveredAppliance() { applianceTypes = applianceTypes, applianceId = item.cachekey,//不使用id,使用mac+port modelName = item.devtype, version = "1.0", friendlyName = item.chinaname, friendlyDescription = "", isReachable = true, actions = actions, additionalApplianceDetails = { }, manufacturerName = "DASKLIMA" }; //以对象数组返回客户关联设备云帐户的设备、场景 resModel.payload.discoveredAppliances.Add(discoveredAppliance); //设置设备与OpenUid的绑定关系 service.SetEntryInHash("DuerOSOpenUid_Device", item.cachekey, openUid); } } //场景处理,后续 //缓存百度设备列表payload,不包含状态 service.SetEntryInHash("DuerOS_DiscoverPayload", hostId, JsonConvert.SerializeObject(resModel.payload)); } //设备状态详情信息,都要执行,因为缓存的DuerOS_DiscoverPayload不存状态 foreach (var item in resModel.payload.discoveredAppliances) { List <AttributesItem> attributes = new List <AttributesItem>(); //获取当前缓存状态 AttributesItem attribute = GetStateByCachekey(service, item.applianceId); attributes.Add(attribute); item.attributes = attributes; } return(resModel); } } catch (Exception ex) { FunctionHelper.writeLog("GetDevice error:", ex.Message + " " + ex.StackTrace, "DeviceDiscoverHandleError"); return(null); } }