/// <summary> /// AccessToken请求 /// </summary> private Deploy.CustomDTO.ResultDTO <string> GetTokenFromMemorySelf(AccessCertifDTO certif) { var ret = new Deploy.CustomDTO.ResultDTO <string> { ResultCode = 0, isSuccess = false }; var tokenStr = string.Empty; try { //直接从参数DTO中读取Token if (!certif.UseDeveloperId) { tokenStr = certif.AccessToken; LogHelper.Info(string.Format( "GetTokenFromMemory 参数accessCertif中已经包含AccessToken={0}", tokenStr)); ret.Data = tokenStr; ret.isSuccess = true; } else { var appId = certif.AppId; var appSecret = certif.AppSecret; //从缓存中读取到token if (WeChatMemoryCache.TryGetToken(appId, appSecret, ref tokenStr)) { LogHelper.Info(string.Format( "GetTokenFromMemory 从缓存中获取AccessToken={0}", tokenStr)); ret.Data = tokenStr; ret.isSuccess = true; } else //未能从缓存中读取到token { //调用微信接口获取token ret = GetTokenFromWx(appId, appSecret); if (ret.isSuccess) { WeChatMemoryCache.StorageToken(appId, appSecret, ret.Data); LogHelper.Info(string.Format( "GetTokenFromMemory 调用微信服务获取AccessToken={0}", tokenStr)); } } } } catch (Exception ex) { LogHelper.Error( string.Format("调用GetToken异常{0},参数UseDeveloperId:{1},AppId:{2},AppSecret:{3},AccessToken:{4}", ex.Message, certif.UseDeveloperId, certif.AppId, certif.AppSecret, certif.AccessToken), ex); ret.Message = ex.Message; } return(ret); }
private Deploy.CustomDTO.ResultDTO <string> GetTokenFromMemory(AccessCertifDTO certif) { if (certif == null) { return(new ResultDTO <string>()); } if (certif.IsAppWeChatSetting) { return(GetTokenFromMemoryByAppId(certif)); } else { return(GetTokenFromMemorySelf(certif)); } }
private Deploy.CustomDTO.ResultDTO <string> GetTokenFromMemoryByAppId(AccessCertifDTO certif) { Deploy.CustomDTO.ResultDTO <string> result = new ResultDTO <string>(); if (certif == null || certif.JhAppId == Guid.Empty) { return(result); } var facadeResult = WCPSV.Instance.GetWXAccessToken(certif.JhAppId); if (facadeResult != null && facadeResult.IsSuccess) { result.isSuccess = true; result.Data = facadeResult.Message; } return(result); }
/// <summary> /// 获取应用access_token /// </summary> /// <param name="certif"></param> /// <returns></returns> public Deploy.CustomDTO.ResultDTO<string> GetToken(AccessCertifDTO certif) { if (certif == null || certif.JhAppId == Guid.Empty) return new ResultDTO<string>(); return GetToken(certif.JhAppId); }