コード例 #1
0
        public async Task <H5ResponseViewModel <TokenView> > PwdLogin([FromBody] H5RequestViewModel Parameters)
        {
            var sysCode = _sys.CheckParameters(Parameters.data, "PwdLogin_H5");
            H5ResponseViewModel <TokenView> response = null;
            TokenView result = null;

            if (sysCode == SysCode.Ok)
            {
                string phone = Parameters.data.phone;
                //判断手机号码是否注册
                bool isExist = await _user.PhoneExistAsync(phone);

                if (isExist)
                {
                    //获取用户登录信息。
                    var userLogin = await _user.GetUserLoginAsync(phone);

                    if (userLogin.Salt != 0)
                    {
                        string pwd    = _sys.Md5Encode($"{(string)Parameters.data.password}{userLogin.Salt}");
                        var    userId = _user.UserLoginOrPwd(phone, pwd);
                        if (userId != 0)
                        {
                            result = _token.GetH5Token(userId);
                            await _user.RecordLoginLogAsync(new userLoginLogDto
                            {
                                App_version = "H5",
                                Createtime  = TimeHelper.GetDateTime(),
                                Device_code = "H5",
                                Gps         = "H5",
                                Os_type     = "H5",
                                Os_version  = "H5",
                                Phone       = phone,
                                Userid      = userId
                            });
                        }
                        else
                        {
                            sysCode = SysCode.PwdErr;
                        }
                    }
                    else
                    {
                        //用户H5登录注册,没有密码
                        sysCode = SysCode.UserPwdIsNull;
                    }
                }
                else
                {
                    sysCode = SysCode.PhoneNonentity;
                }
            }
            response = new H5ResponseViewModel <TokenView>(sysCode, result ?? null);
            return(response);
        }
コード例 #2
0
ファイル: TokenService.cs プロジェクト: bsdzingsq/API_Core
        /// <summary>
        /// 获取token
        /// author:陶林辉
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <returns></returns>
        public UserTokenView GetToken(long userId)
        {
            var    vInfo      = _context.UserLogin.Where(e => e.Userid == userId).FirstOrDefault();
            string strToken   = Guid.NewGuid().ToString();
            string strId      = _sys.Md5Encode($"{vInfo.Userid}{vInfo.Createtime}");
            string strSession = Guid.NewGuid().ToString();
            var    entity     = new UserLoginDto
            {
                Createtime = vInfo.Createtime,
                Updatetime = vInfo.Updatetime,
                Is_first   = vInfo.Is_first,
                Password   = vInfo.Password,
                Phone      = vInfo.Phone,
                Salt       = vInfo.Salt,
                Status     = vInfo.Status,
                Token      = strToken,
                Userid     = vInfo.Userid
            };
            UserTokenView Token = new UserTokenView
            {
                SessionToken = strSession,
                UserOpenId   = strId,
                UserToken    = strToken
            };

            RedisHelper.KeyDelete($"{CacheKey.Token}{strId}");
            RedisHelper.KeyDelete($"{CacheKey.SessionToken}{strId}");
            RedisHelper.StringSet($"{CacheKey.Token}{strId}", entity, RedisFolderEnum.token, RedisEnum.Three);
            RedisHelper.StringSet($"{CacheKey.SessionToken}{strId}", strSession, 5, RedisFolderEnum.sessionToken, RedisEnum.Three);
            return(Token);
        }
コード例 #3
0
        /// <summary>
        /// 话费充值
        /// author:陶林辉
        /// </summary>
        /// <param name="phone">手机号码</param>
        /// <param name="cardnum">面额</param>
        /// <param name="orderId">订单号</param>
        /// <returns></returns>
        public async Task <bool> PrepaidRefillAsync(string phone, string cardnum, string orderId)
        {
            var time = DateTime.Now.ToString("yyyyMMddHHmmss");
            var md5  = $"{_ofpay.Userid}{_ofpay.Pwd}140101{cardnum}{orderId}{time}{phone}{_ofpay.Keystr}";

            md5 = _sys.Md5Encode(md5).ToUpper();
            var result = _sys.PostJsonData($"{_ofpay.Url}onlineorder.do?userid={_ofpay.Userid}&userpws={_ofpay.Pwd}&cardid=140101&cardnum={cardnum}&mctype=" +
                                           $"&sporder_id={orderId}&sporder_time={time}&game_userid={phone}&md5_str={md5}&ret_url=&version=6.0", "", Encoding.GetEncoding("gbk"));
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(result);
            XmlNode root  = doc.SelectSingleNode("//orderinfo");
            string  state = root.SelectSingleNode("game_state").InnerText;

            if (state != "9")
            {
                var     ofpayOrderId = root.SelectSingleNode("orderid").InnerText;
                decimal price        = decimal.Parse(root.SelectSingleNode("ordercash").InnerText);
                await UpdateOfpayLogAsync(0, orderId, price, ofpayOrderId);

                return(true);
            }
            string  _ofpayOrderId = root.SelectSingleNode("orderid").InnerText;
            decimal _price        = decimal.Parse(root.SelectSingleNode("ordercash").InnerText);

            await UpdateOfpayLogAsync(9, orderId, _price, _ofpayOrderId); //9是需要退款的,

            return(false);
        }
コード例 #4
0
        public H5ResponseViewModel <Object> Register([FromBody] H5RequestViewModel Parameters)
        {
            var sysCode = _sys.CheckParameters(Parameters.data, "Register");
            H5ResponseViewModel <Object> response = null;
            string phone  = Parameters.data.phone;
            string strKey = $"{CacheKey.Rgister.ToString()}{phone}";

            if (sysCode == SysCode.Ok)
            {
                if (RedisHelper.KeyExists(strKey, RedisFolderEnum.code, RedisEnum.Four) &&
                    RedisHelper.StringGet(strKey, RedisFolderEnum.code, RedisEnum.Four).Equals((string)Parameters.data.verifyCode))
                {
                    var  salt   = _sys.GetRandomSeed(8);
                    long userId = _user.Register(new RegisterDto
                    {
                        App_version = "",
                        Channel     = Parameters.data.channelId,
                        Createtime  = DateTime.Now,
                        Device_code = "",
                        Os_type     = "",
                        Gps         = "",
                        Os_version  = "",
                        Phone       = phone,
                        Platform    = "H5",
                        Updatetime  = DateTime.Now
                    }, new UserLoginDto
                    {
                        Createtime = TimeHelper.GetDateTime(),
                        Is_first   = 1,
                        Password   = _sys.Md5Encode($"{(string)Parameters.data.password}{salt}"),
                        Phone      = phone,
                        Status     = 0,
                        Salt       = salt,
                        Updatetime = TimeHelper.GetDateTime(),
                    }, new UserInfoDto
                    {
                        Createtime = TimeHelper.GetDateTime(),
                        Head       = "",
                        Updatetime = TimeHelper.GetDateTime(),
                        Nick_name  = ""
                    });
                    if (userId != 0)
                    {
                        RedisHelper.KeyDelete(strKey, RedisFolderEnum.code, RedisEnum.Four);
                    }
                    else
                    {
                        sysCode = SysCode.Err;
                    }
                }
                else
                {
                    sysCode = SysCode.CodeErr;
                }
            }
            response = new H5ResponseViewModel <Object>(sysCode, null);
            return(response);
        }
コード例 #5
0
        public ResponseViewModel <UserTokenView> register([FromBody] RequestViewModel obj)
        {
            UserTokenView token = new UserTokenView();
            ResponseViewModel <UserTokenView> response = null;

            obj = JsonHelper.DeserializeJsonToObject <RequestViewModel>(Content(User.Identity.Name).Content);
            string strKey = $"{CacheKey.Rgister.ToString()}{obj.Data.phone}";

            if (RedisHelper.KeyExists(strKey, RedisFolderEnum.code, RedisEnum.Four) && RedisHelper.StringGet(strKey, RedisFolderEnum.code, RedisEnum.Four).Equals((string)obj.Data.verifyCode))
            {
                var  salt   = _sys.GetRandomSeed(8);
                long userId = _user.Register(new RegisterDto
                {
                    App_version = obj.Client.Version,
                    Channel     = obj.Client.Channel,
                    Createtime  = DateTime.Now,
                    Device_code = obj.Client.DeviceCode,
                    Os_type     = obj.Client.OsType,
                    Gps         = obj.Client.Gps,
                    Os_version  = obj.Client.OsVersion,
                    Phone       = obj.Data.phone,
                    Platform    = obj.Client.Platform,
                    Updatetime  = DateTime.Now
                }, new UserLoginDto
                {
                    Createtime = TimeHelper.GetDateTime(),
                    Is_first   = 1,
                    Password   = _sys.Md5Encode($"{(string)obj.Data.password}{salt}"),
                    Phone      = obj.Data.phone,
                    Status     = 0,
                    Updatetime = TimeHelper.GetDateTime(),
                    Salt       = salt
                }, new UserInfoDto
                {
                    Createtime = TimeHelper.GetDateTime(),
                    //Head = "",
                    Updatetime = TimeHelper.GetDateTime(),
                    //Nick_name = ""
                });
                if (userId != 0)
                {
                    //获取token
                    token    = _token.GetToken(userId);
                    response = new ResponseViewModel <UserTokenView>(SysCode.Ok, token, obj.Encrypt, _sys, obj.Secret);
                    _user.RecordLoginLogAsync(new userLoginLogDto
                    {
                        App_version = obj.Client.Version,
                        Createtime  = TimeHelper.GetDateTime(),
                        Device_code = obj.Client.DeviceCode,
                        Gps         = obj.Client.Gps,
                        Os_type     = obj.Client.OsType,
                        Os_version  = obj.Client.OsVersion,
                        Phone       = obj.Data.phone,
                        Userid      = userId
                    });
                    RedisHelper.KeyDelete(strKey, RedisFolderEnum.code, RedisEnum.Four);
                }
                else
                {
                    response = new ResponseViewModel <UserTokenView>(SysCode.Err, null, obj.Encrypt, _sys, obj.Secret);
                }
            }
            else
            {
                /*不存在验证码,返回验证码错误*/
                response = new ResponseViewModel <UserTokenView>(SysCode.CodeErr, null, obj.Encrypt, _sys, obj.Secret);
            }
            return(response);
        }