我必须实现一个 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
任何的想法 ?