public async static ETTask LinkByFaceBook(Player player, LinkInfo info, L2C_Link response) { string fbToken = info.Secret; bool isValidToken = await FacebookHelper.ValidateFacebookToken(fbToken); if (!isValidToken) { response.Error = ErrorCode.ERR_LinkFailed; return; } ThirdPartyInfo fbInfo = await FacebookHelper.GetFacebookUserInfo(fbToken); if (fbInfo == null) { response.Error = ErrorCode.ERR_LinkFailed; return; } long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(fbInfo.id, UserDataHelper.tagFB); if (thirdPartyUser == null) { long uid = player.uid; User user = await UserDataHelper.FindOneUser(uid); if (user == null) { response.Error = ErrorCode.ERR_LinkFailed; return; } //綁定第三方-FB thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagFB; thirdPartyUser.userId = fbInfo.id; thirdPartyUser.gender = fbInfo.gender; thirdPartyUser.location = fbInfo.location; thirdPartyUser.email = fbInfo.email; thirdPartyUser.name = fbInfo.name; thirdPartyUser.birthday = fbInfo.birthday; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); //取得新的第三方列表 response.LinkTypes.Clear(); response.LinkTypes.AddRange(await GetAllLinkType(user.Id)); } else { response.Error = ErrorCode.ERR_LinkIsExist; } }
public async static ETTask LinkByAppleId(Player player, LinkInfo info, L2C_Link response) { string appleId = CryptographyHelper.AESDecrypt(info.Secret); ThirdPartyInfo appleInfo = new ThirdPartyInfo { id = appleId, }; long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); ThirdPartyUser thirdPartyUser = await UserDataHelper.FindOneThirdPartyUser(appleInfo.id, UserDataHelper.tagAppleId); if (thirdPartyUser == null) { long uid = player.uid; User user = await UserDataHelper.FindOneUser(uid); if (user == null) { response.Error = ErrorCode.ERR_LinkFailed; return; } // 綁定第三方-Apple thirdPartyUser = ComponentFactory.CreateWithId <ThirdPartyUser>(IdGenerater.GenerateId()); thirdPartyUser.uid = user.Id; thirdPartyUser.party = UserDataHelper.tagAppleId; thirdPartyUser.userId = appleInfo.id; thirdPartyUser.gender = appleInfo.gender; thirdPartyUser.location = appleInfo.location; thirdPartyUser.email = appleInfo.email; thirdPartyUser.name = appleInfo.name; thirdPartyUser.birthday = appleInfo.birthday; thirdPartyUser.createAt = now; await UserDataHelper.UpsertThirdPartyUser(thirdPartyUser); // 取得新的第三方列表 response.LinkTypes.Clear(); response.LinkTypes.AddRange(await GetAllLinkType(user.Id)); } else { response.Error = ErrorCode.ERR_LinkIsExist; } }