Java 应用商店收据验证
Java app store receipt validation
我正在尝试验证来自 Java 服务的 Apple App Store 收据。除了错误 21002,"Receipt Data Property Was Malformed",我什么也得不到。我读过其他人有同样的问题,但没有看到解决方案。我认为这将是相当直接的,但是,一直无法解决这个错误。这是我的代码:
EDIT 通过在下面标记为 // EDIT 的更改,我现在在 verifyReceipt 调用的 return 中得到一个异常,也 makred //EDIT:
String hexDataReceiptData = "<30821e3b 06092a86 4886f70d 010702a0 .... >";
// EDIT
hexDataReceiptData = hexDataReceiptData.replace(">", "").replace("<", "");
final String base64EncodedReceiptData = Base64.encode(hexDataReceiptData.getBytes());
JSONObject jsonObject = new JSONObject();
try
{
jsonObject.put("receipt-data",base64EncodedReceiptData);
}
catch (JSONException e)
{
e.printStackTrace();
}
URL url = new URL("https://sandbox.itunes.apple.com/verifyReceipt");
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
//Send request
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(jsonObject.toString());
wr.flush();
//Get Response
BufferedReader rd =
new BufferedReader(new
InputStreamReader(connection.getInputStream()));
StringBuilder httpResponse = new StringBuilder();
String line;
while ((line = rd.readLine()) != null)
{
httpResponse.append(line);
httpResponse.append('\r');
}
wr.close();
rd.close();
// EDIT
// {"status":21002, "exception":"java.lang.IllegalArgumentException"}
在这里发布:Java and AppStore receipt verification,在iOS中进行base64编码并发送到服务器。但是,为什么?
我正在尝试验证来自 Java 服务的 Apple App Store 收据。除了错误 21002,"Receipt Data Property Was Malformed",我什么也得不到。我读过其他人有同样的问题,但没有看到解决方案。我认为这将是相当直接的,但是,一直无法解决这个错误。这是我的代码:
EDIT 通过在下面标记为 // EDIT 的更改,我现在在 verifyReceipt 调用的 return 中得到一个异常,也 makred //EDIT:
String hexDataReceiptData = "<30821e3b 06092a86 4886f70d 010702a0 .... >";
// EDIT
hexDataReceiptData = hexDataReceiptData.replace(">", "").replace("<", "");
final String base64EncodedReceiptData = Base64.encode(hexDataReceiptData.getBytes());
JSONObject jsonObject = new JSONObject();
try
{
jsonObject.put("receipt-data",base64EncodedReceiptData);
}
catch (JSONException e)
{
e.printStackTrace();
}
URL url = new URL("https://sandbox.itunes.apple.com/verifyReceipt");
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
//Send request
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(jsonObject.toString());
wr.flush();
//Get Response
BufferedReader rd =
new BufferedReader(new
InputStreamReader(connection.getInputStream()));
StringBuilder httpResponse = new StringBuilder();
String line;
while ((line = rd.readLine()) != null)
{
httpResponse.append(line);
httpResponse.append('\r');
}
wr.close();
rd.close();
// EDIT
// {"status":21002, "exception":"java.lang.IllegalArgumentException"}
在这里发布:Java and AppStore receipt verification,在iOS中进行base64编码并发送到服务器。但是,为什么?