0

我必须实现一个 API,旨在使用 Rest 模板通过 Apple 服务器验证收据。但是,我总是从https://sandbox.itunes.apple.com/verifyReceipt收到状态代码 21002

 public void verifyReceipt(Purchase purchase) {

    String uri = "https://sandbox.itunes.apple.com/verifyReceipt";
    String receipt = new String(Base64.getEncoder().encode(purchase.getReceipt().getBytes()));

    Map<String, String> params = new HashMap<>();
    params.put("receipt-data", receipt);
    params.put("password", "secret");

    Gson gson = new Gson();
    String json = gson.toJson(params);
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> request = new HttpEntity<>(json, headers);
    ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.POST, request ,String.class);
....

}

苹果文档: https ://developer.apple.com/documentation/appstorereceipts/verifyreceipt

任何的想法 ?

4

1 回答 1

1

什么是Purchase班级?客户端(iOS 应用程序)发送到我们服务器端的收据数据应该已经是 base64 编码的。

于 2021-06-08T08:00:05.753 回答