示例#1
0
        /// <summary>
        /// 应用.
        /// </summary>
        /// <param name="iUserInfo">用户数据.</param>
        public void Apply(OneSdkUserInfo iUserInfo)
        {
            Reset();

            app      = iUserInfo.productCode;
            sdk      = iUserInfo.channelId;
            uin      = iUserInfo.channelUserId;
            sess     = iUserInfo.token;
            channel  = iUserInfo.channelId;
            platform = SysSettings.GetInstance().PlatformType.ToString();
            option   = "OneSDK";
        }
示例#2
0
        /// <summary>
        /// 登录校验.
        /// </summary>
        /// <returns>校验状态.</returns>
        /// <param name="iUserInfo">用户信息.</param>
        private void LoginCheck(OneSdkUserInfo iUserInfo)
        {
            UpdateStatus(SdkStatus.LoginChecking);
            if (string.IsNullOrEmpty(_loginCheckBaseUrl))
            {
                Error("loginCheck()::The base url of login check is invalid!!!");
                UpdateStatus(SdkStatus.LoginCheckFailed);
                return;
            }

            var loginCheckUrl = _loginCheckBaseUrl;

            Info("loginCheck()::Url:{0}", loginCheckUrl);
            if (string.IsNullOrEmpty(loginCheckUrl))
            {
                Error("loginCheck()::The url of login check is invalid!!!");
                UpdateStatus(SdkStatus.LoginCheckFailed);
                return;
            }

            // 详细数据
            var jsonData = GetLoginCheckInfoJson(iUserInfo);

            if (string.IsNullOrEmpty(jsonData))
            {
                Error("createLoginCheckURL():JsonConvert Failed!!!(Data:{0})",
                      iUserInfo.ToString());
                UpdateStatus(SdkStatus.LoginCheckFailed);
                return;
            }

            var response = ExecuteHttpPost(loginCheckUrl, jsonData);

            if (null == response)
            {
                UpdateStatus(SdkStatus.LoginCheckFailed);
                return;
            }
            Info("loginCheck()::Result:{0}", response.StatusCode);
            if (HttpStatusCode.OK != response.StatusCode)
            {
                _loginCheckFailed?.Invoke(response.StatusCode.ToString());
                UpdateStatus(SdkStatus.LoginCheckFailed);
                return;
            }

            _loginCheckSucceeded?.Invoke(response.StatusCode.ToString());

            UpdateStatus(SdkStatus.LoginCheckSucceeded);
        }
示例#3
0
        /// <summary>
        /// 取得登录校验用信息(Json格式).
        /// </summary>
        /// <returns>登录校验用信息(Json格式).</returns>
        /// <param name="iUserInfo">易接用户信息.</param>
        private string GetLoginCheckInfoJson(OneSdkUserInfo iUserInfo)
        {
            var checkInfo = new OneSdkLoginCheckInfo();

            checkInfo.Apply(iUserInfo);

            // 详细数据
            var jsonData = UtilsJson <OneSdkLoginCheckInfo> .ConvertToJsonString(checkInfo);

            if (!string.IsNullOrEmpty(jsonData))
            {
                return(jsonData);
            }
            Error("createLoginCheckURL():JsonConvert Failed!!!(Data:{0})",
                  checkInfo.ToString());
            UpdateStatus(SdkStatus.LoginCheckFailed);
            return(null);
        }
示例#4
0
        /// <summary>
        /// 解析登录信息.
        /// </summary>
        /// <returns>Json数据对象.</returns>
        /// <param name="iJsonDetail">Json详细.</param>
        public SdkAccountBaseInfo ParserLoginResponseInfo(string iJsonDetail)
        {
            // 登录完成
            UpdateStatus(SdkStatus.LoginCompleted);

            if (null == _userInfo)
            {
                _userInfo = new OneSdkUserInfo();
            }
            if (null == _userInfo)
            {
                Error("ParserLoginResponseInfo()::Memory New Error!!!!");
                return(_userInfo);
            }
            _userInfo.Reset();

            var sfjson       = new SfjsonObject(iJsonDetail);
            var status       = (string)sfjson.get("result");
            var customParams = (string)sfjson.get("customParams");

            Info("ParserLoginResponseInfo()::CustomParams:{0}", customParams);

            switch (status)
            {
            // 登出
            case SLogout:
            {
                _sfUserInfo = null;
                UpdateStatus(SdkStatus.Logouted);

                // 重登录
                if (_isLogin)
                {
                    ReLogin();
                }

                // 登录成功
                break;
            }

            case SLoginSuccess:
            {
                UpdateStatus(SdkStatus.LoginCompleted);

                var userinfoTmp = (SfjsonObject)sfjson.get("userinfo");
                if (null != userinfoTmp)
                {
                    _userInfo.userId        = long.Parse((string)userinfoTmp.get("id"));
                    _userInfo.channelId     = (string)userinfoTmp.get("channelid");
                    _userInfo.channelUserId = (string)userinfoTmp.get("channeluserid");
                    _userInfo.userName      = (string)userinfoTmp.get("username");
                    _userInfo.token         = (string)userinfoTmp.get("token");
                    _userInfo.productCode   = (string)userinfoTmp.get("productcode");
                    _sfUserInfo             = new SFOnlineUser(
                        _userInfo.userId,
                        _userInfo.channelId,
                        _userInfo.channelUserId,
                        _userInfo.userName,
                        _userInfo.token,
                        _userInfo.productCode);
                }
                if (null != _loginCheckCallback)
                {
                    // 校验数据
                    var checkInfo = GetLoginCheckInfoJson(_userInfo);
                    if (string.IsNullOrEmpty(checkInfo))
                    {
                        Error("ParserLoginResponseInfo():JsonConvert Failed!!!(Data:{0})",
                              _userInfo.ToString());
                        UpdateStatus(SdkStatus.LoginCheckFailed);
                        return(null);
                    }
                    Info("ParserLoginResponseInfo()::CheckInfo:{0}", checkInfo);
                    _loginCheckCallback(checkInfo, _loginCheckSucceeded, _loginCheckFailed);
                }
                else
                {
                    // 登录校验&更新状态
                    LoginCheck(_userInfo);
                }

                // 登录失败
                break;
            }

            case SLoginFailed:
            {
                UpdateStatus(SdkStatus.LoginFailed);
                // 重登录
                if (_isLogin)
                {
                    ReLogin();
                }

                break;
            }
            }
            Info("ParserLoginResponseInfo()::UserResultInfo:{0}", _userInfo.ToString());
            return(_userInfo);
        }