Example #1
0
        /// <summary>
        /// 解析支付信息.
        /// </summary>
        /// <returns>Json数据对象.</returns>
        /// <param name="iJsonDetail">Json详细.</param>
        /// <param name="iOnPaymentSucceeded">支付成功回调函数.</param>
        public SdkPaymentBaseInfo ParserPayResponseInfo(
            string iJsonDetail,
            Action <SdkAccountBaseInfo, string> iOnPaymentSucceeded)
        {
            if (null == iOnPaymentSucceeded)
            {
                Warning("SDKParserPaymentInfo()::OnPaymentSucceeded is null!!!");
            }

            UpdateStatus(SdkStatus.PurchaseCompleted);
            Info("ParserPayResponseInfo()::Detail:{0}", iJsonDetail);
            var sfjson = new SfjsonObject(iJsonDetail);
            var status = (string)sfjson.get("result");

            if (string.IsNullOrEmpty(status))
            {
                Error("ParserPayResponseInfo()::Data Format Invalid!!!!(Detail:{0})", iJsonDetail);
                return(null);
            }
            var data = (string)sfjson.get("data");

            if (string.IsNullOrEmpty(data))
            {
                Error("ParserPayResponseInfo()::Data Format Invalid!!!!(Detail:{0})", iJsonDetail);
                return(null);
            }

            if (null == _payment)
            {
                _payment = new OneSdkPaymentInfo();
                _payment.Reset();
            }
            if (null == _payment)
            {
                Error("ParserPayResponseInfo()::(OneSDKPaymentInfo)Memory New Error!!!!");
                return(null);
            }

            switch (status)
            {
            case SPaySuccess:
            {
                UpdateStatus(SdkStatus.PurchaseSucceeded);
                _payment.succeeded = true;

                if (null != iOnPaymentSucceeded)
                {
                    iOnPaymentSucceeded(_userInfo, _payment.orderNo);
                }
                else
                {
                    Warning("ParserPayResponseInfo()::OnPaymentSucceeded is null!!!!");
                }

                break;
            }

            case SPayFailed:
                UpdateStatus(SdkStatus.PurchaseFailed);
                _payment.succeeded = false;
                break;

            case SPayOrderNo:
                UpdateStatus(SdkStatus.PurchaseOrdered);
                _payment.succeeded = true;
                _payment.orderNo   = data;
                break;
            }
            Info("ParserPayResponseInfo()::PayInfo:{0}", _payment.ToString());
            return(_payment);
        }
Example #2
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);
        }