"Token is expired or invalid" 尝试在服务器端验证华为订阅时
"Token is expired or invalid" when trying to server-side validate Huawei subscription
我正在尝试对华为订阅进行服务器端验证,但目前卡在验证部分
- 我成功从this url
获得了access_token
对字符串进行base64编码UTF-8格式'APPAT:my_access_token'
然后我尝试从 https://subscr-drcn.iap.hicloud.com/sub/applications/v2/purchases/get 获取购买详情。我以 json 格式发送 subscriptionId 和 purchaseToken,在 Authorization ('Basic my_access_token') header 和 Content-Type=application/json;charset=UTF-8
中发送 base64encoded access_token
每次我收到这样的回复:
{
“响应代码”:“6”,
"responseMessage": "令牌已过期或无效"
}
搜索此邮件没有帮助。它可能有什么问题?是无效的 purchaseToken 还是无效的 accessToken?
请帮我解决这个问题,谢谢!
请检查如下:
- 检查您的 access_token:获取 access_token 并打印它。
- 引用Base64时,参考
import org.apache.commons.codec.binary.Base64;
- 正确添加到页眉:
* Construct an Authorization field in the request header.
*
* @param appAt App-level access token.
* @return headers Return the request header.
*/
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;
}
/**
有关详细信息,请参阅 docs。
我正在尝试对华为订阅进行服务器端验证,但目前卡在验证部分
- 我成功从this url 获得了access_token
对字符串进行base64编码UTF-8格式'APPAT:my_access_token'
然后我尝试从 https://subscr-drcn.iap.hicloud.com/sub/applications/v2/purchases/get 获取购买详情。我以 json 格式发送 subscriptionId 和 purchaseToken,在 Authorization ('Basic my_access_token') header 和 Content-Type=application/json;charset=UTF-8
中发送 base64encoded access_token每次我收到这样的回复:
{ “响应代码”:“6”, "responseMessage": "令牌已过期或无效" }
搜索此邮件没有帮助。它可能有什么问题?是无效的 purchaseToken 还是无效的 accessToken?
请帮我解决这个问题,谢谢!
请检查如下:
- 检查您的 access_token:获取 access_token 并打印它。
- 引用Base64时,参考
import org.apache.commons.codec.binary.Base64;
- 正确添加到页眉:
* Construct an Authorization field in the request header.
*
* @param appAt App-level access token.
* @return headers Return the request header.
*/
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;
}
/**
有关详细信息,请参阅 docs。