/// <summary> /// 获取js 接口 Ticket /// 内部已经处理缓存 /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <WxGetJsTicketResp> GetJsTicketFromWxAsync(WxJsTicketType type) { var req = new OsHttpRequest { HttpMethod = HttpMethod.Get, AddressUrl = string.Concat(m_ApiUrl, "/cgi-bin/ticket/getticket?type=", type.ToString()) }; return(await RestCommonOffcialAsync <WxGetJsTicketResp>(req)); }
/// <summary> /// 获取js 接口 Ticket /// 内部已经处理缓存 /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <WxGetJsTicketResp> GetJsTicketAsync(WxJsTicketType type) { string key = string.Format(WxCacheKeysUtil.OffcialJsTicketKey, ApiConfig.AppId, type); var ticket = CacheUtil.Get <WxGetJsTicketResp>(key, ModuleNames.SocialCenter); if (ticket != null && ticket.expires_time > DateTime.Now) { return(ticket); } var req = new OsHttpRequest(); req.HttpMothed = HttpMothed.GET; req.AddressUrl = string.Concat(m_ApiUrl, string.Concat("cgi-bin/ticket/getticket?type=", type.ToString())); var ticketRes = await RestCommonOffcialAsync <WxGetJsTicketResp>(req); if (ticketRes.IsSuccess()) { ticketRes.expires_time = DateTime.Now.AddSeconds(ticketRes.expires_in); CacheUtil.AddOrUpdate(key, ticketRes, TimeSpan.FromSeconds(ticketRes.expires_in - 10), null, ModuleNames.SocialCenter); } return(ticketRes); }