sunpengfei
2025-08-11 04bd24b1faf7419547d1609b9eecb27fae910856
feat:开发
2个文件已修改
23 ■■■■ 已修改文件
FlexJobApi.Core/Models/UserServer/Auths/Commands/BindWxmpUserInfoCommand.cs 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FlexJobApi.UserServer.Application/Auths/Commands/LoginCommandHandler.cs 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FlexJobApi.Core/Models/UserServer/Auths/Commands/BindWxmpUserInfoCommand.cs
@@ -11,10 +11,16 @@
    /// <summary>
    /// 绑定微信小程序用户信息
    /// </summary>
    [Resource([EnumResourceController.Auth])]
    [Resource([EnumResourceController.Auth], AllowAnonymous = true)]
    public class BindWxmpUserInfoCommand : IRequest<LoginCommandCallback>
    {
        /// <summary>
        /// 访问令牌
        /// </summary>
        [Required]
        public string AccessToken { get; set; }
        /// <summary>
        /// 包括敏感数据在内的完整用户信息的加密数据
        /// </summary>
        [Required]
FlexJobApi.UserServer.Application/Auths/Commands/LoginCommandHandler.cs
@@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
@@ -152,9 +153,15 @@
        /// <exception cref="NotImplementedException"></exception>
        public async Task<LoginCommandCallback> Handle(BindWxmpUserInfoCommand request, CancellationToken cancellationToken)
        {
            var logier = JwtUtils.GetCurrentLogier();
            var claims = JWTEncryption.ReadJwtToken(request.AccessToken).Claims;
            var claimIdentity = new ClaimsIdentity("AuthenticationTypes.Federation");
            claimIdentity.AddClaims(claims);
            var claimsPrincipal = new ClaimsPrincipal(claimIdentity);
            var id = claimsPrincipal.FindFirstValue("Id").ToGuid();
            var type = claimsPrincipal.FindFirstValue("Type").ToEnum<EnumUserType>();
            var user = await rep.AsQueryable()
                .Where(it => it.Type == logier.Type && it.Id == logier.Id)
                .Where(it => it.Type == type && it.Id == id)
                .FirstOrDefaultAsync(cancellationToken);
            if (user == null) throw Oops.Oh(EnumErrorCodeType.s404, "当前账号");
            if (user.WxmpOpenId.IsNull()) throw Oops.Oh(EnumUserErrorCodeType.u1100);
@@ -187,11 +194,11 @@
                }
                var bindPhoneNumberUser = await rep.AsQueryable()
                    .Where(it => it.Type == logier.Type && it.PhoneNumber == info.PhoneNumber && it.Id != user.Id)
                    .Where(it => it.Type == type && it.PhoneNumber == info.PhoneNumber && it.Id != user.Id)
                    .FirstOrDefaultAsync(cancellationToken);
                if (bindPhoneNumberUser == null)
                {
                    if (logier.Type == EnumUserType.Enterprise)
                    if (type == EnumUserType.Enterprise)
                    {
                        throw Oops.Oh(EnumErrorCodeType.s404, "该账号");
                    }