跳到主要内容

年龄检查

如果需要年龄门槛,现在必须进行一次 /age-gate/check 的 API 调用,以确定下一步的工作流程。如果玩家的年龄低于发布者门户中为游戏配置的最低年龄,返回的 status 字段将为 PROHIBITED。此时,玩家应被阻止继续游戏。如果玩家提供了需要在当前地点获得可验证的家长同意的出生日期,则 status 字段的值将为 CHALLENGE,并且一个新的同意挑战的 ID 将在名为 challengeID 的字段中返回。此时,游戏必须要求玩家寻求家长同意。最后,如果 status 的值为 PASS,则玩家可以继续进入游戏。

用Unreal C++创建会话
void UKidWorkflow::StartKidSessionWithDOB(const FString& Location, const FString& DOB)
{
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
JsonObject->SetStringField(TEXT("dateOfBirth"), DOB);
JsonObject->SetStringField(TEXT("jurisdiction"), Location);

FString ContentJsonString;
TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&ContentJsonString);
FJsonSerializer::Serialize(JsonObject.ToSharedRef(), Writer);

HttpRequestHelper::PostRequestWithAuth(BaseUrl + TEXT("/age-gate/check"), ContentJsonString,
AuthToken, [this](FHttpResponsePtr Response, bool bWasSuccessful)
{
if (bWasSuccessful)
{
TSharedPtr<FJsonObject> JsonResponse;
TSharedRef<TJsonReader<>> Reader =
TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(Reader, JsonResponse))
{
FString Status = JsonResponse->GetStringField(TEXT("status"));
if (Status == TEXT("CHALLENGE"))
{
TSharedPtr<FJsonObject> Challenge =
JsonResponse->GetObjectField(TEXT("challenge"));
FString ChallengeId =
Challenge->GetStringField(TEXT("challengeId"));
FString OneTimePassword =
Challenge->GetStringField(TEXT("oneTimePassword"));
FString QRCodeUrl =
Challenge->GetStringField(TEXT("url"));
SaveChallengeId(ChallengeId);

ShowConsentChallenge(ChallengeId, ConsentTimeoutSeconds, OneTimePassword,
QRCodeUrl, [this](bool bConsentGranted, const FString &SessionId)
{
if (bConsentGranted)
{
GetSessionPermissions(SessionId, TEXT(""));
ClearChallengeId();
}
else
{
HandleNoConsent();
}
});
}
else if (Status == TEXT("PASS"))
{
SessionInfo = JsonResponse->GetObjectField(TEXT("session"));
SaveSessionInfo();
}
else if (Status == TEXT("PROHIBITED"))
{
HandleProhibitedStatus();
}
}
}
});
}