我正在尝试 IAP 的服务器端 Canceled api,但我无法使用此 api 取消订阅。每次单击取消时,我都会收到此错误: responseCode:"6","responseMessage":"900030-authorization format invalid"
我使用的 API 是这样的: https ://subscr-dra.iap.hicloud.com/sub/applications/v2/purchases/stop
有人可以帮我解决这个问题吗?
我正在尝试 IAP 的服务器端 Canceled api,但我无法使用此 api 取消订阅。每次单击取消时,我都会收到此错误: responseCode:"6","responseMessage":"900030-authorization format invalid"
我使用的 API 是这样的: https ://subscr-dra.iap.hicloud.com/sub/applications/v2/purchases/stop
有人可以帮我解决这个问题吗?
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.
检查您作为授权放入标头的令牌的格式。
代码:
let oriString = 'APPAT:' + app_level_access_token;
let authorizationToken = new Buffer.from(oriString).toString('base64'); // converting the token into Base64.
现在authorizationToken
,您可以在标题中使用它。