123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- using LYFZ.WXLibrary;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- namespace LYFZ.WeixinServers
- {
- /// <summary>
- /// 全局性缓存;
- /// </summary>
- public static class GlobalCache
- {
- #region 数据
- // 几个重要的缓存数据表;
- public static DataTable DT_AuthorizeApp { get; set; } = new DataTable();
- public static DataTable DT_IndustryInfo { get; set; } = new DataTable();
- public static DataTable DT_EnterpriseInfo { get; set; } = new DataTable();
- public static DataTable DT_AppTypeInfo { get; set; } = new DataTable();
- public static DataTable DT_ServerInfo { get; set; } = new DataTable();
- public static DataTable DT_EnterpriseAppEntry { get; set; } = new DataTable();
- public static DataTable DT_KfParticularsInfo { get; set; } = new DataTable();
- #region dal
- // dal;
- public static LoginDal.app_authorization DalAppAuthorize = new LoginDal.app_authorization();
- public static LoginDal.industry DalIndustry = new LoginDal.industry();
- public static LoginDal.enterprise DalEnterprise = new LoginDal.enterprise();
- public static LoginDal.app_type DalAppType = new LoginDal.app_type();
- public static LoginDal.server_entry DalServer = new LoginDal.server_entry();
- public static LoginDal.enterprise_app_entry DalEnterpriseAppEntry = new LoginDal.enterprise_app_entry();
- public static LoginDal.kf_particulars DalKfParticulars = new LoginDal.kf_particulars();
- #endregion
- #endregion
- #region 刷新缓存数据
- public static void Refresh_Industry()
- {
- DataSet ds = DalIndustry.GetAllList("id");
- lock(DT_IndustryInfo)
- {
- try
- {
- DT_IndustryInfo.Rows.Clear();
- DT_IndustryInfo.Dispose();
- DT_IndustryInfo = null;
- }
- catch
- {
- }
- DT_IndustryInfo = ds.Tables[0];
- DT_IndustryInfo.PrimaryKey = new DataColumn[] { DT_IndustryInfo.Columns["ind_name"] };
- }
- }
- public static void Refresh_AppType()
- {
- DataSet ds = DalAppType.GetAllList("id");
- lock (DT_AppTypeInfo)
- {
- try
- {
- DT_AppTypeInfo.Rows.Clear();
- DT_AppTypeInfo.Dispose();
- DT_AppTypeInfo = null;
- }
- catch
- {
- }
- DT_AppTypeInfo = ds.Tables[0];
- DT_AppTypeInfo.PrimaryKey = new DataColumn[] { DT_AppTypeInfo.Columns["app_type_name"] };
- }
- }
- public static void Refresh_MsgServer()
- {
- DataSet ds = DalServer.GetAllList("id");
- lock (DT_ServerInfo)
- {
- try
- {
- DT_ServerInfo.Rows.Clear();
- DT_ServerInfo.Dispose();
- DT_ServerInfo = null;
- }
- catch
- {
- }
- DT_ServerInfo = ds.Tables[0];
- DT_ServerInfo.PrimaryKey = new DataColumn[] { DT_ServerInfo.Columns["server_ip"] };
- }
- }
- public static void Refresh_Enterprise()
- {
- DataSet ds = DalEnterprise.GetAllList("id");
- lock (DT_EnterpriseInfo)
- {
- try
- {
- DT_EnterpriseInfo.Rows.Clear();
- DT_EnterpriseInfo.Dispose();
- DT_EnterpriseInfo = null;
- }
- catch
- {
- }
- DT_EnterpriseInfo = ds.Tables[0];
- DT_EnterpriseInfo.PrimaryKey = new DataColumn[] { DT_EnterpriseInfo.Columns["ent_name"] };
- }
- }
- public static void Refresh_EntAppEntry()
- {
- DataSet ds = DalEnterpriseAppEntry.GetAllList("id");
- lock (DT_EnterpriseAppEntry)
- {
- try
- {
- DT_EnterpriseAppEntry.Rows.Clear();
- DT_EnterpriseAppEntry.Dispose();
- DT_EnterpriseAppEntry = null;
- }
- catch
- {
- }
- DT_EnterpriseAppEntry = ds.Tables[0];
- DT_EnterpriseAppEntry.PrimaryKey = new DataColumn[] { DT_EnterpriseAppEntry.Columns["id"] };
- }
- }
- public static void Refresh_kfParticulars()
- {
- DataSet ds = DalKfParticulars.GetAllList("id");
- lock (DT_KfParticularsInfo)
- {
- try
- {
- DT_KfParticularsInfo.Rows.Clear();
- DT_KfParticularsInfo.Dispose();
- DT_KfParticularsInfo = null;
- }
- catch
- {
- }
- DT_KfParticularsInfo = ds.Tables[0];
- DT_KfParticularsInfo.PrimaryKey = new DataColumn[] { DT_KfParticularsInfo.Columns["kf_account"] };
- }
- }
- public static void Refresh_AppAuth()
- {
- DataSet ds = DalAppAuthorize.GetAllList("id");
- lock (DT_AuthorizeApp)
- {
- try
- {
- DT_AuthorizeApp.Rows.Clear();
- DT_AuthorizeApp.Dispose();
- DT_AuthorizeApp = null;
- }
- catch
- {
- }
- DT_AuthorizeApp = ds.Tables[0];
- DT_AuthorizeApp.PrimaryKey = new DataColumn[] { DT_AuthorizeApp.Columns["app_id"] };
- // 添加到字典中;
- Refresh_Dictionary_AppAuth(DT_AuthorizeApp);
- }
- }
- #region appId增删改查函数
- public static void Refresh_Dictionary_AppAuth(DataTable DT_AuthorizeApp)
- {
- foreach (DataRow row in DT_AuthorizeApp.Rows)
- {
- LoginModel.app_authorization model = DalAppAuthorize.DataRowToModel(row);
- AddAuthorizedAPPIDHand(model);
- }
- }
- public static void AddAuthorizedAPPIDHand(LoginModel.app_authorization model)
- {
- lock (LYFZ.WXLibrary.OpenPlatformConfig.AuthorizedAPPIDHandleList)
- {
- if (!LYFZ.WXLibrary.OpenPlatformConfig.AuthorizedAPPIDHandleList.ContainsKey(model.app_id) && model.authorize_status == 1)
- {
- LYFZ.WXLibrary.AuthorizedAPPIDHandle authAPPIDHandle =
- new LYFZ.WXLibrary.AuthorizedAPPIDHandle(model.authorization_info, "CompanyName", model.authorize_status, model.refresh_token_time);
- authAPPIDHandle.EventEvent_AuthorizerRefreshToken += authAPPIDHandle_EventEvent_AuthorizerRefreshToken;
- LYFZ.WXLibrary.OpenPlatformConfig.AuthorizedAPPIDHandleList.Add(model.app_id, authAPPIDHandle);
- }
- }
- }
- static void authAPPIDHandle_EventEvent_AuthorizerRefreshToken(EventAuthorizerRefreshToken e)
- {
- LoginModel.app_authorization model = (LoginModel.app_authorization)DalAppAuthorize.GetModelObject("authorizer_appid", e.Appid);
- if (model != null && model.id > 0)
- {
- var authorizationObj = LYFZ.Weixin.SDK.BasicAPI.JsonToDynamic(model.authorization_info);
- authorizationObj.authorization_info.authorizer_access_token = e.Authorizer_access_token;
- authorizationObj.authorization_info.expires_in = e.Expires_in;
- authorizationObj.authorization_info.authorizer_refresh_token = e.Authorizer_refresh_token;
- model.refresh_token_time = e.RefreshTokenTime;
- model.authorizer_access_token = e.Authorizer_access_token;
- model.expires_in = e.Expires_in;
- model.authorizer_refresh_token = e.Authorizer_refresh_token;
- model.authorization_info = authorizationObj.ToString();
- DalAppAuthorize.Update(model);
- }
- }
- public static void RemoveAppObject(string authorizer_Appid, string CompanyName)
- {
- LYFZ.WXLibrary.AuthorizedAPPIDHandle authAPPIDHandle = null;
- if (OpenPlatformConfig.AuthorizedAPPIDHandleList.ContainsKey(authorizer_Appid))
- {
- authAPPIDHandle = OpenPlatformConfig.AuthorizedAPPIDHandleList[authorizer_Appid];
- //authAPPIDHandle.JMGDomainName = JMGDomainName;
- authAPPIDHandle.CompanyName = CompanyName;
- LoginModel.app_authorization model =
- (LoginModel.app_authorization)DalAppAuthorize.GetModelObject("authorizer_appid", authorizer_Appid);
- if (model != null && model.id > 0)
- {
- //model.JMGDomainName = authAPPIDHandle.JMGDomainName;
- // model.CompanyName = authAPPIDHandle.CompanyName;
- //LYFZ.WXLibrary.CommonHandleClass.WriteLog("更新授权处理对象中的加密锁域名:authorizer_Appid=" + authorizer_Appid + " & JMGDomainName=" + Authorization_infoModel.JMGDomainName, "-2", Global.LogsDongleDomainList);
- // Authorization_infoDal.Update(Authorization_infoModel);
- // UpdateAuthorizationInfoDaTable(authorizer_Appid, Authorization_infoModel);
-
- }
- }
- }
- public static void UpdateAppObject()
- {
- }
- #endregion
- #endregion
- #region 函数
- public static LoginModel.enterprise GetEnterpriseModel(string ent_id)
- {
- bool find = false;
- LoginModel.enterprise model = new LoginModel.enterprise();
- foreach (DataRow dr in DT_EnterpriseInfo.Rows)
- {
- model = DalEnterprise.DataRowToModel(dr);
- if (model.ent_id == ent_id)
- {
- find = true;
- break;
- }
- }
- return find ? model : null;
- }
- #region 公用普通函数
- public static string GuidString()
- {
- return Guid.NewGuid().ToString("N");
- }
- public static LoginModel.user GetUserInfo(string strUser, string strUserPsw)
- {
- LoginDal.user dal = new LoginDal.user();
- LoginModel.user model = new LoginModel.user();
- DataSet ds = dal.GetList("user_account ='" + strUser + "' and user_psw = '" + strUserPsw + "'", "id");
- if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- {
- return model = dal.DataRowToModel(ds.Tables[0].Rows[0]);
- }
- else
- {// 没有该账号记录;
- return null;
- }
- }
- public static long DateTimeToTimeStamp(DateTime dt)
- {
- DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
- return (long)(dt - startTime).TotalSeconds;// 相差秒数,则为Unix时间戳;
- }
- public static long DateTimeToJSTimeStamp(DateTime dt)
- {
- DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
- return (long)(dt - startTime).TotalMilliseconds;// 相差秒数,则为JavaScript时间戳;
- }
- public static DateTime JSTimeStampToDateTime(long jsTimeStamp)
- {
- //DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1)).AddMilliseconds(jsTimeStamp);
- //DateTime dt = startTime.AddMilliseconds(jsTimeStamp);
- return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(jsTimeStamp);
- }
- public static DateTime TimeStampToDateTime(long timeStamp)
- {
- return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(timeStamp);
- }
- #endregion
- #endregion
- }
- }
|