Java应用商店收据验证

时间:2015-07-26 23:19:36

标签: java in-app-purchase

我正在尝试从Java服务验证Apple App Store收据。除了错误21002,我无法得到任何回报,"收据数据属性格式错误"。我已经阅读了其他有同样问题的人,但是,没有看到解决方案。我认为这将是相当直接的,但是,无法绕过错误。这是我的代码:

编辑通过将更改标记为// EDIT,我现在从verifyReceipt调用的返回中获得异常,也是makred //编辑:

    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"}

1 个答案:

答案 0 :(得分:0)

如此处发布:Java and AppStore receipt verification,在iOS中执行base64编码并发送到服务器。但是,为什么?