アップルストアで購入されたときのレシートの確認プログラムが、
どう作ってよいのかわからないのですが、
どこかにサンプルなどありまでしょうか?
(国外も探したのですが、JAVAで認識しない型のクラス変数などを(DefaultHttpClient)
使っており、流用できないのです)
PS.サンプルソースがありました。
ただ、DefaultHttpClient、HttpClientParams、JSONObjectなどなど、
ecilpsで、自動宣言してくれるものがなく、これらがエラーになって困っています。
try { String url = "https://buy.itunes.apple.com/verifyReceipt"; DefaultHttpClient client = null; try { String input = IOUtils.toString(is); log.info("THE INPUTSTREAM: " + input); JSONObject receipt = new JSONObject(); receipt.put("receipt-data", input); client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); StringEntity entity = new StringEntity(receipt.toString()); entity.setContentType("application/json"); post.setEntity(entity); HttpClientParams.setRedirecting(post.getParams(), false); HttpResponse response = client.execute(post); if (300 <= response.getStatusLine().getStatusCode()) { throw new RuntimeException("No response from iTune store. status code: " + response.getStatusLine().getStatusCode()); } if (null == response.getEntity()) { log.info("Response is null"); throw new Exception("Response is null"); } StringBuilder sb = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); for (String line; null != (line = reader.readLine());) { sb.append(line); } JSONObject json = new JSONObject(sb.toString()); log.info("THE JSON" + json); //Then work with json below } catch (Exception e) { throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build()); } finally { if (null != client) { client.getConnectionManager().shutdown(); } }
回答1件
あなたの回答
tips
プレビュー