/// <summary> /// 调用接口创建目录 返回空值表示创建失败 /// </summary> /// <param name="Model"></param> /// <param name="cataname"></param> /// <returns></returns> public string CreateDirectory(W_PolyvInfo Model, string cataname, out string message) { message = ""; try { string url = string.Format("http://api.polyv.net/v2/video/{0}/addCata", Model.userid); string ts = ConvertDateTimeToInt(DateTime.Now).ToString().Substring(0, 13); string signn = string.Format("cataname={0}&catatype={3}&cataurl={4}&parentid=1&ptime={1}{2}", cataname, ts, Model.secretkey, "0", "cs"); string Sign = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(signn, "sha1"); string postData = string.Format("cataname={0}&catatype={3}&cataurl={4}&parentid=1&ptime={1}&sign={2}", cataname, ts, Sign, "0", "cs"); string result = ResponseToString(doPost(url, postData)); JavaScriptSerializer jss = new JavaScriptSerializer(); JsonModel Json = jss.Deserialize <JsonModel>(result); if (Json.code == 200 && Json.data != null) { return(Json.data.cataid); } else { message = Json.message; return(""); } } catch (Exception ex) { return(""); } }
/// <summary> /// 保利威视配置 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool SavePolyvInfo(PolyvInfoModel model) { if (model.System_Station_ID == 0) { throw new ApiException("机构ID不存在!"); } //自主类型 参数判断 if (model.PolyvSource == 1) { if (string.IsNullOrEmpty(model.userid)) { throw new ApiException("userid不能为空!"); } if (string.IsNullOrEmpty(model.writetoken)) { throw new ApiException("writetoken不能为空!"); } if (string.IsNullOrEmpty(model.readtoken)) { throw new ApiException("readtoken不能为空!"); } if (string.IsNullOrEmpty(model.secretkey)) { throw new ApiException("secretkey不能为空!"); } string refMessage = ""; //测试接口是否可用、参数是否正确 if (!CheckParameter(model.userid, model.writetoken, model.readtoken, model.secretkey, ref refMessage)) { throw new ApiException(refMessage); } } H_Station station = Orm.Single <H_Station>(x => x.ID == model.System_Station_ID); string StationName = station != null ? station.Name : ""; if (model.PolyvSource == 1) { model.Name = StationName; //自主的就读机构的名称 } string Message = string.Empty; //是否第一次设置 W_PolyvInfo_Detail polyvDetail = Orm.Single <W_PolyvInfo_Detail>(x => x.System_Station_ID == model.System_Station_ID); if (polyvDetail == null) //第一次设置 { if (model.PolyvSource == 0) //系统默认 { #region W_PolyvInfo Model = Orm.Single <W_PolyvInfo>(x => x.System_Station_ID == 0); //读主表默认 if (model == null) { throw new ApiException("未找到对应的默认配置数据!"); } //调用接口创建目录 string cataid = CreateDirectory(Model, StationName, out Message); //创建目录失败 if (string.IsNullOrEmpty(cataid)) { throw new ApiException("创建目录失败!" + Message); } else { //添加详细 return(SavePolyvDetail(true, model.System_Station_ID, Model.ID, cataid, model.Valid, model.PolyvSource)); } #endregion } else if (model.PolyvSource == 1) //自主类型 { #region W_PolyvInfo Model = Orm.Single <W_PolyvInfo>(x => x.System_Station_ID == model.System_Station_ID); //读主表配置 if (Model == null) //主表为空 { W_PolyvInfo polyv = new W_PolyvInfo(); polyv.System_Station_ID = model.System_Station_ID; polyv.Name = model.Name; polyv.userid = model.userid; polyv.writetoken = model.writetoken; polyv.readtoken = model.readtoken; polyv.secretkey = model.secretkey; polyv.AddTime = DateTime.Now; int polyv_id = (int)Orm.Insert(polyv, true); if (polyv_id > 0) { //调用接口创建目录 string cataid = CreateDirectory(polyv, StationName, out Message); //创建目录失败 if (string.IsNullOrEmpty(cataid)) { throw new ApiException("创建目录失败!" + Message); } else { //添加详细 return(SavePolyvDetail(true, polyv.System_Station_ID, polyv_id, cataid, model.Valid, model.PolyvSource)); } } else { throw new ApiException("设置不成功,设置主表添加异常!"); } } else { //调用接口创建目录 string cataid = CreateDirectory(model, StationName, out Message); //创建目录失败 if (string.IsNullOrEmpty(cataid)) { throw new ApiException("创建目录失败!" + Message); } else { //直接修改明细 return(SavePolyvDetail(true, model.System_Station_ID, Model.ID, cataid, model.Valid, model.PolyvSource)); } } #endregion } else { throw new ApiException("设置不成功,账号类型不正确!"); } } else //不是第一次设置 { if (model.PolyvSource == 0) //系统默认 { #region W_PolyvInfo Model = Orm.Single <W_PolyvInfo>(x => x.System_Station_ID == 0); //读主表默认 if (model == null) { throw new ApiException("未找到对应的默认配置数据!"); } //读详细表 W_PolyvInfo_Detail D_Model = Orm.Single <W_PolyvInfo_Detail>(x => x.System_Station_ID == model.System_Station_ID); if (D_Model != null) { //不创建目录 直接修改详细 return(SavePolyvDetail(false, D_Model.System_Station_ID, Model.ID, D_Model.cataid, model.Valid, model.PolyvSource)); } else { throw new ApiException("未找到对应的明细配置数据!"); } #endregion } else if (model.PolyvSource == 1) //自主类型 { #region W_PolyvInfo Model = Orm.Single <W_PolyvInfo>(x => x.System_Station_ID == model.System_Station_ID); //读主表配置 if (Model == null) //主表为空 { W_PolyvInfo polyv = new W_PolyvInfo(); polyv.System_Station_ID = model.System_Station_ID; polyv.Name = model.Name; polyv.userid = model.userid; polyv.writetoken = model.writetoken; polyv.readtoken = model.readtoken; polyv.secretkey = model.secretkey; polyv.AddTime = DateTime.Now; int polyv_id = (int)Orm.Insert(polyv, true); if (polyv_id > 0) { //调用接口创建目录 string cataid = CreateDirectory(polyv, StationName, out Message); //创建目录失败 if (string.IsNullOrEmpty(cataid)) { throw new ApiException("创建目录失败!" + Message); } else { //修改详细 return(SavePolyvDetail(false, polyv.System_Station_ID, polyv_id, cataid, model.Valid, model.PolyvSource)); } } else { throw new ApiException("设置不成功,设置主表添加异常!"); } } else //主表不为空,修改 { //数据是否修改 bool HasChange = false; if (model.userid != Model.userid) { HasChange = true; } if (model.writetoken != Model.writetoken) { HasChange = true; } if (model.readtoken != Model.readtoken) { HasChange = true; } if (model.secretkey != Model.secretkey) { HasChange = true; } W_PolyvInfo_Detail D_Model = Orm.Single <W_PolyvInfo_Detail>(x => x.System_Station_ID == model.System_Station_ID); //读详细表 if (HasChange) //如果数据有变更 { //调用接口创建目录 string cataid = CreateDirectory(model, StationName, out Message); //创建目录失败 if (string.IsNullOrEmpty(cataid)) { throw new ApiException("创建目录失败!" + Message); } else { //修改主表 if (SqlMapper.Update("UpdatePolyvInfo", new { Name = model.Name, userid = model.userid, writetoken = model.writetoken, readtoken = model.readtoken, secretkey = model.secretkey, System_Station_ID = model.System_Station_ID, ID = Model.ID }) > 0) { //修改详细 return(SavePolyvDetail(false, D_Model.System_Station_ID, Model.ID, cataid, model.Valid, model.PolyvSource)); } else { throw new ApiException("主表修改失败!" + Message); } } } else { //直接修改明细 return(SavePolyvDetail(false, D_Model.System_Station_ID, Model.ID, D_Model.cataid, model.Valid, model.PolyvSource)); } } #endregion } else { throw new ApiException("设置不成功,账号类型不正确!"); } } }