Apple 购买:使用 Rest 模板验证收据

Apple purchase : verify receipt using Rest template

我必须实施一个 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);
....

}

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

有什么想法吗?

什么是Purchaseclass?客户端(iOS App)发送到我们服务器端的收据数据应该已经是base64编码了。