示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override bool CheckLogin()
        {
            if (string.IsNullOrEmpty(_sessionID))
            {
                return(false);
            }
            string      key         = _mobileType == MobileType.ptAndroid ? "android" : "ios";
            GameChannel gameChannel = ZyGameBaseConfigManager.GameSetting.GetChannelSetting(ChannelType.channelUC);

            if (gameChannel == null)
            {
                TraceLog.ReleaseWrite("The sdkChannel UC section is null.");
                return(false);
            }
            GameSdkSetting setting = gameChannel.GetSetting(key);

            if (setting == null)
            {
                TraceLog.ReleaseWrite("The sdkChannel UC section channelUC:{0} is null.", key);
                return(false);
            }

            string        id      = ((DateTime.Now - Convert.ToDateTime("1970-1-1")).TotalMilliseconds).ToString().Substring(0, 13);
            string        signSrc = setting.AppId + "sid=" + _sessionID + setting.AppKey;
            string        sign    = AMD5(signSrc);
            StringBuilder sb      = new StringBuilder();

            sb.Append("{");
            sb.Append("\"service\":\"").Append(gameChannel.Service).Append("\",");
            sb.Append("\"id\":\"").Append(id).Append("\",");
            sb.Append("\"game\":{");
            sb.Append("\"cpId\":\"").Append(setting.AppId).Append("\",");
            sb.Append("\"gameId\":\"").Append(setting.GameId).Append("\",");
            sb.Append("\"channelId\":\"").Append(gameChannel.ChannelId).Append("\",");
            sb.Append("\"serverId\":\"").Append(setting.ServerId).Append("\"},");
            sb.Append("\"data\":{");
            sb.Append("\"sid\":\"").Append(_sessionID).Append("\"},");
            sb.Append("\"encrypt\":\"").Append(encrypt).Append("\",");
            sb.Append("\"sign\":\"").Append(sign).Append("\"}");

            string result = httpPost(gameChannel.Url, sb.ToString(), Encoding.UTF8);
            UCInfo ucinfo = null;

            try
            {
                ucinfo = JsonUtils.Deserialize <UCInfo>(result);
            }
            catch (Exception ex)
            {
                new BaseLog().SaveLog(ex);
                return(false);
            }
            if (ucinfo == null || ucinfo.state.code != "1")
            {
                TraceLog.ReleaseWrite("Danlesdk login fail:{0},request url:{1},param:{2},signsrc:{3}", result, gameChannel.Url, sb.ToString(), signSrc);
                return(false);
            }

            _retailUser = ucinfo.data.ucid;

            string[] arr = SnsManager.LoginByRetail(_retailID, _retailUser);
            this.UserID     = arr[0];
            this.PassportID = arr[1];
            return(true);
        }
示例#2
0
文件: LoginUC.cs 项目: dongliang/Scut
        public bool CheckLogin()
        {
            if (string.IsNullOrEmpty(_sessionID))
            {
                return(false);
            }
            var sec = SdkSectionFactory.SectionUC;

            if (sec == null)
            {
                TraceLog.ReleaseWrite("The sdkChannel UC section is null.");
                return(false);
            }
            string key            = _mobileType == MobileType.ptAndroid ? "android" : "ios";
            var    channelElement = sec.Channels[key];

            if (channelElement == null)
            {
                TraceLog.ReleaseWrite("The sdkChannel UC section channelUC:{0} is null.", key);
                return(false);
            }

            string        id   = ((DateTime.Now - Convert.ToDateTime("1970-1-1")).TotalMilliseconds).ToString().Substring(0, 13);
            string        sign = AMD5(channelElement.CpId + "sid=" + _sessionID + channelElement.ApiKey);
            StringBuilder sb   = new StringBuilder();

            sb.Append("{");
            sb.Append("\"service\":\"").Append(sec.Service).Append("\",");
            sb.Append("\"id\":\"").Append(id).Append("\",");
            sb.Append("\"game\":{");
            sb.Append("\"cpId\":\"").Append(channelElement.CpId).Append("\",");
            sb.Append("\"gameId\":\"").Append(channelElement.GameId).Append("\",");
            sb.Append("\"channelId\":\"").Append(sec.ChannelId).Append("\",");
            sb.Append("\"serverId\":\"").Append(channelElement.ServerId).Append("\"},");
            sb.Append("\"data\":{");
            sb.Append("\"sid\":\"").Append(_sessionID).Append("\"},");
            sb.Append("\"encrypt\":\"").Append(encrypt).Append("\",");
            sb.Append("\"sign\":\"").Append(sign).Append("\"}");

            string result = httpPost(sec.Url, sb.ToString(), Encoding.UTF8);
            UCInfo ucinfo = null;

            try
            {
                ucinfo = JsonUtils.Deserialize <UCInfo>(result);
            }
            catch (Exception ex)
            {
                new BaseLog().SaveLog(ex);
                return(false);
            }
            if (ucinfo == null || ucinfo.state.code != "1")
            {
                TraceLog.ReleaseWrite("Danlesdk login fail:{0},request url:{1},param:{2}", result, sec.Url, sb.ToString());
                return(false);
            }

            _retailUser = ucinfo.data.ucid;

            string[] arr = SnsManager.LoginByRetail(_retailID, _retailUser);
            this.UserID     = arr[0];
            this.PassportID = arr[1];
            return(true);
        }