Ejemplo n.º 1
0
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <returns></returns>
        public static User CreateUser(string MibleNumber)
        {
            //防止数据库同步时差 导致重复创建账号 Sleep 2s
            System.Threading.Thread.Sleep(2000);
            using (var client = new UserAccountClient())
            {
                var password = new Random().Next(100000, 1000000).ToString();
                CreateUserRequest request = new CreateUserRequest
                {
                    MobileNumber   = MibleNumber,
                    ChannelIn      = nameof(ChannelIn.H5),
                    Password       = password,
                    Profile        = new UserProfile(),
                    UserCategoryIn = nameof(UserCategoryIn.Tuhu)
                };
                var Result = client.CreateUserRequest(request);

                Result.ThrowIfException(true);
                if (Result.Success && Result.Result != null)
                {
                    Log(UserActionEnum.Register, Result.Result.UserId, "chexian_创建用户,CreateUser:成功");
                    return(Result.Result);
                }
                else
                {
                    Log(UserActionEnum.Register, null, "chexian_创建用户,CreateUser:失败");
                    return(null);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询或者创建用户
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="userName"></param>
        /// <param name="nickName"></param>
        /// <param name="headUrl"></param>
        /// <returns></returns>
        public static User GetOrCreateUser(string mobile, string userName = null, string nickName = null, string headUrl = null)
        {
            User user = null;

            if (!string.IsNullOrEmpty(mobile))
            {
                using (var client = new UserAccountClient())
                {
                    var result = client.GetUserByMobile(mobile);
                    result.ThrowIfException(true);
                    user = result.Result;
                    if (user == null)
                    {
                        var createResult = client.CreateUserRequest(
                            new CreateUserRequest
                        {
                            MobileNumber = mobile,
                            Profile      = new UserProfile
                            {
                                UserName = userName,
                                NickName = nickName,
                                HeadUrl  = headUrl
                            },
                            ChannelIn      = nameof(ChannelIn.None),
                            UserCategoryIn = nameof(UserCategory.Tuhu),
                        });
                        createResult.ThrowIfException(true);
                        user = createResult.Result;
                    }
                }
            }

            return(user);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 查询或者创建用户
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="userName"></param>
        /// <param name="nickName"></param>
        /// <param name="headUrl"></param>
        /// <returns></returns>
        public static async Task <User> GetOrCreateUser(string mobile, string userName = null, string nickName = null, string headUrl = null)
        {
            User user = null;

            try
            {
                if (!string.IsNullOrEmpty(mobile))
                {
                    using (var client = new UserAccountClient())
                    {
                        var result = client.GetUserByMobile(mobile);
                        user = result.Result;
                    }
                    if (user == null)
                    {
                        using (var client = new UserAccountClient())
                        {
                            var createResult = client.CreateUserRequest(
                                new CreateUserRequest
                            {
                                MobileNumber = mobile,
                                Profile      = new UserProfile
                                {
                                    UserName = userName,
                                    NickName = nickName,
                                    HeadUrl  = headUrl
                                },
                                ChannelIn      = nameof(ChannelIn.ThirdPartyDiversion),
                                UserCategoryIn = nameof(UserCategory.Tuhu),
                            });
                            createResult.ThrowIfException(true);
                            user = createResult.Result;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Warn("创建用户失败", ex);
            }

            return(user);
        }
        public async Task TaskMethod()
        {
            try
            {
                var list         = new List <UserApplyActivityModel>();
                var noRepeatList = new List <string>();
                using (var client = new ActivityClient())
                {
                    var result = await client.GetUserApplyActivityRangeByScoreAsync();

                    if (result.Success)
                    {
                        using (var activityClient = new ActivityClient())
                        {
                            foreach (var item in result.Result)
                            {
                                if (await CheckApplyUserCountAsync(item.ActivityId))
                                {
                                    //检查用户手机号、车牌号、驾驶证号是否已经使用
                                    var isExist =
                                        await activityClient.CheckUserApplyActivityInfoIsExistAsync(item.ActivityId,
                                                                                                    item.Mobile, item.CarNum, item.DriverNum);

                                    if (isExist.Success && !isExist.Result)
                                    {
                                        User user = null;
                                        using (var userClient = new UserAccountClient())
                                        {
                                            try
                                            {
                                                var userResult = userClient.GetUserByMobile(item.Mobile);
                                                userResult.ThrowIfException(true);
                                                user = userResult.Result;
                                                if (user == null)
                                                {
                                                    var createResult = userClient.CreateUserRequest(
                                                        new CreateUserRequest
                                                    {
                                                        MobileNumber = item.Mobile,
                                                        Profile      = new UserProfile
                                                        {
                                                            UserName = item.UserName,
                                                            NickName = null,
                                                            HeadUrl  = null
                                                        },
                                                        ChannelIn      = nameof(ChannelIn.None),
                                                        UserCategoryIn = nameof(UserCategory.Tuhu),
                                                    });
                                                    createResult.ThrowIfException(true);
                                                    user = createResult.Result;
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                Logger.Error("用户创建失败。" + ex.Message, ex);
                                            }
                                        }
                                        //添加到待审核集合中
                                        if (!noRepeatList.Contains(item.CarNum) &&
                                            !noRepeatList.Contains(item.Mobile) &&
                                            !noRepeatList.Contains(item.DriverNum))
                                        {
                                            list.Add(item);
                                            noRepeatList.AddRange(new[] { item.Mobile, item.CarNum, item.DriverNum });
                                        }
                                        //从SortedSet中移除
                                        var removeResult = await client
                                                           .RemoveOneUserApplyActivitySortedSetCacheAsync(item);

                                        if (!removeResult.Success)
                                        {
                                            Logger.Error(removeResult.ErrorMessage, removeResult.Exception);
                                        }
                                        item.UserId = user.UserId;
                                    }
                                    else
                                    {
                                        Logger.Error(isExist.ErrorMessage, isExist.Exception);
                                    }
                                }
                            }
                        }
                    }
                }
                if (list.Any())
                {
                    await WashCarActivityMinHangAutoAuditAsync(list);
                }
                list.Clear();
                noRepeatList.Clear();
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }
        }