The Extension of AT File is incorrect.
Authentication information is specified based on the request header.
The details are as follows: App-level access token: Authorization:
Basic Base64(APPAT:atvalue)
- Example: The app-level access token is thisIsAppAtValue, then APPAT:atvalue is APPAT:thisIsAppAtValue. Therefore, replace
APPAT:atvalue in Base64(APPAT:atvalue) with APPAT:thisIsAppAtValue,
and value QVBQQVQ6dGhpc0lzQXBwQXRWYWx1ZQ== is obtained. The value of
Authorization in the request header is as follows: Basic
QVBQQVQ6dGhpc0lzQXBwQXRWYWx1ZQ==
The sample code is as follows:
/* Build Authorization in Header
*
* @param appAt app AccessToken
* @return headers
*/
public static Map<String, String> buildAuthorization(String appAt) {
String oriString = MessageFormat.format("APPAT:{0}", appAt);
String authorization =
MessageFormat.format("Basic {0}", Base64.encodeBase64String(oriString.getBytes(StandardCharsets.UTF_8)));
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", authorization);
headers.put("Content-Type", "application/json; charset=UTF-8");
return headers;
}
HMS In-App Purchases(IAP) Severdemo on Github.