using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json.Linq;
using Shared.SimpleControl;
namespace Shared
{
///
/// 接口请求封装
///
public class HttpServerRequest
{
#region ■ 变量声明___________________________
///
/// 通用方法
///
private static HttpServerRequest m_Current = null;
///
/// 通用方法
///
public static HttpServerRequest Current {
get {
if (m_Current == null) {
m_Current = new HttpServerRequest ();
}
return m_Current;
}
}
#endregion
#region ■ 通用请求接口_______________________
///
/// 根椐用户账号获取注册区域 免登录 // 检测账号是否注册也用这个接口
///
///
///
public ResponsePackNew GetRegionByAccount(string account)
{
var requestJson = HttpUtil.GetSignRequestJson(new RegionByAccountObj() { account = account });
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_GetRegionByAccount, requestJson, HttpUtil.GlobalRequestHttpsHost);
}
///
/// 刷新Token
///
///
public string RefreshToken()
{
var requestJson = HttpUtil.GetSignRequestJson(new RefreshTokenObj()
{
refreshToken = MainPage.LoginUser.RefreshToken,
});
var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_Login, requestJson);
if (revertObj.Code.ToUpper() == StateCode.SUCCESS)
{
var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject(revertObj.Data.ToString());
MainPage.LoginUser.LoginTokenString = revertData.headerPrefix + revertData.accessToken;
MainPage.LoginUser.RefreshToken = revertData.refreshToken;
MainPage.LoginUser.LastTime = DateTime.Now;
MainPage.LoginUser.SaveUserInfo();
}
return revertObj.Code;
}
#endregion
#region * 注册、登录部分___________________________
///
/// 通用 发送验证码方法
///
/// 1:注册 2:找回密码 3:绑定4:验证码登陆 5:敏感数据
/// 邮箱或者手机号
/// 是否手机
/// 手机国家区号
///
public ResponsePackNew VerificationCodeSend(VerifyType verifyType, string account, bool isPhone = false, string phoneZoneCode = "86")
{
var requestObj = new VerifyCodeSendObj()
{
verifyType = (int)verifyType,
languageType = Utlis.GetPostLanguageType()
};
// 是否是手机
if (isPhone)
{
requestObj.phone = account;
requestObj.phonePrefix = phoneZoneCode;
}
else
{
requestObj.mail = account;
}
// 超时时间设置为20秒,应该测试海外服务器发送验证码响应时间很久
var requestJson = HttpUtil.GetSignRequestJson(requestObj);
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Verification_Send, requestJson, "", "", HttpUtil.TIME_OUT_LONG);
}
///
/// 账号登录-使用密码
///
/// 账号
/// 密码
///
public ResponsePackNew LoginByPassword(string account, string password)
{
var requestJson = HttpUtil.GetSignRequestJson(new LoginObj()
{
account = account,
loginPwd = password
});
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Login, requestJson);
}
///
/// 验证码登录
///
/// 账号
/// 验证码
///
public ResponsePackNew LoginValidCode(string account, string vCode)
{
var requestJson = HttpUtil.GetSignRequestJson(new LoginObj()
{
account = account,
verifyCode = vCode,
grantType = "verify"
});
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Login, requestJson);
}
///
/// 验证短信或者邮箱验证码,之后注册
///
/// 邮箱或者手机号
/// 密码
/// 验证码
/// 是否手机
///
public ResponsePackNew ValidataCodeAndRegister(string name,string account, string password, string code, bool isPhone = false)
{
var requestObj = new RegisterObj() { loginPwd = password, verifyCode = code, memberName = name};//, memberName = account
if (isPhone)
{
requestObj.memberPhone = account;
}
else
{
requestObj.memberEmail = account;
}
var requestJson = HttpUtil.GetSignRequestJson(requestObj);
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_Register, requestJson, "", "", HttpUtil.TIME_OUT_LONG);
}
///
/// 忘记密码,重置密码
///
/// 邮箱或者手机号
/// 新密码
/// 验证码
/// 是否手机账号
///
public ResponsePackNew ForgetPassword(string account, string password, string vCode, bool isPhone)
{
var requestObj = new ForgetPwdObj() { verifyCode = vCode, loginPwd = password };
if (isPhone)
{
//手机忘记密码
requestObj.memberPhone = account;
}
else
{
//邮箱忘记密码
requestObj.memberEmail = account;
}
var requestJson = HttpUtil.GetSignRequestJson(requestObj);
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_ForgetPwd, requestJson);
}
///
/// 修改密码
/// 提供新旧密码
///
///
///
///
public ResponsePackNew ModifyPassword (string oldPassword, string newPassword) {
var requestJson = HttpUtil.GetSignRequestJson (new UpdatePwdObj () {
loginPwd = oldPassword,
loginNewPwd = newPassword
});
return HttpUtil.RequestHttpsPost (NewAPI.API_POST_Update_Pwd, requestJson);
}
///
/// 验证验证码
///
/// 验证类型
/// 验证账号
/// 验证码
/// 是否手机
/// 验证通过后,验证码是否失效
///
public ResponsePackNew ValidatorCode(VerifyType verifyType, string account, string code, bool isPhone, bool verifySuccessFail = true)
{
var requestObj = new VerifyCodeCheckObj() { verifyCode = code, verifyType = (int)verifyType, verifySuccessFail = verifySuccessFail };
if (isPhone)
{
//手机
requestObj.phone = account;
}
else
{
//邮箱
requestObj.mail = account;
}
var requestJson = HttpUtil.GetSignRequestJson(requestObj);
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Verification_Check, requestJson);
}
#endregion
#region * 个人信息部分___________________________
/////
///// 获取用户信息
/////
/////
//public string GetUserInfo(bool bGetHeadImage = true)
//{
// var requestJson = HttpUtil.GetSignRequestJson(new NullObj());
// var resultObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_GetMemberInfo, requestJson);
// if (resultObj.Code == StateCode.SUCCESS)
// {
// var info = Newtonsoft.Json.JsonConvert.DeserializeObject(resultObj.Data.ToString());
// MainPage.LoginUser.userEmailInfo = info.memberEmail;
// MainPage.LoginUser.userMobileInfo = info.memberPhone;
// MainPage.LoginUser.userName = info.memberName;
// if (!string.IsNullOrEmpty(info.memberPhonePrefix))
// {
// MainPage.LoginUser.areaCode = info.memberPhonePrefix;
// }
// //是否需要获取头像
// if (bGetHeadImage)
// {
// //2020-12-15 修改头像方案
// if (!string.IsNullOrEmpty(info.memberHeadIcon))
// {
// var headImageBytes = ImageUtlis.Current.DownHeadImageByImageKey(info.memberHeadIcon);
// if (headImageBytes != null && headImageBytes.Length > 0)
// {
// MainPage.LoginUser.headImagePagePath = info.memberHeadIcon;
// //MainPage.LoginUser.headImagePagePath = imageKey;
// }
// }
// }
// MainPage.LoginUser.SaveUserInfo();
// Utlis.WriteLine("获取用户信息成功。");
// }
// return resultObj.Code;
//}
/////
///// 获取用户头像
/////
/////
//public void GetUserHeadImageByKey(string imageKey)
//{
// var headImageBytes = ImageUtlis.Current.DownHeadImageByImageKey(imageKey);
// if (headImageBytes != null && headImageBytes.Length > 0)
// {
// //MainPage.LoginUser.headImagePageBytes = headImageBytes;
// MainPage.LoginUser.headImagePagePath = imageKey;
// }
//}
///
/// 更新用户昵称
///
///
///
public ResponsePackNew EditUserName(string userName)
{
var requestJson = HttpUtil.GetSignRequestJson(new UpdateMemberNameRes()
{
memberName = userName
});
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_UpdateMemberInfo, requestJson);
}
///
/// 标记2.0平台数据
///
///
public bool Mark (string newHomeId)
{
Dictionary dic = new Dictionary ();
dic.Add ("homeId", newHomeId);
dic.Add ("mark", true);
var requestJson = HttpUtil.GetSignRequestJson (dic);
var revertObj = HttpUtil.RequestHttpsPost (NewAPI.API_Post_Mark, requestJson);
if (revertObj != null) {
if (revertObj.Code == "0") {
UserConfig.Instance.CurrentRegion.indiaIsAsyncDeviceMark = true;
return true;
}
}
return false;
}
/////
///// 更新用户头像
/////
/////
/////
//public ResponsePackNew UpdateMemberHeadIcon(string memberHeadIcon)
//{
// var requestJson = HttpUtil.GetSignRequestJson(new UpdateMemberHeadIconRes()
// {
// memberHeadIcon = memberHeadIcon
// });
// return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_UpdateMemberInfo, requestJson);
//}
/////
///// 更新用户头像
/////
/////
/////
//public string UpdataUserHeadImage(string fileName)
//{
// byte[] bytes = Shared.IO.FileUtils.ReadFile(fileName);
// var revertObj = HttpUtil.RequestHttpsUpload(RestSharp.Method.POST, NewAPI.API_POST_Head_Upload, bytes);
// return revertObj.Code;
//}
///
/// 更改绑定账户的邮箱或者手机号
/// 2020-11-16 待修改
///
///
///
///
///
public string BindAccount(string account, string code = "", bool isPhone = false)
{
var requestObj = new BindWithAccountObj() { verifyCode = code };
if (isPhone)
{
//手机
requestObj.memberPhone = account;
}
else
{
//邮箱
requestObj.memberEmail = account;
}
var requestJson = HttpUtil.GetSignRequestJson(requestObj);
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_BindWithAccount, requestJson).Code;
}
///
/// 解绑手机或者邮箱
///
///
///
public string UnBindAccount(bool isPhone)
{
var requestObj = new UnBindAccountObj() { unBindLabel = isPhone ? "PHONE" : "EMAIL" };
var requestJson = HttpUtil.GetSignRequestJson(requestObj);
return HttpUtil.RequestHttpsPost(NewAPI.API_POST_Member_UnbindWithAccount, requestJson).Code;
}
#endregion
#region * 住宅部分___________________________
///
/// 获取住宅列表
///
public ResponsePackNew GetHomeList (HomeTypeEnum homeType = HomeTypeEnum.BUSPRO)
{
var requestJson = HttpUtil.GetSignRequestJson (new GetHomeListObj () { homeType = homeType.ToString () });
return HttpUtil.RequestHttpsPost (NewAPI.API_POST_Gethomepager, requestJson);
}
///
/// 获取住宅列表
///
public string GetHomePager (HomeTypeEnum homeType = HomeTypeEnum.BUSPRO)
{
var requestJson = HttpUtil.GetSignRequestJson (new GetHomeListObj () { homeType = homeType.ToString () });
var resultObj = HttpUtil.RequestHttpsPost (NewAPI.API_POST_Gethomepager, requestJson);
if (resultObj.Code == StateCode.SUCCESS) {
UserConfig.Instance.HomeLists = new List ();
var homeList = Newtonsoft.Json.JsonConvert.DeserializeObject> (resultObj.Data.ToString ());
if (homeList == null || homeList.Count == 0) {
UserConfig.Instance.SaveUserConfig ();
} else {
foreach (var mHome in homeList) {
var home = RegionInfoResNewToHome (mHome);
UserConfig.Instance.HomeLists.Add (home);
}
//住宅被删除
var findHome = UserConfig.Instance.HomeLists.Find ((obj) => obj.Id == UserConfig.Instance.CurrentRegion.Id);
if (findHome == null) {
Shared.Application.RunOnMainThread (() => {
UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0];
GetHomeGatewayList ();
UserConfig.Instance.SaveUserConfig ();
//提示住宅被删除
//Action action = () =>
//{
// MainPage.GoUserPage (true);
//};
//new UI.PublicAssmebly ().TipMsg (StringId.Tip, StringId.ResidenceDeletedSwitchToAnotherResidence, action);
});
} else {
//刷新当前住宅
UserConfig.Instance.CurrentRegion = findHome;
UserConfig.Instance.SaveUserConfig ();
//刷新一次住宅网关
GetHomeGatewayList ();
}
}
}
return resultObj.Code;
}
///
///
///
///
///
public RegionInfoRes RegionInfoResNewToHome (RegionInfoResNew mHome)
{
return new RegionInfoRes () {
Id = mHome.Id,
Name = mHome.homeName,
IsOthreShare = mHome.IsOtherShare,
isRemoteControl = mHome.isRemoteControl,
isBindGateway = mHome.isBindGateway,
regionUrl = mHome.regionUrl,
debugStaffUserId = mHome.debugStaffUserId,
debugPerm = mHome.debugPerm,
indiaIsAsyncDeviceMark = mHome.indiaIsAsyncDeviceMark
};
}
///
/// 编辑住宅信息
///
/// 0 修改住宅名字、1 修改住宅地址
///
///
public ResponsePackNew EditResidenceInfo(int editId, string editName)
{
var requestObj = new AddOrUpdateHomeObj()
{
homeId = UserConfig.Instance.CurrentRegion.Id,
};
if (editId == 0)
{
requestObj.homeName = editName;
}
else if (editId == 1)
{
requestObj.Address = editName;
}
var requestJson = HttpUtil.GetSignRequestJson(requestObj);
return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Home_UpdateHome, requestJson);
}
///
/// 根据homeId删除指定
///
///
///
public ResponsePackNew AddHome (string homeName)
{
var requestJson = HttpUtil.GetSignRequestJson (new AddOrUpdateHomeObj () {
homeName = homeName,
homeType = HomeTypeEnum.BUSPRO.ToString ()
}) ;
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Home_AddHome, requestJson);
}
///
/// 根据homeId删除指定
///
///
///
public ResponsePackNew DeleteHome (string homeId)
{
var requestJson = HttpUtil.GetSignRequestJson (new HomeIdObj () {
homeId = homeId
});
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Home_Delete, requestJson);
}
#region 网关相关
///
/// 绑定网关
///
///
///
public ResponsePackNew BindGateway (BindGatewayObj newGateway)
{
var requestJson = HttpUtil.GetSignRequestJson (newGateway);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_BindGateway, requestJson);
}
///
/// 解绑网关
///
///
///
public ResponsePackNew UnBindGateway (string homeId, string mac)
{
var d = new Dictionary ();
d.Add ("homeId", homeId);
d.Add ("gatewayId", mac);
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_UntieGateway, requestJson);
}
///
/// 强制换绑网关
///
///
///
public ResponsePackNew ForceBind (string homeId,string mac)
{
var d = new Dictionary ();
d.Add ("homeId", homeId);
d.Add ("mac", mac);
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.Api_Post_ForceBind, requestJson);
}
///
/// 获取刷新当前住宅的网关列表
///
public string GetHomeGatewayList()
{
try
{
if (string.IsNullOrEmpty(UserConfig.Instance.CurrentRegion.Id)) return "";
var nowhomeId = UserConfig.Instance.CurrentRegion.Id;
var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = nowhomeId });
var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_GetGatewayList, requestJson);
if (revertObj.Code == StateCode.SUCCESS)
{
var mHomeGatewayRes = Newtonsoft.Json.JsonConvert.DeserializeObject>(revertObj.Data.ToString());
if (nowhomeId == UserConfig.Instance.CurrentRegion.Id)
{
if (mHomeGatewayRes != null)
{
if (mHomeGatewayRes.Count > 0)
{
UserConfig.Instance.HomeGateway = mHomeGatewayRes[0];
UserConfig.Instance.SaveUserConfig();
return revertObj.Code;
}
}
//其余情况清空网关信息
UserConfig.Instance.HomeGateway = null;
UserConfig.Instance.SaveUserConfig ();
}
}
else
{
//提示错误
}
return revertObj.Code;
}
catch
{
return "";
}
}
///
/// 获取网关信息
///
public string GetGatewayInfo()
{
Dictionary d = new Dictionary();
d.Add("homeId", UserConfig.Instance.CurrentRegion.Id);
d.Add("gatewayId", UserConfig.Instance.HomeGateway.gatewayId);
var jsonString = HttpUtil.GetSignRequestJson(d);
var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetGatewayInfo, jsonString);
if (revertObj.Code == StateCode.SUCCESS)
{
var mHomeGatewayRes = Newtonsoft.Json.JsonConvert.DeserializeObject(revertObj.Data.ToString());
if (mHomeGatewayRes != null)
{
if(mHomeGatewayRes.gatewayStatus)
{
//DriverLayer.Control.Ins.GatewayOnline = true;
}
}
}
return revertObj.Code;
}
#endregion
#region 子账号相关
///
/// 获取住宅下的成员账号
///
///
public ResponsePackNew GetResidenceMemberAccount()
{
var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = UserConfig.Instance.CurrentRegion.Id });
return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_FindAll, requestJson);
}
///
/// 绑定子账号到住宅下
///
///
///
///
public ResponsePackNew BindResidenceMemberAccount (string subAccount, string nickName)
{
//添加子账号
var requestObj = new ChildAddObj () { homeId = UserConfig.Instance.CurrentRegion.Id, account = subAccount, nickName = nickName };
var requestJson = HttpUtil.GetSignRequestJson (requestObj);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Child_Add, requestJson);
}
///
/// 删除住宅下的成员账号
///
///
public ResponsePackNew DeleteResidenceMemberAccount(ResidenceMemberInfo subaccount)
{
var requestObj = new ChildDeleteObj()
{
childAccountId = subaccount.childAccountId,
homeId = subaccount.homeId
};
var requestJson = HttpUtil.GetSignRequestJson(requestObj);
return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Delete, requestJson);
}
///
/// 修改子账号昵称
///
///
///
///
public ResponsePackNew EditSubAccountNickName(string nickName, string childAccountId)
{
var requestJson = HttpUtil.GetSignRequestJson(new UpdateChildNickNameObj()
{
homeId = UserConfig.Instance.CurrentRegion.Id,
childAccountId = childAccountId,
nickName = nickName,
});
return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Update, requestJson);
}
///
/// 修改子账号创建场景权限
///
///
///
///
public ResponsePackNew ChangeCreateSceneState(bool isAllow, string childAccountId)
{
var requestJson = HttpUtil.GetSignRequestJson(new UpdateChildAllowCreateSceneObj()
{
homeId = UserConfig.Instance.CurrentRegion.Id,
childAccountId = childAccountId,
isAllowCreateScene = isAllow,
});
return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Update, requestJson);
}
#endregion
#region 调试人员管理
///
/// 添加调试人员
///
/// 添加调试人员账号
///
public ResponsePackNew AddDebugStaff (string account)
{
Dictionary d = new Dictionary ();
d.Add ("homeId", UserConfig.Instance.CurrentRegion.Id);
d.Add ("account", account);
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_DebugStaff_ADD, requestJson);
}
///
/// 删除调试人员
///
/// 添加调试人员账号
///
public ResponsePackNew DelDebugStaff ()
{
Dictionary d = new Dictionary ();
d.Add ("homeId", UserConfig.Instance.CurrentRegion.Id);
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_DebugStaff_DELETE, requestJson);
}
///
/// 添加调试人员
///
/// 添加调试人员账号
///
public ResponsePackNew UpdateDebugPerm (bool debugPerm)
{
Dictionary d = new Dictionary ();
d.Add ("homeId", UserConfig.Instance.CurrentRegion.Id);
d.Add ("debugPerm", debugPerm);
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_DebugStaff_UPDATE, requestJson);
}
#endregion
#region 新数据分享
///
/// 添加分享
///
///
///
public ResponsePackNew AddShareData(AddShareObj addShareObj)
{
var requestJson = HttpUtil.GetSignRequestJson(addShareObj);
return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_Add, requestJson);
}
///
/// 删除分享
///
///
///
public ResponsePackNew DeleteShareData(DeleteShareObj deleteShareObj)
{
var requestJson = HttpUtil.GetSignRequestJson(deleteShareObj);
return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_Delete, requestJson);
}
///
/// 获取分享
///
///
///
public ResponsePackNew GetShareDataByMemberAccount(string childAccountId)
{
var requestJson = HttpUtil.GetSignRequestJson(new GetShareObj()
{
homeId = UserConfig.Instance.CurrentRegion.Id,
childAccountId = childAccountId,
});
return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_GetList, requestJson);
}
#endregion
#endregion
#region * 备份相关部分___________________________
///
/// 创建备份文件夹
///
///
///
public ResponsePackNew GetHomeDataBackupList ()
{
var requestObj = new HomeIdObj () {
homeId = UserConfig.Instance.CurrentRegion.Id,
};
var requestJson = HttpUtil.GetSignRequestJson (requestObj);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Folder_FindAll, requestJson);
}
///
/// 创建备份文件夹
///
///
///
public ResponsePackNew CreateBackupFolder (string folderName)
{
var requestObj = new BackupFolderCreateObj () {
backupClassify = BackupClassify.USER_DEFINED_BACKUP.ToString (),
backupDataType = BackupDataType.HDL_ON.ToString (),
homeId = UserConfig.Instance.CurrentRegion.Id,
folderName = folderName,
};
var requestJson = HttpUtil.GetSignRequestJson (requestObj);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Folder_Create, requestJson);
}
///
/// 修改备份文件夹名字
///
///
///
///
public ResponsePackNew UpdateBackupFolderName (string newName, BackupListNameInfoRes mBackupFile)
{
var requestObj = new UpdateBackupObj () {
folderId = mBackupFile.id,
homeId = mBackupFile.homeId,
folderName = newName,
};
var requestJson = HttpUtil.GetSignRequestJson (requestObj);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Folder_Update, requestJson);
}
///
/// 删除备份文件夹
///
///
///
public ResponsePackNew DeleteBackupFolder (string folderId)
{
var requestObj = new BackupFolderIdObj () {
homeId = UserConfig.Instance.CurrentRegion.Id,
folderId = folderId,
};
var requestJson = HttpUtil.GetSignRequestJson (requestObj);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Folder_Delete, requestJson);
}
///
/// 获取备份文件夹所有文件列表
///
///
///
public ResponsePackNew GetBackupFolderAllFileList (string folderId)
{
var requestObj = new BackupFolderIdObj () {
homeId = UserConfig.Instance.CurrentRegion.Id,
folderId = folderId,
};
var requestJson = HttpUtil.GetSignRequestJson (requestObj);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_File_FindAll, requestJson);
}
#endregion
#region * Mqtt___________________________
///
/// 获取MQTT远程连接信息接口
///
public MqttInfo GetMqttRemoteInfo(string attachClientId)
{
try
{
var requestJson = HttpUtil.GetSignRequestJson(new GetMqttRemoteInfoObj()
{
attachClientId = attachClientId + "L1",
homeType = HomeTypeEnum.BUSPRO.ToString()
});
var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GetMqttRemoteInfo, requestJson, UserConfig.Instance.CurrentRegion.regionUrl);
if (revertObj.Code == StateCode.SUCCESS)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject(revertObj.Data.ToString());
}
else
{
Utlis.WriteLine("GetMqttRemoteInfo error Code:" + revertObj.Code);
return null;
}
}
catch
{
return null;
}
}
#endregion
#region * 获取天气部分___________________________
///
/// 获取指定经纬度的城市信息
///
public void GetCityInfo(string lon, string lat)
{
CommonPage.AirQuality = new AirQuality ();
System.Threading.Tasks.Task.Run (() => {
while (true) {
Utlis.WriteLine ("Get Location GetAirQuality");
//获取天气
var webClient = new WebClient ();
//if(arg1 == null) {
// Utlis.WriteLine ("GetAirQuality arg1 == null");
//}
string url = $"https://developer.hdlcontrol.com/Weather/Weather/FindCity/?lon={lon}&lat={lat}";
string responseString = null;
try {
responseString = Encoding.UTF8.GetString (webClient.DownloadData (url));
} catch (Exception ex) {
Utlis.WriteLine (ex.Message);
}
if (responseString != null) {
try {
var revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject (responseString);
JObject jt = Newtonsoft.Json.JsonConvert.DeserializeObject (revertObj.ResponseData.ToString ());
CommonPage.AirQuality.city = jt ["City"].ToString ();
var cityId = jt ["Cid"].ToString ();
url = $"https://developer.hdlcontrol.com/Weather/Weather/GetAirQualityAndWeather/?cid={cityId}";
responseString = null;
try {
responseString = Encoding.UTF8.GetString (webClient.DownloadData (url));
revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject (responseString);
jt = Newtonsoft.Json.JsonConvert.DeserializeObject (revertObj.ResponseData.ToString ());
CommonPage.AirQuality.airQTemp = jt ["Temperature"].ToString ();
CommonPage.AirQuality.airQHumidity = jt ["Humidity"].ToString ();
CommonPage.AirQuality.airQAirPM25 = jt ["PM25"].ToString ();
CommonPage.AirQuality.airQAirWeather = jt ["Weather"].ToString ();
break;
} catch (Exception ex) {
Utlis.WriteLine (ex.Message);
}
} catch (Exception ex) {
Utlis.WriteLine (ex.ToString ());
}
}
}
Shared.Application.RunOnMainThread (() => {
if (CommonPage.RefreshAir != null)
CommonPage.RefreshAir ();
});
});
}
#endregion
#region * 上传设备列表___________________________
///
/// 上传Oid列表
///
///
///
public ResponsePackNew UploadDeviceOidList (Oids mOids)
{
var requestJson = HttpUtil.GetSignRequestJson (mOids);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Device_Oid_Add, requestJson);
}
///
/// 上传Sid列表
///
///
///
public ResponsePackNew UploadDeviceSidList (Sids mSids)
{
var requestJson = HttpUtil.GetSignRequestJson (mSids);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Device_Sid_Add, requestJson);
}
///
/// 获取设备列
///
///
public ResponsePackNew GetDeviceList ()
{
var requestJson = HttpUtil.GetSignRequestJson (new HomeIdObj {
homeId = UserConfig.Instance.CurrentRegion.Id,
});
return HttpUtil.RequestHttpsPostFroHome (NewAPI.Api_Post_GetDevcieList, requestJson);
}
#endregion
#region 音箱语言控制相关___________________________
///
/// 获取已授权的音箱列表
///
///
public ResponsePackNew GetSpeakerList ()
{
var requestJson = HttpUtil.GetSignRequestJson (new GetSpeakerObj {
homeId = UserConfig.Instance.CurrentRegion.Id,
});
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Speaker_List_Get, requestJson);
}
///
/// 编辑音箱授权备注
///
///
public ResponsePackNew UpdateSpeakerRemark (UpdateSpeakerRemarkObj remarkObj)
{
var requestJson = HttpUtil.GetSignRequestJson (remarkObj);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Speaker_Remark_Update, requestJson);
}
///
/// 解除音箱绑定
///
///
public ResponsePackNew UnbindSpeaker (string tokenId)
{
Dictionary d = new Dictionary ();
d.Add ("tokenId", tokenId);
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Speaker_Unbind, requestJson);
}
///
/// 获取音箱分配的设备和场景列表
///
/// 0 是查询全部 1是查询设备 2是查询场景
///
///
public ResponsePackNew GetSpeakerDeviceList (int getType, string tokenId)
{
Dictionary d = new Dictionary ();
d.Add ("homeId", UserConfig.Instance.CurrentRegion.Id);
d.Add ("tokenId", tokenId);
if(getType > 0) {
d.Add ("isDevice", getType == 1);
}
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Speaker_DeviceList_Get, requestJson);
}
///
/// 更新音箱控制的设备和场景目标
///
///
public ResponsePackNew UpdateSpeakerDeviceList (UpdateSpeakerDeviceListObj updateSpeakerDeviceListObj)
{
var requestJson = HttpUtil.GetSignRequestJson (updateSpeakerDeviceListObj);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.API_POST_Speaker_DeviceList_Update, requestJson);
}
#endregion
///
/// 申请设备密钥
///
///
///
public ResponsePackNew ApplyDeviceSecret (string mac)
{
Dictionary d = new Dictionary ();
d.Add ("supplier", "HDL");
d.Add ("mac", mac);
d.Add ("spk", "BUSUDPGATEWAY");
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.Api_Post_ApplyDeviceSecret, requestJson);
}
//#region Kaede --设备功能——————————————————————————————————
/////
///// 获取设备列表
/////
/////
//public ResponsePackNew GetDeviceList()
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// //d.Add("gatewayId", DB_ResidenceData.residenceData.HomeGateway.gatewayId);
// //d.Add("roomId", DB_ResidenceData.residenceData.residecenInfo.RegionID);//可控参数,当需要分页获取,怎么知道分页总数
// //d.Add("searchType", DB_ResidenceData.residenceData.residecenInfo.RegionID);
// //d.Add("pageSize", DB_ResidenceData.residenceData.residecenInfo.RegionID);
// //d.Add("pageNo", DB_ResidenceData.residenceData.residecenInfo.RegionID);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetDevcieList, requestJson);
//}
/////
///// 获取设备详情列表
/////
/////
//public ResponsePackNew GetDeviceInfoList(List functionIds)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("deviceIds", functionIds);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetDevcieInfoList, requestJson);
//}
/////
///// 刷新设备状态
/////
/////
//public ResponsePackNew RefreshDeviceStatus(List functionIds)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("deviceIds", functionIds);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// Utlis.WriteLine($"读取设备状态:{requestJson}");
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_RefreshDeviceStatus, requestJson);
//}
///////
/////// 控制设备
///////
///////
////public ResponsePackNew ControlDevice(List actionObjs)
////{
//// Dictionary d = new Dictionary();
//// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
//// d.Add("gatewayId", UserConfig.Instance.HomeGateway.gatewayId);//DriverLayer.Control.Ins.GatewayId);
//// d.Add("actions", actionObjs);
//// var requestJson = HttpUtil.GetSignRequestJson(d);
//// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_ControlDevice, requestJson);
////}
/////
///// 编辑设备信息
///// 绑定关系、名称、收藏
/////
/////
//public ResponsePackNew UpdataDevcieInfo(Common function)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("deviceId", function.deviceId);
// d.Add("name", function.Name);
// d.Add("collect", function.collect);
// d.Add("roomIds", function.roomIds);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditDevice, requestJson);
//}
/////
///// 更新设备绑定房间信息
/////
/////
//public ResponsePackNew UpdataDevcieBindRoomInfo(Function function)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("deviceId", function.deviceId);
// d.Add("roomIds", function.roomIds);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditDevice, requestJson);
//}
/////
///// 设备绑定房间
/////
//public ResponsePackNew BindDeviceToRoom(List deviceIds,List roomIds)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("deviceIds", deviceIds);
// d.Add("roomIds", roomIds);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_BindDeviceToRoom, requestJson);
//}
/////
///// 设备解绑房间
/////
//public string UnbindDeviceToRoom(string deviceId, string roomId)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("deviceIds", new List() { deviceId });
// d.Add("roomIds", new List() { roomId });
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_UnbindDeviceToRoom, requestJson).Code;
//}
/////
///// 设备名称修改
/////
//public string EditDeviceName(string deviceId, string deviceName)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("deviceId", deviceId);
// d.Add("name", deviceName);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditDeviceName, requestJson).Code;
//}
/////
///// 收藏设备
/////
//public ResponsePackNew CollectDevice(string deviceId)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("deviceIds",new List() { deviceId });
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CollectDevice, requestJson);
//}
/////
///// 取消收藏设备
/////
//public ResponsePackNew CancelCollectDevice(string deviceId)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("deviceIds", new List() { deviceId });
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CancelCollectDevice, requestJson);
//}
//#endregion
//#region Kaede --场景功能--------------------------
///
/// 获取场景列表
/// 房间ID可空,默认查询住宅下所有房间
///
/// 房间ID
///
public ResponsePackNew GetSceneList (string roomId = null)
{
Dictionary d = new Dictionary ();
d.Add ("homeId", UserConfig.Instance.CurrentRegion.Id);
if (roomId != null) {
d.Add ("roomId", roomId);
}
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.Api_Post_GetSecneList, requestJson);
}
/////
///// 获取场景详情
/////
///// 场景ID
/////
//public ResponsePackNew GetSceneInfo(string seceneId)
//{
// Dictionary d = new Dictionary();
// d.Add("userSceneIds",new List() { seceneId });
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetSecneInfo, requestJson);
//}
/////
///// 获取场景详情列表
/////
///// 场景ID
/////
//public ResponsePackNew GetSceneListInfo(List seceneIds)
//{
// Dictionary d = new Dictionary();
// d.Add("userSceneIds", seceneIds);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetSecneInfo, requestJson);
//}
/////
///// 添加场景
/////
/////
/////
//public ResponsePackNew AddScene (List sceneList)
//{
// Dictionary d = new Dictionary ();
// d.Add ("homeId", UserConfig.Instance.CurrentRegion.Id);
// d.Add ("scenes", sceneList);
// var requestJson = HttpUtil.GetSignRequestJson (d);
// var pack = HttpUtil.RequestHttpsPostFroHome (NewAPI.Api_Post_AddSecne, requestJson);
// Utlis.WriteLine ($"{pack.Data}");
// return pack;
//}
///
/// 全量同步场景
///
///
///
public ResponsePackNew SecneSyncList (List sceneList)
{
Dictionary d = new Dictionary ();
d.Add ("homeId", UserConfig.Instance.CurrentRegion.Id);
d.Add ("scenes", sceneList);
var requestJson = HttpUtil.GetSignRequestJson (d);
var pack = HttpUtil.RequestHttpsPostFroHome (NewAPI.Api_Post_Secne_SyncList, requestJson);
Utlis.WriteLine ($"{pack.Data}");
return pack;
}
///
/// 更新场景
///
///
///
public ResponsePackNew EditScene (List sceneList)
{
Dictionary d = new Dictionary ();
d.Add ("homeId", UserConfig.Instance.CurrentRegion.Id);
d.Add ("scenes", sceneList);
var requestJson = HttpUtil.GetSignRequestJson (d);
return HttpUtil.RequestHttpsPostFroHome (NewAPI.Api_Post_EditSecne, requestJson);
}
/////
///// 删除场景
/////
/////
//public string DeleteScene(string userSceneId)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("userSceneIds", new List() { userSceneId });
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_DeleteSecne, requestJson).Code;
//}
/////
///// 执行场景
/////
/////
//public string ExecuteScene(string userSceneId)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("userSceneIds", new List() { userSceneId });
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_ExecuteSecne, requestJson).Code;
//}
/////
///// 收藏场景
/////
/////
/////
//public string CollectScene(string userSceneId)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("userSceneIds", new List() { userSceneId });
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CollectScene, requestJson).Code;
//}
/////
///// 取消收藏场景
/////
/////
/////
//public string CancelCollectScene(string userSceneId)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("userSceneIds", new List() { userSceneId });
// var requestJson = HttpUtil.GetSignRequestJson(d);
// return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CancelCollectScene, requestJson).Code;
//}
//#endregion
//#region Kaede --房间功能--------------------------
/////
///// 获取房间列表
/////
///// 获取类型:ROOM\FLOOR;不输入返回全部
/////
//public ResponsePackNew GetRoomList(string GetType = "All")
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// if (GetType != "All")
// {
// d.Add("roomType", GetType);
// }
// d.Add("pageSize", "1000");
// var requestJson = HttpUtil.GetSignRequestJson(d);
// var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetRoomList, requestJson);
// return pack;
//}
/////
///// 添加房间\楼层
///// 楼层也属于房间
/////
/////
//public ResponsePackNew AddRoom(List rooms)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("rooms", rooms);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_AddRoom, requestJson);
// //var revData = Newtonsoft.Json.JsonConvert.DeserializeObject>(pack.Data.ToString());
// //if (revData != null)
// //{
// // SpatialInfo.CurrentSpatial.UpdateSpatialList(revData, OptionType.Update);
// //}
// return pack;
//}
/////
///// 修改房间信息
/////
/////
//public ResponsePackNew UpdateRoom(List rooms)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("rooms", rooms);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_UpdateRoom, requestJson);
// //var revData = Newtonsoft.Json.JsonConvert.DeserializeObject>(pack.Data.ToString());
// //if (revData != null)
// //{
// // SpatialInfo.CurrentSpatial.UpdateSpatialList(revData,OptionType.Update);
// //}
// return pack;
//}
/////
///// 删除房间
/////
/////
/////
//public ResponsePackNew DeleteRoom(List roomIds)
//{
// Dictionary d = new Dictionary();
// d.Add("homeId", UserConfig.Instance.CurrentRegion.RegionID);
// d.Add("ids", roomIds);
// var requestJson = HttpUtil.GetSignRequestJson(d);
// var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_DelRoom, requestJson);
// return pack;
//}
//#endregion
///
/// 修改设备备注
///
///
///
///
///
public ResponsePackNew EditDeviceName (string deviceId,string homeId,string name)
{
var d = new Dictionary ();
d.Add ("deviceId", deviceId);
d.Add ("homeId", homeId);
d.Add ("name", name);
var requestJson = HttpUtil.GetSignRequestJson (d);
var pack = HttpUtil.RequestHttpsPostFroHome (NewAPI.Api_Post_EditDeviceName, requestJson);
return pack;
}
}
}