public static CheckDataResult CheckData(string request) { var requestData = CheckFormat(request); if (requestData == null) { return(CheckDataResult.FailResult(ResultError(ResultCode.JsonParsingFailure, "报文解析失败"))); } if (requestData.Header.AccountId != CtripConfig.AccountId) { return(CheckDataResult.FailResult(ResultError(ResultCode.IncorrectAccountInformation, "携程账户信息不正确"))); } var isSign = CheckSign(requestData); if (!isSign) { return(CheckDataResult.FailResult(ResultError(ResultCode.SignatureError, "签名验证失败"))); } var requestBody = CheckRequestBodyForDecrypt(requestData.Body); if (string.IsNullOrEmpty(requestBody)) { return(CheckDataResult.FailResult(ResultError(ResultCode.JsonParsingFailure, "报文解析失败"))); } requestData.Body = requestBody; return(CheckDataResult.SuccessResult(requestData)); }
/// <summary> /// 上传文件 /// </summary> /// <param name="file"></param> /// <returns></returns> public JsonResult ImportData(HttpPostedFileBase file) { var checkResult = new CheckDataResult { Result = false }; if (file == null) { checkResult.ErrorMessages.Add("找不到上传的文件!"); return(Json(checkResult, JsonRequestBehavior.AllowGet)); } var fileName = file.FileName; var ext = fileName.Substring(fileName.LastIndexOf(".")); if (!ext.InStr(".txt", ".doc", ".docx", ".xls", ".xlsx", ".jpg", ".png", ".xmind", ".rar", ".zip")) { checkResult.ErrorMessages.Add("文件格式不正确,仅支持:txt、doc、xls、jpg、png、xmind、rar、zip文件!"); return(Json(checkResult, JsonRequestBehavior.AllowGet)); } var entity = new FilesDTO(); entity.file_name = fileName.Replace(ext, ""); entity.file_ext = ext; entity.file_key = Guid.NewGuid().ToString("N").ToUpper() + ext; entity.file_timestamp = DateTime.Now; byte[] fileBytes = null; fileBytes = new byte[file.ContentLength]; file.InputStream.Read(fileBytes, 0, file.ContentLength); entity.file_bytes = fileBytes; CacheHelper.SetCacheValue(entity.file_key, entity, 24 * 60); checkResult.Result = true; checkResult.Entity = new FilesDTO() { file_key = entity.file_key, file_name = entity.file_name }; return(Json(checkResult, JsonRequestBehavior.AllowGet)); }