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

问题描述

我必须实现一个 API,该 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

有什么想法吗?

解决方法

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...