/// <summary>
        /// 微信网页登录
        /// 兼容服务端渲染与前端渲染页面
        /// </summary>
        /// <returns>用户Id</returns>
        public async Task <string> WxWebLoin(WebAppAuthUserInfo userInfo)
        {
            var targetUserAccount = await sugarClient.Queryable <UserWxAccountMapping>()
                                    .Where(x => x.UserId == userInfo.UnionId && x.WxOpenId == userInfo.OpenId).FirstAsync();

            if (targetUserAccount == null)
            {
                targetUserAccount = new UserWxAccountMapping
                {
                    Id         = Guid.NewGuid(),
                    UserId     = Guid.NewGuid().ToString(),
                    AppId      = configuration["wx:appId"],
                    WxOpenId   = userInfo.OpenId,
                    CreateTime = DateTime.Now
                };
                await sugarClient.Insertable <UserWxAccountMapping>(targetUserAccount).ExecuteCommandAsync();
            }

            //targetUserAccount.Avatar = userInfo.HeadImgUrl;
            //targetUserAccount.NickName = userInfo.NickName;
            //if (targetUserAccount.Profile == null)
            //{
            //    targetUserAccount.Profile = new UserAccountProfile();
            //}
            //targetUserAccount.Profile.Location = userInfo.Country + "," + userInfo.Country + "," + userInfo.Province;
            //await userAccountAccessor.Update(targetUserAccount);
            return(targetUserAccount.Id.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// 微信网页登录
        /// 兼容服务端渲染与前端渲染页面
        /// </summary>
        /// <returns>用户Id</returns>
        public async Task <string> WxWebLoin(WebAppAuthUserInfo userInfo)
        {
            var targetUserAccount = await userAccountAccessor.OneAsync <UserAccountEntry>(x => x.WeChat.OpenIdMapping
                                                                                          .Any(c => c.Source == userInfo.AppId && c.OpenId == userInfo.OpenId));

            if (targetUserAccount == null)
            {
                targetUserAccount = new UserAccountEntry
                {
                    WeChat = new UserAccountWeChat
                    {
                        OpenIdMapping = new List <WeChatAccountOpenIdMapping> {
                            new WeChatAccountOpenIdMapping
                            {
                                Source  = userInfo.AppId,
                                OpenId  = userInfo.OpenId,
                                Type    = userInfo.WxLoginType,
                                UnionId = userInfo.UnionId,
                                Id      = Guid.NewGuid()
                            }
                        },
                        Id      = Guid.NewGuid(),
                        UnionId = userInfo.UnionId
                    },
                    Id         = Guid.NewGuid(),
                    CreateTime = DateTime.Now
                };
                await userAccountAccessor.Add(targetUserAccount);
            }

            targetUserAccount.Avatar   = userInfo.HeadImgUrl;
            targetUserAccount.NickName = userInfo.NickName;
            if (targetUserAccount.Profile == null)
            {
                targetUserAccount.Profile = new UserAccountProfile();
            }
            targetUserAccount.Profile.Location = userInfo.Country + "," + userInfo.Country + "," + userInfo.Province;
            await userAccountAccessor.Update(targetUserAccount);

            return(targetUserAccount.Id.ToString());
        }