Verify an App Store Transaction Receipt 【苹果服务端 验证一个应用程序商店交易收据有效性】
来源:互联网 发布:淘宝优惠券分享到微信 编辑:程序博客网 时间:2024/04/27 18:59
1、 从Transaction 的TransactionReceipt属性中得到接收的数据,并以base64编码;
2、创建JSON对象,字典格式,单键值对,键名为“receiptdata”,值为上一次编码的数据,效果:
{"receipt-data":"base64编码之后的数据"}
3、发送HTTP POST请求,将数据发送到App Store ,其地址为:https://buy.itunes.apple.com/verifyReceipt
4、App Store的返回值也是一个JSON格式对象,包括两个键值对:
{
"status" : 0,
"receipt" : { … }
}
说明:
如果status的值为0,就说明该receipt为有效的,否则就是无效的。
public int verifyReceipt( byte[] receipt) { int status = -1; //This is the URL of the REST webservice in iTunes App Store URL url = new URL("https://buy.itunes.apple.com/verifyReceipt"); //make connection, use post mode HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setAllowUserInteraction(false); //Encode the binary receipt data into Base 64 //Here I'm using org.apache.commons.codec.binary.Base64 as an encoder, since commons-codec is already in Grails classpath Base64 encoder = new Base64(); String encodedReceipt = new String(encoder.encode(receipt)); //Create a JSON query object //Here I'm using Grails' org.codehaus.groovy.grails.web.json.JSONObject Map map = new HashMap(); map.put("receipt-data", encodedReceipt); JSONObject jsonObject = new JSONObject(map); //Write the JSON query object to the connection output stream PrintStream ps = new PrintStream(connection.getOutputStream()); ps.print(jsonObject.toString()); ps.close(); //Call the service BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); //Extract response String str; StringBuffer sb = new StringBuffer(); while ((str = br.readLine()) != null) { sb.append(str); sb.append("/n"); } br.close(); String response = sb.toString(); //Deserialize response JSONObject result = new JSONObject(response); status = result.getInt("status"); if (status == 0) { //provide content } else { //signal error, throw an exception, do your stuff honey! } return status ; }
验证的方式也可以采用HTTP协议:HttpClient,下载httpcomponents-client,然后导入lib里的几个jar包。
这也是一种方式,不再进行多余的说明了。所谓条条道路通“苹果”。
- Verify an App Store Transaction Receipt 【苹果服务端 验证一个应用程序商店交易收据有效性】
- 苹果开发——App内购以及验证store的收据
- 【IAP支付之三】苹果IAP安全支付与防范 receipt收据验证
- 【IAP支付之三】苹果IAP安全支付与防范 receipt收据验证
- Mac App Store receipt validater
- iOS App上传到苹果应用商店App Store教程
- iOS App上传到苹果应用商店App Store教程
- App Store Review Guidelines 苹果商店审核指导
- iOS--在线搜索苹果 App Store 应用商店
- 苹果支付php服务端处理,以及双重验证,收据,状态码
- IOS应用程序发布到苹果APP STORE
- IOS应用程序发布到苹果APP STORE
- App Store,应用程序商店绝非说开就开
- 【原创】线上应用程序商店(App Store)调研报告
- 关于手机应用程序商店(App Store)的思考
- 应用商店App Store
- APP STORE 付费验证(IAP)服务端验证全过程
- APP STORE 付费验证(IAP)服务端验证全过程
- 谨慎使用java变长数据结构
- C++初始化成员列表(member initialization list)
- perl简单读写文件
- wince的build过程
- Unix/Linux中nohup命令
- Verify an App Store Transaction Receipt 【苹果服务端 验证一个应用程序商店交易收据有效性】
- Item 44 与模板参数无关的代码
- 让c++程序暂停的方法有哪些?
- 国企&外企
- 10-07-15Ubuntu的root密码忘记已解决
- C++代码和调试
- Jemter 远程连接多台pc测试
- Ubuntu下修改多系统默认开机启动顺序
- sharepoint 获取userprofileManager中用户详细信息