Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.9k views
in Technique[技术] by (71.8m points)

"Token is expired or invalid" when trying to server-side validate Huawei subscription

I'm trying to do a server-side verification of Huawei subscription, but currently I'm stuck at verification part

  1. Im successfully obtain access_token from this url
  1. Do a base64encode UTF-8 format of string 'APPAT:my_access_token'

  2. Then I'm trying to get purchaseDetails from https://subscr-drcn.iap.hicloud.com/sub/applications/v2/purchases/get. Im sending subscriptionId and purchaseToken in json format and base64encoded access_token in Authorization ('Basic my_access_token') header and Content-Type=application/json;charset=UTF-8

  3. Every time I get this response:

    { "responseCode": "6", "responseMessage": "Token is expired or invalid" }

Searching for this message didn't help. What can be the problem with it? Is it invalid purchaseToken or invalid accessToken?

Please help me with this, thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please check as follows:

  1. Check your access_token: obtain the access_token and print it.
  2. When referencing Base64, refer to import org.apache.commons.codec.binary.Base64;
  3. Add to the header correctly:
* 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;
    }
    /**

For more details, see docs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...