//获取accesstoken public static bool LoginImmediately() { IntPtr pBuf; int iLength; string header = BuildHeaderParas("token"); int ret = HkSDK.OpenSDK_HttpSendWithWait(ApiUrl, header, "", out pBuf, out iLength); string returnstr = Marshal.PtrToStringAnsi(pBuf, iLength); //string accessToken = string.Empty; if (ret == 0) { JObject result = (JObject)JsonConvert.DeserializeObject(returnstr); if (result["result"]["code"].ToString() == "200") { HkApi.AccessToken = result["result"]["data"]["accessToken"].ToString(); Debug.WriteLine(HkApi.AccessToken); } else { Debug.WriteLine(result["result"]["code"].ToString()); } } return(ret == 0); }
//截图 public static bool CapturePicture(IntPtr sessionId, string fileName) { if (!String.IsNullOrWhiteSpace(fileName)) { return(HkSDK.OpenSDK_CapturePicture(sessionId, fileName) == 0 ? true : false); } return(false); }
//申请会话 public static IntPtr AllocSession() { IntPtr userID = Marshal.StringToHGlobalAnsi(userId); IntPtr sessionId = IntPtr.Zero; int sidLength = -1; bool flag = HkSDK.OpenSDK_AllocSession(msgHandler, userID, ref sessionId, ref sidLength, false, uint.MaxValue) == 0; //SessionIdstr = Marshal.PtrToStringAnsi(sessionId, sidLength); return(sessionId); }
//获取设备列表 返回jsonstr public static GetDevListResult GetCameraList() { IntPtr pBuf; int iLength; int ret = HkSDK.OpenSDK_Data_GetDevList(AccessToken, 0, 50, out pBuf, out iLength); string returnJsonStr = Marshal.PtrToStringAnsi(pBuf); GetDevListResult result = null; if (ret == 0) { result = (GetDevListResult)JsonConvert.DeserializeObject(returnJsonStr, typeof(GetDevListResult)); } //Marshal.FreeHGlobal(pBuf); return(result); }
//第三方登录 public unsafe static bool Login() { int ret = -1; try { string token = string.Empty; char * pToken = (char *)Marshal.StringToBSTR(token); int pLen = 0; ret = HkSDK.OpenSDK_Mid_Login(&pToken, &pLen); if (ret == 0) { AccessToken = Marshal.PtrToStringAnsi((IntPtr)pToken, pLen); AccessTokenLength = pLen; } } catch (Exception) { } return(ret == 0); }
//反初始化库 public static bool Close() { return(HkSDK.OpenSDK_FiniLib() == 0); }
//初始化库 public static bool Init() { return(HkSDK.OpenSDK_InitLib(AuthAddr, PlatformAddr, AppKey) == 0); }
//停止播放(预览) public static bool StopPlay(IntPtr SessionId) { CloseAllocion(SessionId);//每次播放结束会话 return(HkSDK.OpenSDK_StopRealPlay(SessionId, 0) == 0); }
//播放视频(预览) public static bool StartPlay(IntPtr hWnd, string cameraId, IntPtr sessionId) { return(HkSDK.OpenSDK_StartRealPlay(sessionId, hWnd, cameraId, AccessToken, videoQualityLevel, _SafeKey, AppKey, 0) == 0); }
//结束会话 public static bool CloseAllocion(IntPtr sid) { string sid1 = sid.ToString(); return(HkSDK.OpenSDK_FreeSession(sid1) == 0); }