首页 > 移动平台 > 详细

IOSIAP二次验证

时间:2017-02-07 12:28:24      阅读:220      评论:0      收藏:0      [点我收藏+]

直接上代码

 1 import com.alibaba.fastjson.JSONObject;
 2 import java.io.BufferedReader;
 3 import java.io.InputStreamReader;
 4 import java.io.PrintStream;
 5 import java.net.URL;
 6 import javax.net.ssl.HttpsURLConnection;
 7 
 8 public class IosIAP {
 9     public static JSONObject verifyReceipt1(String recepit) throws Exception {
10         String url = "https://buy.itunes.apple.com/verifyReceipt";
11 
12         return verifyReceipt1(url, recepit);
13     }
14 
15     public static JSONObject verifyReceipt1(String url, String receipt)
16             throws Exception {
17         HttpsURLConnection connection = (HttpsURLConnection) new URL(url)
18                 .openConnection();
19         connection.setRequestMethod("POST");
20         connection.setDoOutput(true);
21         connection.setAllowUserInteraction(false);
22         PrintStream ps = new PrintStream(connection.getOutputStream());
23         ps.print("{\"receipt-data\": \"" + receipt + "\"}");
24         ps.close();
25         BufferedReader br = new BufferedReader(new InputStreamReader(
26                 connection.getInputStream()));
27 
28         StringBuffer sb = new StringBuffer();
29         String str;
30         while ((str = br.readLine()) != null) {
31             sb.append(str);
32         }
33         br.close();
34         String resultStr = sb.toString();
35         JSONObject result = JSONObject.parseObject(resultStr);
36         if ((result != null)
37                 && (result.getInteger("status").intValue() == 21007)) {
38             return verifyReceipt1(
39                     "https://sandbox.itunes.apple.com/verifyReceipt", receipt);
40         }
41         return result;
42     }
43 }

 

IOSIAP二次验证

原文:http://www.cnblogs.com/coates/p/6373444.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!