Ejemplo n.º 1
0
        private static async Task <ResultMo <OauthUserMo> > AddOrUpdateOauthUser(SocialPaltforms plat, string code, string state)
        {
            var userWxRes = await SnsCommon.GetOauthUserByCode(plat, code, state);

            var userRes = await OauthUserRep.Instance.GetOauthUserByAppUserId(
                MemberShiper.AppAuthorize.TenantId,
                userWxRes.data.app_user_id, plat);

            if (userRes.IsSuccess())
            {
                var user = userRes.data;
                user.SetFromSocial(userWxRes.data);

                await OauthUserRep.Instance.UpdateUserWithToken(user);

                return(new ResultMo <OauthUserMo>(user));
            }

            if (!userRes.IsResultType(ResultTypes.ObjectNull))
            {
                return(userRes);
            }

            var newUser = userWxRes.data;
            var idRes   = await OauthUserRep.Instance.Add(newUser);

            if (!idRes.IsSuccess())
            {
                return(idRes.ConvertToResultOnly <OauthUserMo>());
            }

            newUser.id = idRes.id;
            return(new ResultMo <OauthUserMo>(newUser));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取授权地址
        /// </summary>
        /// <param name="plat">平台</param>
        /// <param name="redirectUrl">重定向回跳地址</param>
        /// <param name="state">返回参数,自行编码</param>
        /// <param name="type">授权类型</param>
        /// <returns></returns>

        public ResultMo <string> GetOauthUrl(SocialPaltforms plat, string redirectUrl, string state, AuthClientType type)
        {
            var handler = SnsCommon.GetHandlerByPlatform(plat);

            return(handler.GetOauthUrl(redirectUrl, state, type));
        }