zhengyuxuan
2025-03-24 d68803c51b977a265c9cca17aa8346d2e3a1a8aa
Merge branch 'master' of http://120.26.58.240:8888/r/LifePaymentApi
1个文件已修改
28 ■■■■■ 已修改文件
LifePayment/LifePayment.Application/User/AccountService.cs 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LifePayment/LifePayment.Application/User/AccountService.cs
@@ -11,11 +11,13 @@
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Caching;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Volo.Abp.Identity.Application.Contracts.Account;
using Volo.Abp.IdentityModel;
using ZeroD.Util;
using ZeroD.Util.Fadd;
using static LifePayment.Domain.Shared.LifePaymentConstant;
@@ -30,6 +32,8 @@
        private readonly IRepository<User, Guid> _userRepository;
        private readonly IRepository<UserChannle, Guid> _userChannleRep;
        private readonly IIdentityUserAppService _identityUserService;
        private readonly IDistributedCache<string> _distributedCache;
        public AccountService(
               IWxManager wxManager,
@@ -38,7 +42,8 @@
               IRepository<User, Guid> userRepository,
               IIdentityUserAppService identityUserService,
               IRepository<LifePayUser, Guid> lifePayUserRepository,
               IRepository<UserChannle, Guid> userChannleRep)
               IRepository<UserChannle, Guid> userChannleRep,
               IDistributedCache<string> distributedCache)
        {
            _configuration = configuration;
            _wxManager = wxManager;
@@ -47,19 +52,38 @@
            _authenticator = authenticator;
            _userRepository = userRepository;
            _userChannleRep = userChannleRep;
            _distributedCache = distributedCache;
        }
        #region 查询
        public async Task<WxMiniAppIndentityInfo> GetLifePayWxIndentity(string code)
        {
            var cacheData = await _distributedCache.GetAsync(code);
            var result = new WxMiniAppIndentityInfo();
            if (cacheData != null)
            {
                result.OpenId = cacheData;
            }
            else
            {
            var res = await _wxManager.GetWxOauth2AccessToken(code);
            var result = new WxMiniAppIndentityInfo
                result = new WxMiniAppIndentityInfo
            {
                SessionKey = res.SessionKey,
                OpenId = res.OpenId,
                UnionId = res.UnionId
            };
                if (!string.IsNullOrEmpty(res.OpenId))
                {
                    await _distributedCache.SetAsync(code, res.OpenId, options: new Microsoft.Extensions.Caching.Distributed.DistributedCacheEntryOptions()
                    {
                        AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5)
                    });
                }
            }
            return result;
        }