using System; using System.Collections.Generic; using Sog; using Sog.Crypto; using ProtoCSStruct; namespace HttpProxy { public static class MessageTaskHandler { //测试用,所有登录的玩家互相是好友,并且不校验token //public static bool bTestFriend = false; //测试用,所有登录的玩家互相是好友,并且不校验token public static Dictionary TestFriendAllLoginIsFriend = new Dictionary(); public static void HandlerPacket(uint remoteAppID, StructPacket packet) { switch (packet.MsgID) { case (int)CSMsgID.AccountReq: HttpCheckAccountTokenReq(remoteAppID, packet); break; case (int)SSMsgID.QueryHttpSnsFriendListReq: HttpQuerySnsFriendList(remoteAppID, packet); break; case (int)SSMsgID.BindGuestFacebookHttpCheckReq: OnBindGuestFacebookHttpCheckReq(remoteAppID, packet); break; case (int)SSMsgID.UnbindGuestFacebookNotifyHttp: OnUnBindGuestFacebookNotifyHttp(remoteAppID, packet); break; default: TraceLog.Error("MessageTaskHandler.HandlerPacket unknow MsgID {0}", packet.MsgID); break; } } private static void HttpCheckAccountTokenReq(uint remoteAppID, StructPacket packet) { ref CSAccountAuthReq accountAuthReq = ref packet.GetMessage(); SSHttpCheckAccountToken ssRes = new SSHttpCheckAccountToken(); ssRes.CSAccountAuthReq = accountAuthReq; ssRes.Ret = -1; int accountType = accountAuthReq.Account.AccountType; string accountId = accountAuthReq.Account.AccountID.GetString(); string accountToken = accountAuthReq.Account.AccountToken.GetString(); TraceLog.Debug("MessageTaskHandler.HttpCheckAccountTokenReq type {0} id {1}, token {2}" , accountType, accountId, accountToken); //facebook校验token, if (accountType == (int)AccountType.AccountType_Facebook || accountType == (int)AccountType.AccountType_QQ || accountType == (int)AccountType.AccountType_WX || accountType == (int)AccountType.AccountType_WXMini) { if(HttpProxyServerUtils.IsTestFacebookMode()) { ssRes.Nick.SetString( "Test_" + accountId); ssRes.Ret = 0; HttpProxyServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.HttpCheckAccountTokenRes, ref ssRes, packet.ObjectID); return; } //先校验cache FacebookAccountInfo accountInfo = FacebookTokenCacheSvc.GetAccountInfo(accountType, accountId); if (accountInfo != null && accountToken.Equals(accountInfo.Token)) { ssRes.Gender = accountInfo.Gender; ssRes.Nick.SetString(accountInfo.Nick); ssRes.Icon.SetString(accountInfo.Icon); ssRes.Email.SetString( accountInfo.Email); ssRes.Ret = 0; TraceLog.Trace("MessageTaskHandler.HttpCheckAccountTokenReq type {0} id {1} token check success use cache" , accountType, accountId); } else if(accountType == (int)AccountType.AccountType_Facebook) { DoFacebookAuth(ref accountAuthReq, ref ssRes); } else if(accountType == (int)AccountType.AccountType_QQ) { DoQQAuth(ref accountAuthReq, ref ssRes); } else if (accountType == (int)AccountType.AccountType_WX) { DoWXAuth(ref accountAuthReq, ref ssRes); } else if (accountType == (int)AccountType.AccountType_WXMini) { DoWXMini(ref accountAuthReq, ref ssRes); } } else if(accountType == (int)AccountType.AccountType_Google) { bool exception = false; string userid; string name; string icon; string email; if(GoogleAuth.AuthToken(accountId, accountToken , out exception, out userid, out name, out icon, out email) == false) { TraceLog.Error("MessageTaskHandler.HttpCheckAccountTokenReq type {0} id {1} token {2} GoogleAuth check failed!" , accountType, accountId, accountToken); ssRes.Ret = -1; } else { ssRes.Nick.SetString(name); ssRes.Icon.SetString(icon); ssRes.Email.SetString(email); ssRes.Ret = 0; } } else if (accountType == (int)AccountType.AccountType_Hero) { DoHeroAuth(ref accountAuthReq, ref ssRes); } else if (accountType == (int)AccountType.AccountType_HeroUSDK) { DoHeroUSDKAuth(ref accountAuthReq, ref ssRes); } else if (accountType == (int)AccountType.AccountType_Huawei) { DoHuaweiAuth(accountType, accountId, accountToken, ref ssRes); } else if(accountType == (int)AccountType.AccountType_Guest)//游客 { if(HttpProxyServerUtils.GetServerConfig().auth_guest) { DoMSDKGuestAuth(ref accountAuthReq, ref ssRes); } else { //不是第三方平台校验一下token的固定算法 string serverComputeToken = GuestAccountCrypto.GetAccountToken(accountId); if (accountAuthReq.Account.AccountToken.Equals(serverComputeToken)) { TraceLog.Debug("MessageTaskHandler.HttpCheckAccountTokenReq type {0} id {1} token {2}, token check success,return ret = 0" , accountType, accountId, accountToken); ssRes.Ret = 0; } else { TraceLog.Debug("MessageTaskHandler.HttpCheckAccountTokenReq type {0} id {1} token {2}, token check failed servercomptoken {3},return ret = -1" , accountType, accountId, accountToken, serverComputeToken); ssRes.Ret = -1; } } } //todo 测试 //int useType = 1; //string openId = "1003235707224565"; //ssRes.UserType = useType; //ssRes.OpenId.SetString(openId); //ssRes.Compensation = 5; HttpProxyServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.HttpCheckAccountTokenRes, ref ssRes, packet.ObjectID); } private static void DoWXMini(ref CSAccountAuthReq accountAuthReq, ref SSHttpCheckAccountToken accountCheckToken) { bool exception = false; bool bAuthSuccess = false; bAuthSuccess = WechatMini.AuthToken(out var openId, accountAuthReq.Account.AccountToken.GetString(), ref accountCheckToken, out exception); if (bAuthSuccess == false) { TraceLog.Error("MessageTaskHandler.DoWXMini type {0} id {1} token {2} check failed!" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, accountAuthReq.Account.AccountToken); accountCheckToken.Ret = -1; if (exception) { accountCheckToken.Ret = 1201; TraceLog.Error("MessageTaskHandler.DoWXMiniuth type {0} id {1} http query throw exception, set error code 1201" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID); } } else { //string signatureServer = HashHelper.SHA1String(accountAuthReq.RawData.GetString() + accountCheckToken.SessionKey.GetString()); //TraceLog.Error("MessageTaskHandler.DoWXMiniuth getsignature client:{0} server:{1}", accountAuthReq.Signature.GetString(), signatureServer); //if (signatureServer != accountAuthReq.Signature.GetString()) //{ // accountCheckToken.Ret = -1; // return; //} //accountCheckToken.Signature.SetString(signatureServer); accountCheckToken.Ret = 0; accountCheckToken.CSAccountAuthReq.Account.AccountID.SetString(openId); return; //成功,继续拉取用户信息 string[] userinfo = WechatMini.QueryUserInfo(accountAuthReq.Account.AccountID.GetString(), accountAuthReq.Account.AccountToken.GetString(), out exception); if (userinfo == null) { TraceLog.Error("MessageTaskHandler.DoWXMini type {0} id {1} token {2} QueryUserInfo failed!" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, accountAuthReq.Account.AccountToken); accountCheckToken.Ret = -1; } else { accountCheckToken.Nick.SetString(userinfo[0]); if (userinfo[1] == "1") { accountCheckToken.Gender = (int)GenderType.Male; } else { accountCheckToken.Gender = (int)GenderType.Female; } accountCheckToken.Icon.SetString(userinfo[2]); accountCheckToken.Ret = 0; FacebookTokenCacheSvc.UpdateAccountTokenToCache( accountAuthReq.Account.AccountType , accountAuthReq.Account.AccountID.GetString() , accountAuthReq.Account.AccountToken.GetString() , accountCheckToken.Nick.GetString() , accountCheckToken.Icon.GetString() , accountCheckToken.Gender , accountCheckToken.Email.GetString()); } } } private static void DoFacebookAuth(ref CSAccountAuthReq accountAuthReq, ref SSHttpCheckAccountToken accountCheckToken) { bool exception = false; bool bAuthSuccess = false; bAuthSuccess = FacebookAuth.AuthToken(accountAuthReq.Account.AccountID.GetString(), accountAuthReq.Account.AccountToken.GetString(), out exception); if (bAuthSuccess == false) { TraceLog.Error("MessageTaskHandler.DoFacebookAuth type {0} id {1} token {2} check failed!" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, accountAuthReq.Account.AccountToken); accountCheckToken.Ret = -1; if (exception) { accountCheckToken.Ret = 1201; TraceLog.Error("MessageTaskHandler.DoFacebookAuth type {0} id {1} http query throw exception, set error code 1201" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID); } } else { //成功,继续拉取用户信息 string[] userinfo = FacebookAuth.QueryUserInfo(accountAuthReq.Account.AccountToken.GetString(), out exception); if (userinfo == null) { TraceLog.Error("MessageTaskHandler.DoFacebookAuth type {0} id {1} token {2} FacebookAuth.QueryUserInfo failed!" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, accountAuthReq.Account.AccountToken); accountCheckToken.Ret = -1; } else { accountCheckToken.Nick.SetString(userinfo[0]); if (userinfo[1] == "male") { accountCheckToken.Gender = (int)GenderType.Male; } else { accountCheckToken.Gender = (int)GenderType.Female; } accountCheckToken.Icon.SetString(userinfo[2]); accountCheckToken.Email.SetString(userinfo[3]); accountCheckToken.Ret = 0; FacebookTokenCacheSvc.UpdateAccountTokenToCache( accountAuthReq.Account.AccountType , accountAuthReq.Account.AccountID.GetString() , accountAuthReq.Account.AccountToken.GetString() , accountCheckToken.Nick.GetString() , accountCheckToken.Icon.GetString() , accountCheckToken.Gender , accountCheckToken.Email.GetString()); } } } private static void DoQQAuth(ref CSAccountAuthReq accountAuthReq, ref SSHttpCheckAccountToken accountCheckToken) { bool exception = false; bool bAuthSuccess = false; bAuthSuccess = QQAuth.AuthToken(accountAuthReq.Account.AccountID.GetString(), accountAuthReq.Account.AccountToken.GetString(), accountAuthReq.Ip.GetString(), out exception); if (bAuthSuccess == false) { TraceLog.Error("MessageTaskHandler.DoQQAuth type {0} id {1} token {2} check failed!" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, accountAuthReq.Account.AccountToken); accountCheckToken.Ret = -1; if (exception) { accountCheckToken.Ret = 1201; TraceLog.Error("MessageTaskHandler.DoQQAuth type {0} id {1} http query throw exception, set error code 1201" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID); } } else { //成功,继续拉取用户信息 string[] userinfo = QQAuth.QueryUserInfo(accountAuthReq.Account.AccountID.GetString(), accountAuthReq.Account.AccountToken.GetString(), out exception); if (userinfo == null) { TraceLog.Error("MessageTaskHandler.DoQQAuth type {0} id {1} token {2} QueryUserInfo failed!" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, accountAuthReq.Account.AccountToken); accountCheckToken.Ret = -1; } else { accountCheckToken.Nick.SetString(userinfo[0]); if (userinfo[1] == "男") { accountCheckToken.Gender = (int)GenderType.Male; } else { accountCheckToken.Gender = (int)GenderType.Female; } accountCheckToken.Icon.SetString(userinfo[2]); accountCheckToken.Ret = 0; FacebookTokenCacheSvc.UpdateAccountTokenToCache( accountAuthReq.Account.AccountType , accountAuthReq.Account.AccountID.GetString() , accountAuthReq.Account.AccountToken.GetString() , accountCheckToken.Nick.GetString() , accountCheckToken.Icon.GetString() , accountCheckToken.Gender , accountCheckToken.Email.GetString()); } } } private static void DoWXAuth(ref CSAccountAuthReq accountAuthReq, ref SSHttpCheckAccountToken accountCheckToken) { bool exception = false; bool bAuthSuccess = false; bAuthSuccess = WeixinAuth.AuthToken(accountAuthReq.Account.AccountID.GetString(), accountAuthReq.Account.AccountToken.GetString(), out exception); if (bAuthSuccess == false) { TraceLog.Error("MessageTaskHandler.DoWXAuth type {0} id {1} token {2} check failed!" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, accountAuthReq.Account.AccountToken); accountCheckToken.Ret = -1; if (exception) { accountCheckToken.Ret = 1201; TraceLog.Error("MessageTaskHandler.DoWXAuth type {0} id {1} http query throw exception, set error code 1201" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID); } } else { //成功,继续拉取用户信息 string[] userinfo = WeixinAuth.QueryUserInfo(accountAuthReq.Account.AccountID.GetString(), accountAuthReq.Account.AccountToken.GetString(), out exception); if (userinfo == null) { TraceLog.Error("MessageTaskHandler.DoWXAuth type {0} id {1} token {2} QueryUserInfo failed!" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, accountAuthReq.Account.AccountToken); accountCheckToken.Ret = -1; } else { accountCheckToken.Nick.SetString(userinfo[0]); if (userinfo[1] == "1") { accountCheckToken.Gender = (int)GenderType.Male; } else { accountCheckToken.Gender = (int)GenderType.Female; } accountCheckToken.Icon.SetString(userinfo[2]); accountCheckToken.Ret = 0; FacebookTokenCacheSvc.UpdateAccountTokenToCache( accountAuthReq.Account.AccountType , accountAuthReq.Account.AccountID.GetString() , accountAuthReq.Account.AccountToken.GetString() , accountCheckToken.Nick.GetString() , accountCheckToken.Icon.GetString() , accountCheckToken.Gender , accountCheckToken.Email.GetString()); } } } private static void DoMSDKGuestAuth(ref CSAccountAuthReq accountAuthReq, ref SSHttpCheckAccountToken accountCheckToken) { bool exception = false; bool bAuthSuccess = false; bAuthSuccess = MSDKGuestAuth.AuthToken(accountAuthReq.Account.AccountID.GetString(), accountAuthReq.Account.AccountToken.GetString(), out exception); if (bAuthSuccess == false) { TraceLog.Error("MessageTaskHandler.DoMSDKGuestAuth type {0} id {1} token {2} check failed!" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, accountAuthReq.Account.AccountToken); accountCheckToken.Ret = -1; if (exception) { accountCheckToken.Ret = 1201; TraceLog.Error("MessageTaskHandler.DoMSDKGuestAuth type {0} id {1} http query throw exception, set error code 1201" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID); } } else { accountCheckToken.Ret = 0; } } private static void DoHeroAuth(ref CSAccountAuthReq accountAuthReq, ref SSHttpCheckAccountToken accountCheckToken) { string userId, userName, accessToken; try { accessToken = HeroAuth.GetAccessToken(accountAuthReq.AuthCode.GetString()); if (accessToken == null) { TraceLog.Error("MessageTaskHandler.DoHeroAuth type {0} id {1} get accessToken fail" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID); accountCheckToken.Ret = -1; return; } if (! HeroAuth.GetUserInfo(accessToken, out userId, out userName)) { TraceLog.Error("MessageTaskHandler.DoHeroAuth type {0} id {1} get userInfo fail" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID); accountCheckToken.Ret = -1; return; } if (! accountAuthReq.Account.AccountID.Equals(userId)) { TraceLog.Error("MessageTaskHandler.DoHeroAuth type {0} accountId {1} userId {2} not same" , accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID, userId); accountCheckToken.Ret = -1; return; } } catch (Exception ex) { TraceLog.Exception(ex); accountCheckToken.Ret = -1; return; } accountCheckToken.Ret = 0; accountCheckToken.Nick.SetString(userName); accountCheckToken.CSAccountAuthReq.Account.AccountID.SetString(userId); accountCheckToken.CSAccountAuthReq.Account.AccountToken.SetString(accessToken); } private static void DoHeroUSDKAuth(ref CSAccountAuthReq authReq, ref SSHttpCheckAccountToken accountCheckToken) { HeroUSDKAccountInfo userInfo = null; try { var proj = HeroUSDKAuth.GetProject(authReq.Version.ProductId.GetString()); string accountId = authReq.Account.AccountID.GetString(); string accountToken = authReq.Account.AccountToken.GetString(); ; userInfo = HeroUSDKAuth.GetUserInfo(proj, accountId, accountToken,authReq.Account.Compensation); if (userInfo == null) { TraceLog.Error("MessageTaskHandler.DoHeroUSDKAuth type {0} id {1} get userInfo fail" , authReq.Account.AccountType, authReq.Account.AccountID); accountCheckToken.Ret = -1; return; } if (! authReq.Account.AccountID.Equals(userInfo.userId)) { TraceLog.Error("MessageTaskHandler.DoHeroUSDKAuth type {0} accountId {1} userId {2} not same" , authReq.Account.AccountType, authReq.Account.AccountID, userInfo.userId); accountCheckToken.Ret = -1; return; } } catch (Exception ex) { TraceLog.Exception(ex); accountCheckToken.Ret = -1; return; } accountCheckToken.Ret = 0; // hero usdk的回包中, 有时没有cName字段, 就用cUid作为nick if (string.IsNullOrEmpty(userInfo.userName)) { } else { accountCheckToken.Nick.SetString(userInfo.userName); } accountCheckToken.UserType = userInfo.userType; if (!string.IsNullOrEmpty(userInfo.openId)) { accountCheckToken.OpenId.SetString(userInfo.openId); } accountCheckToken.CSAccountAuthReq.Account.AccountID.SetString(userInfo.userId); accountCheckToken.ChannelId = userInfo.channelId; accountCheckToken.Channel.SetString(userInfo.channel); accountCheckToken.Compensation = userInfo.compensation; } // 华为HMS Core鉴权 private static void DoHuaweiAuth(int accountType, string accountId, string accountToken, ref SSHttpCheckAccountToken res) { try { if (HuaweiAuth.GetIDTokenInfo(accountId, accountToken)) { TraceLog.Trace("MessageTaskHandler.DoHuaweiAuth type {0} id {1} succ", accountType, accountId); res.Ret = 0; } else { TraceLog.Error("MessageTaskHandler.DoHuaweiAuth type {0} id {1} fail", accountType, accountId); res.Ret = -1; } } catch (Exception ex) { TraceLog.Exception(ex); res.Ret = -1; } } // 华为AGC鉴权 private static void DoHuaweiAGCAuth(int accountType, string accountId, string accountToken, ref SSHttpCheckAccountToken res) { try { if (HuaweiAuth.VerifyAGCUserToken(accountId, accountToken) == 0) { TraceLog.Trace("MessageTaskHandler.DoHuaweiAGCAuth type {0} id {1} succ", accountType, accountId); res.Ret = 0; } else { TraceLog.Error("MessageTaskHandler.DoHuaweiAGCAuth type {0} id {1} fail", accountType, accountId); res.Ret = -1; } } catch (Exception ex) { TraceLog.Exception(ex); res.Ret = -1; } } private static void HttpQuerySnsFriendList(uint remoteAppID, StructPacket packet) { ref SSQueryHttpSnsFriendListReq httpSnsReq = ref packet.GetMessage(); TraceLog.Debug("MessageTaskHandler.HttpQuerySnsFriendList begin accountType {0} accountID {1} accountToken {2}" , httpSnsReq.Account.AccountType , httpSnsReq.Account.AccountID , httpSnsReq.Account.AccountToken); List friendlist = null; if (HttpProxyServerUtils.IsTestFacebookMode()) { lock (TestFriendAllLoginIsFriend) { if (TestFriendAllLoginIsFriend.ContainsKey(httpSnsReq.Account.AccountID.GetString()) == false) { TestFriendAllLoginIsFriend.Add(httpSnsReq.Account.AccountID.GetString(), 1); } friendlist = new List(); foreach (var item in TestFriendAllLoginIsFriend) { if (httpSnsReq.Account.AccountID.Equals(item.Key)) { continue; } SnsFriendInfoAccount onefriend = new SnsFriendInfoAccount(); onefriend.AccountType = 1; onefriend.AccountID.SetString( item.Key); onefriend.Nick.SetString( "TestFriendOnly"); onefriend.Uid = 0; friendlist.Add(onefriend); } } } else { if (httpSnsReq.Account.AccountType == (int)AccountType.AccountType_Facebook) { bool exception = false; FacebookAccountInfo accountInfo = FacebookTokenCacheSvc.GetAccountInfo(httpSnsReq.Account.AccountType, httpSnsReq.Account.AccountID.GetString()); //防止频繁刷新 if (accountInfo != null && accountInfo.Friendlist != null && HttpProxyServerUtils.GetTimeSecond() - accountInfo.LastHttpQueryFriendTime < 300) { friendlist = accountInfo.Friendlist; TraceLog.Trace("MessageTaskHandler.HttpQuerySnsFriendList id {0} get list success use cache" , httpSnsReq.Account.AccountID); } else { friendlist = FacebookAuth.QuerySnsFriendList(httpSnsReq.Account.AccountToken.GetString(), out exception); if (friendlist != null && exception == false) { FacebookTokenCacheSvc.UpdateFriendToCache(httpSnsReq.Account.AccountType, httpSnsReq.Account.AccountID.GetString(), friendlist); accountInfo = FacebookTokenCacheSvc.GetAccountInfo(httpSnsReq.Account.AccountType, httpSnsReq.Account.AccountID.GetString()); if(accountInfo != null) { accountInfo.LastHttpQueryFriendTime = HttpProxyServerUtils.GetTimeSecond(); } } //http服务器出问题了,返回cache if(exception == true) { TraceLog.Error("MessageTaskHandler.HttpQuerySnsFriendList id {0} http query exception" , httpSnsReq.Account.AccountID); if(accountInfo != null && accountInfo.Friendlist != null) { friendlist = accountInfo.Friendlist; TraceLog.Trace("MessageTaskHandler.HttpQuerySnsFriendList id {0} get list success use cache after http query" , httpSnsReq.Account.AccountID); } } } } else { //游客没有Facebook好友 TraceLog.Debug("MessageTaskHandler.HttpQuerySnsFriendList account no friend list accountType {0} accountId {1}" , httpSnsReq.Account.AccountType, httpSnsReq.Account.AccountID); return; } } ref SSQueryHttpSnsFriendListRes res = ref CSStructPool.Instance.GetObjRef(); res.Account = httpSnsReq.Account; if (friendlist != null && friendlist.Count > 0) { foreach (var friend in friendlist) { res.Friends.Add(friend); } } HttpProxyServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.QueryHttpSnsFriendListRes, ref res, packet.ObjectID); } private static void OnBindGuestFacebookHttpCheckReq(uint remoteAppID, StructPacket packet) { ref SSBindGuestFacebookHttpCheckReq req = ref packet.GetMessage(); SSBindGuestFacebookHttpCheckRes res = new SSBindGuestFacebookHttpCheckRes(); res.AccountInfo = req.AccountInfo; res.GuestAccountID = req.GuestAccountID; res.Ret = -1; TraceLog.Debug("MessageTaskHandler.OnBindGuestFacebookHttpCheckReq type {0} id {1} token {2}" , req.AccountInfo.AccountType , req.AccountInfo.AccountID , req.AccountInfo.AccountToken); bool exception = false; if (req.AccountInfo.AccountType == (int)AccountType.AccountType_Facebook) { bool bAuthSuccess = FacebookAuth.AuthToken(req.AccountInfo.AccountID.GetString(), req.AccountInfo.AccountToken.GetString(), out exception); if (bAuthSuccess == false) { TraceLog.Error("MessageTaskHandler.OnBindGuestFacebookHttpCheckReq type {0} id {1} token {2} check failed!" , req.AccountInfo.AccountType, req.AccountInfo.AccountID, req.AccountInfo.AccountToken); } else { //成功,继续拉取用户信息 string[] userinfo = FacebookAuth.QueryUserInfo(req.AccountInfo.AccountToken.GetString(), out exception); if (userinfo == null) { TraceLog.Error("MessageTaskHandler.OnBindGuestFacebookHttpCheckReq type {0} id {1} token {2} FacebookAuth.QueryUserInfo failed!" , req.AccountInfo.AccountType, req.AccountInfo.AccountID, req.AccountInfo.AccountToken); } else { res.Nick.SetString(userinfo[0]); if (userinfo[1] == "female") { res.Gender = 1; } res.Icon.SetString(userinfo[2]); res.Email.SetString(userinfo[3]); res.Ret = 0; } } } else if(req.AccountInfo.AccountType == (int)AccountType.AccountType_Google) { string userid; string name; string icon; string email; if (GoogleAuth.AuthToken(req.AccountInfo.AccountID.GetString(), req.AccountInfo.AccountToken.GetString() , out exception, out userid, out name, out icon, out email) == false) { TraceLog.Error("MessageTaskHandler.OnBindGuestFacebookHttpCheckReq type {0} id {1} token {2} GoogleAuth check failed!" , req.AccountInfo.AccountType, req.AccountInfo.AccountID, req.AccountInfo.AccountToken); res.Ret = -1; } else { res.Nick.SetString( name); res.Icon.SetString( icon); res.Email.SetString( email); res.Ret = 0; } } else if (req.AccountInfo.AccountType == (int)AccountType.AccountType_HeroUSDK) { } HttpProxyServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSMsgID.BindGuestFacebookHttpCheckRes, ref res, packet.ObjectID); } private static void OnUnBindGuestFacebookNotifyHttp(uint remoteAppID, StructPacket packet) { ref SSUnbindGuestFacebookNotifyHttp req = ref packet.GetMessage(); TraceLog.Debug("MessageTaskHandler.OnUnBindGuestFacebookNotifyHttp type {0} id {1}" , req.AccountInfo.AccountType , req.AccountInfo.AccountID); FacebookTokenCacheSvc.ClearAccountInfo(req.AccountInfo.AccountType, req.AccountInfo.AccountID.GetString()); } } }