feat(feedback): implement feedbacks.

This commit is contained in:
huanghongxun
2021-10-03 20:32:40 +08:00
parent c2a87e2474
commit dfb2d3f2bf
13 changed files with 522 additions and 198 deletions

View File

@@ -53,7 +53,7 @@ public class MicrosoftService {
private static final String AUTHORIZATION_URL = "https://login.live.com/oauth20_authorize.srf";
private static final String ACCESS_TOKEN_URL = "https://login.live.com/oauth20_token.srf";
private static final String SCOPE = "XboxLive.signin offline_access";
private static final int[] PORTS = { 29111, 29112, 29113, 29114, 29115 };
private static final int[] PORTS = {29111, 29112, 29113, 29114, 29115};
private static final ThreadPoolExecutor POOL = threadPool("MicrosoftProfileProperties", true, 2, 10,
TimeUnit.SECONDS);
private static final Pattern OAUTH_URL_PATTERN = Pattern
@@ -257,19 +257,20 @@ public class MicrosoftService {
private static void getXBoxProfile(String uhs, String xstsToken) throws IOException {
HttpRequest.GET("https://profile.xboxlive.com/users/me/profile/settings",
pair("settings", "GameDisplayName,AppDisplayName,AppDisplayPicRaw,GameDisplayPicRaw,"
+ "PublicGamerpic,ShowUserAsAvatar,Gamerscore,Gamertag,ModernGamertag,ModernGamertagSuffix,"
+ "UniqueModernGamertag,AccountTier,TenureLevel,XboxOneRep,"
+ "PreferredColor,Location,Bio,Watermarks," + "RealName,RealNameOverride,IsQuarantined"))
pair("settings", "GameDisplayName,AppDisplayName,AppDisplayPicRaw,GameDisplayPicRaw,"
+ "PublicGamerpic,ShowUserAsAvatar,Gamerscore,Gamertag,ModernGamertag,ModernGamertagSuffix,"
+ "UniqueModernGamertag,AccountTier,TenureLevel,XboxOneRep,"
+ "PreferredColor,Location,Bio,Watermarks," + "RealName,RealNameOverride,IsQuarantined"))
.accept("application/json")
.authorization(String.format("XBL3.0 x=%s;%s", uhs, xstsToken)).header("x-xbl-contract-version", "3")
.authorization(String.format("XBL3.0 x=%s;%s", uhs, xstsToken))
.header("x-xbl-contract-version", "3")
.getString();
}
private static MinecraftProfileResponse getMinecraftProfile(String tokenType, String accessToken)
throws IOException, AuthenticationException {
HttpURLConnection conn = HttpRequest.GET("https://api.minecraftservices.com/minecraft/profile")
.authorization(String.format("%s %s", tokenType, accessToken))
.authorization(tokenType, accessToken)
.createConnection();
int responseCode = conn.getResponseCode();
if (responseCode == HTTP_NOT_FOUND) {
@@ -341,27 +342,27 @@ public class MicrosoftService {
* redirect URI used to obtain the authorization
* code.","correlation_id":"??????"}
*/
private static class LiveAuthorizationResponse {
public static class LiveAuthorizationResponse {
@SerializedName("token_type")
String tokenType;
public String tokenType;
@SerializedName("expires_in")
int expiresIn;
public int expiresIn;
@SerializedName("scope")
String scope;
public String scope;
@SerializedName("access_token")
String accessToken;
public String accessToken;
@SerializedName("refresh_token")
String refreshToken;
public String refreshToken;
@SerializedName("user_id")
String userId;
public String userId;
@SerializedName("foci")
String foci;
public String foci;
}
private static class LiveRefreshResponse {
@@ -391,14 +392,13 @@ public class MicrosoftService {
}
/**
*
* Success Response: { "IssueInstant":"2020-12-07T19:52:08.4463796Z",
* "NotAfter":"2020-12-21T19:52:08.4463796Z", "Token":"token", "DisplayClaims":{
* "xui":[ { "uhs":"userhash" } ] } }
*
* <p>
* Error response: { "Identity":"0", "XErr":2148916238, "Message":"",
* "Redirect":"https://start.ui.xboxlive.com/AddChildToFamily" }
*
* <p>
* XErr Candidates: 2148916233 = missing XBox account 2148916238 = child account
* not linked to a family
*/
@@ -524,12 +524,16 @@ public class MicrosoftService {
/**
* Wait for authentication
*
*
* @return authentication code
* @throws InterruptedException if interrupted
* @throws ExecutionException if an I/O error occurred.
*/
String waitFor() throws InterruptedException, ExecutionException;
default String getIdToken() {
return null;
}
}
private static final Gson GSON = new GsonBuilder()

View File

@@ -63,6 +63,14 @@ public abstract class HttpRequest {
return header("Authorization", token);
}
public HttpRequest authorization(String tokenType, String tokenString) {
return authorization(tokenType + " " + tokenString);
}
public HttpRequest authorization(Authorization authorization) {
return authorization(authorization.getTokenType(), authorization.getAccessToken());
}
public HttpRequest header(String key, String value) {
headers.put(key, value);
return this;
@@ -189,4 +197,9 @@ public abstract class HttpRequest {
return new HttpPostRequest(url);
}
public interface Authorization {
String getTokenType();
String getAccessToken();
}
}