public CMCResponse SearchSystemAppSetting(dynamic obj) { AppSettingInfo appInfo = SystemFactory.Instance.GetUseAppConfig(Convert.ToInt32(obj)); Response.data = appInfo; return(Response); }
//更新应用 public CMCResponse Update(CMCRequest req) { AppSettingInfo info = JsonConvert.DeserializeObject <AppSettingInfo>(req.Data); SystemFactory.Instance.Update(info); Log("{\"LogMenu\":\"系统管理\",\"LogAction\":\"修改应用程序[" + info.AppSettingID + "]\"}", this.UserName, this.IP); return(Response); }
public GetTokenResponse GetToken(GetTokenRequest request) { GetTokenResponse response = new GetTokenResponse(); response.IsTrue = false; response.Status = 0; if (request != null) { try { if (string.IsNullOrEmpty(request.AppId) || string.IsNullOrEmpty(request.Secret) || string.IsNullOrEmpty(request.Session_Id)) { response.Status = 0; response.Msg = "请求参数有误,请检查!"; } else { //获取三方APP信息 AppSettingInfo app = SystemFactory.Instance.GetSystemAppConfig(request.AppId, request.Secret); if (app != null) { if (app.AppStatus == AppStatus.Reviewed) { //更新Token,同时更新过期时间) string newToken = SystemFactory.Instance.UpdateTokenInfo(app); response.IsTrue = true; response.Access_Token = newToken; response.Status = 1; response.Msg = "请求成功!"; response.Expires_In = 7200; response.CorpCode = app.CorpCode; response.SubCorpCode = app.SubCorpCode; response.CorpName = app.CorpName; } else { response.Msg = "请联系管理员审批系统!"; } } else { response.Msg = "该APP未在码中心注册,或密钥有误!请重试或联系管理员"; } } } catch (Exception exception) { response.Msg = exception.Message; } } else { response.Msg = "非法请求,请重试!"; } return(response); }
public GetApplicationResponse GetApplications(GetApplicationRequest request) { GetApplicationResponse response = new GetApplicationResponse(); response.IsTrue = false; response.Status = 0; if (request != null) { try { //验证Token string tokenMsg = ""; AppSettingInfo app = ApiHelper.VerifyTokenAndGetApp(request.Token, out tokenMsg); if (app != null) { //AES验证签名 if (ApiHelper.AESEncrypt(request.Token, request.TimeStamp, app.Seed) != request.Sign) { response.Msg = "签名验证不通过!"; return(response); } //验证API访问权限 if (ApiHelper.InterfaceRightCheck(app.AppSettingID)) { response.Msg = "无访问接口权限,请联系管理员"; return(response); } List <AppSettingInfoSimple> appList = SystemFactory.Instance.GetAllAppConfig(); response.IsTrue = true; response.Status = 1; response.Msg = "请求成功"; response.Data = appList; } else { response.Msg = tokenMsg; } } catch (Exception ex) { response.Msg = ex.Message; } } else { response.Msg = "非法请求,请重试!"; } return(response); }
public void Update(AppSettingInfo info) { Library.Data.SqlEntry.KeyValueCollection keys = new Library.Data.SqlEntry.KeyValueCollection(); keys.Add(new Library.Data.SqlEntry.KeyValue("CorpCode", info.CorpCode)); keys.Add(new Library.Data.SqlEntry.KeyValue("CorpName", info.CorpName)); keys.Add(new Library.Data.SqlEntry.KeyValue("SubCorpCode", info.SubCorpCode)); keys.Add(new Library.Data.SqlEntry.KeyValue("Secret", info.Secret)); keys.Add(new Library.Data.SqlEntry.KeyValue("AppStatus", info.AppStatus)); keys.Add(new Library.Data.SqlEntry.KeyValue("AppID", info.AppID)); keys.Add(new Library.Data.SqlEntry.KeyValue("IsAutoAudit", info.IsAutoAudit)); keys.Add(new Library.Data.SqlEntry.KeyValue("Seed", info.Seed)); dbContext.Update <AppSettingInfo>(keys, CK.K["AppSettingID"].Eq(info.AppSettingID)); }
public string UpdateTokenInfo(AppSettingInfo info) { TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0); string timeSign = Convert.ToInt64(ts.TotalSeconds).ToString(); byte[] bytes = Encoding.Default.GetBytes(timeSign); //Token info.Token = GetMd5Hash(info.Secret + "CMC") + Convert.ToBase64String(bytes); //新过期时间 info.TokenExpireDate = DateTime.Now.AddHours(2); dbContext.Save(info); return(info.Token); }
public virtual void Save(IChromelyConfiguration config) { try { if (_chromelyDynamic == null || _chromelyDynamic.Empty || _chromelyDynamic.Dictionary == null || _chromelyDynamic.Dictionary.Count == 0) { return; } var appSettingsFile = DataPath; if (string.IsNullOrWhiteSpace(appSettingsFile)) { appSettingsFile = AppSettingInfo.GetSettingsFilePath(config.Platform, AppName, true); } if (appSettingsFile == null) { return; } using (StreamWriter streamWriter = File.CreateText(appSettingsFile)) { try { var options = new JsonSerializerOptions(); options.ReadCommentHandling = JsonCommentHandling.Skip; options.AllowTrailingCommas = true; var jsonDic = JsonSerializer.Serialize(_chromelyDynamic.Dictionary, options); streamWriter.Write(jsonDic); Logger.Instance.Log.LogInformation("AppSettings FileName:" + appSettingsFile); } catch (Exception exception) { Logger.Instance.Log.LogWarning(exception.ToString()); Logger.Instance.Log.LogWarning("If this is about cycle was detecttion please see - https://github.com/dotnet/corefx/issues/41288"); } } } catch (Exception exception) { Logger.Instance.Log.LogError(exception, exception.Message); } }
private static void DeleteConfigFile(IChromelyConfiguration config) { try { var appSettingsFile = AppSettingInfo.GetSettingsFilePath(config.Platform, config.AppName ?? "chromely"); if (!string.IsNullOrWhiteSpace(appSettingsFile)) { if (File.Exists(appSettingsFile)) { File.Delete(appSettingsFile); } } } catch { } }
public void Add(string data, bool isAdmin) { AppSettingInfo config = JsonConvert.DeserializeObject <AppSettingInfo>(data); if (isAdmin) { config.AppStatus = AppStatus.Reviewed; } config.CreatedDate = config.ModifiedDate = DateTime.Now; config.TokenExpireDate = DateTime.Now.AddHours(2); //时间戳 TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0); string timeSign = Convert.ToInt64(ts.TotalSeconds).ToString(); byte[] bytes = Encoding.Default.GetBytes(timeSign); //Token config.Token = GetMd5Hash(config.Secret + config.Seed) + Convert.ToBase64String(bytes); dbContext.Save(config); }
public virtual void Save(IChromelyConfiguration config) { try { if (_chromelyDynamic == null || _chromelyDynamic.Empty) { return; } var appSettingsFile = DataPath; if (string.IsNullOrWhiteSpace(appSettingsFile)) { appSettingsFile = AppSettingInfo.GetSettingsFilePath(config.Platform, AppName, true); } if (appSettingsFile == null) { return; } using (StreamWriter streamWriter = File.CreateText(appSettingsFile)) { var options = new JsonSerializerOptions(); options.ReadCommentHandling = JsonCommentHandling.Skip; options.AllowTrailingCommas = true; var jsonDic = JsonSerializer.Serialize(_chromelyDynamic.Dictionary, options); streamWriter.Write(jsonDic); Logger.Instance.Log.Info("AppSettings FileName:" + appSettingsFile); } } catch (Exception exception) { Logger.Instance.Log.Error(exception); } }
public virtual void Read(IChromelyConfiguration config) { try { var appSettingsFile = AppSettingInfo.GetSettingsFilePath(config.Platform, AppName); if (appSettingsFile == null) { return; } var info = new FileInfo(appSettingsFile); if ((info.Exists) && info.Length > 0) { using (StreamReader jsonReader = new StreamReader(appSettingsFile)) { string json = jsonReader.ReadToEnd(); var options = new JsonSerializerOptions(); options.ReadCommentHandling = JsonCommentHandling.Skip; options.AllowTrailingCommas = true; var settingsJsonElement = JsonSerializer.Deserialize <JsonElement>(json, options); var settingsDic = JsonToDictionary(settingsJsonElement); _chromelyDynamic = new ChromelyDynamic(settingsDic); } } if (File.Exists(appSettingsFile)) { DataPath = appSettingsFile; } } catch (Exception exception) { Logger.Instance.Log.LogError(exception, exception.Message); } }