public async Task <StrResp> GetAccessToken(IAppSecret appConfig) { var key = string.Concat(_AccessCacheKey, appConfig); var accessTokenRes = await CacheHelper.GetAsync <WechatAccessTokenResp>(key); if (accessTokenRes != null) { return(new StrResp(accessTokenRes.access_token)); } accessTokenRes = await new WechatAccessTokenReq(appConfig).ExecuteAsync(); if (!accessTokenRes.IsSuccess()) { return(new StrResp().WithResp(accessTokenRes)); } await CacheHelper.SetAbsoluteAsync(key, accessTokenRes, TimeSpan.FromSeconds(accessTokenRes.expires_in - 60 * 5), "OSS.Clients.Platform.Wechat");// 按照返回的过期时间提前5分钟过期 return(new StrResp(accessTokenRes.access_token)); }
public async Task <StrResp> GetJsTicket(WechatJsTicketType type, IAppSecret appConfig) { var key = string.Concat(jsTicketCacheKey, appConfig.app_id); var jsTicketRes = await CacheHelper.GetAsync <WechatJsTicketResp>(key); if (jsTicketRes != null) { return(new StrResp(jsTicketRes.ticket)); } jsTicketRes = await new WechatJsTicketReq(type) .SetContextConfig(appConfig) .ExecuteAsync(); if (!jsTicketRes.IsSuccess()) { return(new StrResp().WithResp(jsTicketRes)); } // 按照返回的过期时间提前5分钟过期 await CacheHelper.SetAbsoluteAsync(key, jsTicketRes, TimeSpan.FromSeconds(jsTicketRes.expires_in - 60 * 5), "OSS.Clients.Platform.Wechat"); return(new StrResp(jsTicketRes.ticket)); }
/// <summary> /// 设置当前请求对应的秘钥配置信息 /// </summary> /// <param name="req"></param> /// <param name="appConfig"></param> /// <returns></returns> public static TReq SetContextConfig <TReq>(this TReq req, IAppSecret appConfig) where TReq : WechatBaseReq { req.app_config = appConfig; return(req); }
//private IAppSecret m_appConfig; public WechatAccessTokenReq(IAppSecret appconfig) : base(HttpMethod.Get) { this.app_config = appconfig; }