using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Net;
|
using HDL_ON.DAL.Server;
|
using HDL_ON.UI.UI2.PersonalCenter.PirDevice;
|
using Newtonsoft.Json.Linq;
|
using Shared;
|
|
namespace HDL_ON.UI.UI2.FuntionControlView.Video
|
{
|
|
public class VideoSend
|
{
|
/// <summary>
|
/// 检查住宅是否绑定丰林,并获取门口机列表
|
/// </summary>
|
/// <returns></returns>
|
public static ResponsePackNew GetVideo()
|
{
|
var jObject = new JObject { { "homeId", PirSend.HomeId } };
|
var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_FL_Check);
|
return responsePackNew;
|
}
|
/// <summary>
|
/// 获取通话记录
|
/// </summary>
|
/// <returns></returns>
|
public static ResponsePackNew GetCall(string flBindId)
|
{
|
var jObject = new JObject { { "homeId", PirSend.HomeId }, { "flBindId", flBindId }, { "pageSize", int.MaxValue } };
|
var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_FL_GetCallList);
|
return responsePackNew;
|
}
|
/// <summary>
|
/// 获取门口机列表(1室内机,2室外机,3围墙机,4管理机,5二次确认机)
|
/// </summary>
|
public static List<FlVideo> GetVideoInfoList(VideoClouds video)
|
{
|
List<FlVideo> eSVideoInfosList = new List<FlVideo>();
|
var jobject = new JObject();
|
jobject.Add("cmtID", video.flCmtId);
|
jobject.Add("unitno", video.flBuildingId);
|
jobject.Add("method", "getUUIDList");
|
try
|
{
|
var str = HttpWebRequest(NewAPI.API_POST_FL_List, jobject.ToString(), "POST");
|
if (string.IsNullOrEmpty(str))
|
{
|
return eSVideoInfosList;
|
}
|
var json = JObject.Parse(str);
|
if (json == null)
|
{
|
return eSVideoInfosList;
|
}
|
if (json["resCode"].ToString() != "0")
|
{
|
return eSVideoInfosList;
|
}
|
eSVideoInfosList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FlVideo>>(json["list"].ToString());
|
|
}
|
catch { }
|
return eSVideoInfosList;
|
}
|
/// <summary>
|
/// 上报动态开锁密码(注意:密码有可能延时1分钟生效)
|
/// </summary>
|
public static void GetQRcode(FrameLayout frame, VideoClouds video, Action<bool, string> action)
|
{
|
///标记是否成功
|
bool if_bool = false;
|
//临时密码
|
string pwd = VideoMethod.GetCode();
|
var jobject = new JObject(); jobject.Add("communityID", video.flCmtId);//社区ID
|
jobject.Add("fromTime", VideoMethod.GetCurrentTimeStamp());//开始时间
|
jobject.Add("validTime", VideoMethod.GetTomorrowTimeStamp());//有效时间
|
jobject.Add("unitno", video.flBuildingId);//单元号
|
jobject.Add("roomno", video.flRoomId);//房间号
|
jobject.Add("code", pwd); jobject.Add("userKey", video.id); jobject.Add("timestamp", VideoMethod.GetCurrentTimeStamp()); jobject.Add("secretKey", video.flSecretKey); jobject.Add("method", "setdynamicpwd"); jobject.Add("numTimes", "5");
|
//加载log
|
Loading loading = new Loading();
|
frame.AddChidren(loading);
|
loading.Start();
|
new System.Threading.Thread(() =>
|
{
|
try
|
{
|
var str = HttpWebRequest(NewAPI.API_POST_FL_QRcode, jobject.ToString(), "POST");
|
if (!string.IsNullOrEmpty(str))
|
{
|
var json = JObject.Parse(str);
|
if (json != null)
|
{
|
var stateCode = json["status"].ToString();
|
if (stateCode == "0")
|
{
|
if_bool = true;
|
}
|
}
|
}
|
}
|
catch { }
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
loading.Hide();
|
action(if_bool, pwd);
|
|
});
|
}
|
|
})
|
{ IsBackground = true }.Start();
|
}
|
/// <summary>
|
/// 下载图片
|
/// </summary>
|
public static void GetIcon(FrameLayout frame,string url)
|
{
|
Loading loading = new Loading();
|
frame.AddChidren(loading);
|
loading.Start();
|
new System.Threading.Thread(() =>
|
{
|
try
|
{
|
var responsePackNew = RequestServerhomeId(null, url);
|
}
|
catch { }
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
loading.Hide();
|
|
});
|
}
|
|
})
|
{ IsBackground = true }.Start();
|
}
|
/// <summary>
|
/// 请求服务器的方法(支持请求方式为POST/GET)
|
/// </summary>
|
/// <param name="getUrl">请求的地址</param>
|
/// <param name="str">请求数据</param>
|
/// <param name="method">请求方式为POST/GET</param>
|
/// <param name="second">超时时间</param>
|
/// <returns></returns>
|
public static string HttpWebRequest(string getUrl, string str, string method, int second = 3)
|
{
|
try
|
{
|
HttpWebRequest request = WebRequest.Create(getUrl) as HttpWebRequest; //创建请求
|
request.Method = method; //请求方式为POST/GET
|
request.ContentType = "application/json";
|
request.Timeout = second * 1000;//超时时间
|
if (method == "POST")
|
{
|
byte[] jsonbyte = System.Text.Encoding.UTF8.GetBytes(str);
|
request.ContentLength = jsonbyte.Length;
|
Stream postStream = request.GetRequestStream();
|
postStream.Write(jsonbyte, 0, jsonbyte.Length);
|
postStream.Close();
|
}
|
//发送请求并获取相应回应数据
|
HttpWebResponse res;
|
try
|
{
|
res = (HttpWebResponse)request.GetResponse();
|
}
|
catch (WebException ex)
|
{
|
res = (HttpWebResponse)ex.Response;
|
}
|
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
|
string content = sr.ReadToEnd(); //获得响应字符串
|
return content;
|
}
|
catch
|
{
|
return null;
|
}
|
}
|
/// <summary>
|
///请求服务器(与住宅有关:例如;homeId)
|
/// </summary>
|
/// <returns></returns>
|
public static ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 20)
|
{
|
var requestJson = HttpUtil.GetSignRequestJson(o);
|
return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout);
|
|
}
|
|
|
}
|
class FlResponsePackNew
|
{//
|
public string status = string.Empty;
|
public string desc = string.Empty;
|
|
}
|
}
|