public JsonResult GetRealNameShareLinkId() { try { _log.Debug("GetRealNameShareLink Start"); var tokenId = CommonHelper.GetToken(Request.Form["TokenId"]); ShareLinkItem item = new ShareLinkItem() { id = Request.Form["Docid"], type = Request.Form["FileType"] }; IShareLinkAPIHelper helper = new ShareLinkAPIHelper(); long errorCode = 0; var realNameId = helper.GetRealNameShareLink(tokenId, item, out errorCode); if (errorCode > 0) { return(Json(new JsonModel { Success = true, StatusCode = errorCode })); } if (string.IsNullOrEmpty(realNameId)) { item.id = CommonHelper.DecodeUrl(item.id); CreatRealNameShareLinkModel model = new CreatRealNameShareLinkModel() { item = item }; realNameId = helper.CreatRealNameShareLink(tokenId, model, out errorCode); if (errorCode > 0) { return(Json(new JsonModel { Success = true, StatusCode = errorCode })); } } _log.Debug("GetRealNameShareLink End"); return(Json(new JsonModel { Success = true, StatusCode = errorCode, Data = realNameId })); } catch (Exception ex) { _log.Debug($"GetRealNameShareLink Exception: {ex.Message}"); return(Json(new JsonModel { Success = false, Message = ex.Message })); } }
public void CreatRealNameShareLink() { CreatRealNameShareLinkModel model = new CreatRealNameShareLinkModel() { item = new ShareLinkItem() { id = CommonHelper.EncodeUrl(TestData.fileId), type = "file" } }; var res = helper.CreatRealNameShareLink(TestData.access_token, model, out long code); Assert.IsNotNull(res); }
/// <summary> /// 创建实名共享 /// </summary> /// <returns>实名共享ID</returns> public string CreatRealNameShareLink(string token, CreatRealNameShareLinkModel model, out long errorCode) { try { var handler = new WebRequestHandler(); handler.ServerCertificateValidationCallback = delegate { return(true); }; using (var httpClient = new HttpClient(handler)) { httpClient.DefaultRequestHeaders.Add("Authorization", token); var json = JsonConvert.SerializeObject(model); var content = new StringContent(json, Encoding.UTF8, "application/json"); var res = httpClient.PostAsync($"{Constant.OAuth2Url}/api/shared-link/v1/document/realname", content).Result; var resStr = res.Content.ReadAsStringAsync().Result; int resCode = (int)res.StatusCode; // 若为错误返回码则抛出异常 if (resCode < 200 || resCode >= 300) { var errModel = JsonConvert.DeserializeObject <ErrorModel>(resStr); _log.Debug($"CreatRealNameShareLink Exception: {errModel.cause}, Code: {errModel.code}"); errorCode = errModel.code; if (errorCode == 403001063) { errorCode = 4030010632; } return(string.Empty); } if (resCode == 201) { errorCode = 0; return(JsonConvert.DeserializeObject <ShareLinkItem>(resStr).id); } errorCode = resCode; return(string.Empty); } } catch (Exception ex) { _log.Debug($"CreatRealNameShareLink Exception: {ex.Message}"); throw ex; } }
public void CreatRealNameShareLinkModelTest() { ShareLinkItem shareLinkItem = new ShareLinkItem() { id = "id", type = "type" }; var id = shareLinkItem.id; var type = shareLinkItem.type; Assert.IsTrue(id == "id"); Assert.IsTrue(type == "type"); CreatRealNameShareLinkModel creatRealNameShareLinkModel = new CreatRealNameShareLinkModel() { item = shareLinkItem }; var item = creatRealNameShareLinkModel.item; Assert.IsTrue(item == shareLinkItem); }