我正在尝试在服务器端验证付款收据。我得到了{"status":21002, "exception":"java.lang.IllegalArgumentException"}
回报
这是代码:
private final static String _sandboxUriStr = "https://sandbox.itunes.apple.com/verifyReceipt";
public static void processPayment(final String receipt) throws SystemException
{
final BASE64Encoder encoder = new BASE64Encoder();
final String receiptData = encoder.encode(receipt.getBytes());
final String jsonData = "{\"receipt-data\" : \"" + receiptData + "\"}";
System.out.println(receipt);
System.out.println(jsonData);
try
{
final URL url = new URL(_sandboxUriStr);
final HttpURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
final OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(jsonData);
wr.flush();
// Get the response
final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null)
{
System.out.println(line);
}
wr.close();
rd.close();
}
catch (IOException e)
{
throw new SystemException("Error when trying to send request to '%s', %s", _sandboxUriStr, e.getMessage());
}
}
我的收据如下所示:
{\n\t"signature" = "[exactly_1320_characters]";\n\t"purchase-info" =
"[exactly_868_characters]";\n\t"environment" = "Sandbox";\n\t"pod" =
"100";\n\t"signing-status" = "0";\n}
带有 BASE64 编码收据的收据数据如下所示:
{"receipt-data" : "[Block_of_chars_76x40+44=3084_chars_total]"}
有人有一个想法或示例代码,我如何从收据字符串中获取回复 JSON,在这里提到?