/// <summary> /// 获取可用Ticket /// </summary> /// <param name="componentAppId"></param> /// <param name="authorizerAppid"></param> /// <param name="getNewTicket">是否强制重新获取新的Ticket</param> /// <returns></returns> public static JsApiTicketResult GetJsApiTicketResult(string componentAppId, string authorizerAppid, bool getNewTicket = false) { TryRegister(componentAppId, authorizerAppid); var accessTicketBag = TryGetItem(authorizerAppid); using (Cache.BeginCacheLock(LockResourceName + ".GetJsApiTicketResult", authorizerAppid))//同步锁 { if (getNewTicket || accessTicketBag.JsApiTicketExpireTime <= DateTime.Now) { //已过期,重新获取 var authorizerAccessToken = TryGetAuthorizerAccessToken(componentAppId, authorizerAppid); accessTicketBag.JsApiTicketResult = ComponentApi.GetJsApiTicket(authorizerAccessToken); accessTicketBag.JsApiTicketExpireTime = ApiUtility.GetExpireTime(accessTicketBag.JsApiTicketResult.expires_in); } } return(accessTicketBag.JsApiTicketResult); }
/// <summary> /// 获取可用Ticket /// </summary> /// <param name="componentAppId"></param> /// <param name="authorizerAppid"></param> /// <param name="getNewTicket">是否强制重新获取新的Ticket</param> /// <returns></returns> public static JsApiTicketResult GetJsApiTicketResult(string componentAppId, string authorizerAppid, bool getNewTicket = false) { TryRegister(componentAppId, authorizerAppid); var accessTicketBag = ItemCollection[authorizerAppid]; lock (accessTicketBag.Lock) { if (getNewTicket || accessTicketBag.JsApiTicketExpireTime <= DateTime.Now) { //已过期,重新获取 var authorizerAccessToken = TryGetAuthorizerAccessToken(componentAppId, authorizerAppid); accessTicketBag.JsApiTicketResult = ComponentApi.GetJsApiTicket(authorizerAccessToken); accessTicketBag.JsApiTicketExpireTime = DateTime.Now.AddSeconds(accessTicketBag.JsApiTicketResult.expires_in); } } return(accessTicketBag.JsApiTicketResult); }