zoukankan
html css js c++ java
IAP (内置购买) 服务器端代码
PHP 服务器端代码,
首先要确 php的 curl 和 SSL (open_ssl)这两个模块开启,可以在 php.ini 中去掉 这两个dll前面的分号。
<?php //服务器二次验证代码 function getReceiptData($receipt, $isSandbox = false) { if ($isSandbox) { $endpoint = 'https://sandbox.itunes.apple.com/verifyReceipt'; } else { $endpoint = 'https://buy.itunes.apple.com/verifyReceipt'; } $postData = json_encode( array('receipt-data' => $receipt) ); $ch = curl_init($endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); //这两行一定要加,不加会报SSL 错误 curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); $response = curl_exec($ch); $errno = curl_errno($ch); $errmsg = curl_error($ch); curl_close($ch); //判断时候出错,抛出异常 if ($errno != 0) { throw new Exception($errmsg, $errno); } $data = json_decode($response); //判断返回的数据是否是对象 if (!is_object($data)) { throw new Exception('Invalid response data'); } //判断购买时候成功 if (!isset($data->status) || $data->status != 0) { throw new Exception('Invalid receipt'); } //返回产品的信息 return array( 'quantity' => $data->receipt->quantity, 'product_id' => $data->receipt->product_id, 'transaction_id' => $data->receipt->transaction_id, 'purchase_date' => $data->receipt->purchase_date, 'app_item_id' => $data->receipt->app_item_id, 'bid' => $data->receipt->bid, 'bvrs' => $data->receipt->bvrs ); } //获取 App 发送过来的数据,设置时候是沙盒状态 $receipt = $_GET['data']; $isSandbox = true; //开始执行验证 try { $info = getReceiptData($receipt, $isSandbox); // 通过product_id 来判断是下载哪个资源 switch($info['product_id']){ case 'com.application.xxxxx.xxxx': Header("Location:xxxx.zip"); break; } } //捕获异常 catch(Exception $e) { echo 'Message: ' .$e->getMessage(); } ?>
查看全文
相关阅读:
【BZOJ3489】A simple rmq problem【kd树】
【BZOJ2716】天使玩偶【kd树】
Codeforces Round #520 (Div. 2)
Codeforces Round #521 (Div. 3)
Educational Codeforces Round 54
【hdu3507】Print Article 【斜率优化dp】
【HDU5992】Finding Hotels 【KD树】
【hdu4347】The Closest M Points 【KD树模板】
【BZOJ2806】Cheat 【广义后缀自动机+单调队列优化dp+二分】
SDSC2018 Day1
原文地址:https://www.cnblogs.com/javawebsoa/p/2458429.html
最新文章
java必备基础知识(一)
JAVA采用JDBC连接操作数据库详解
2013.12.21网站更新记录
Java中构造方法的执行顺序
Oracle复杂查询
java的InputStream和InputStreamReader有什么区别??
Struts2的模型驱动
2012年国家自然科学基金中标项目:云计算相关方向
java实现简单的单点登录
每日一题暂时停更,暑假我们不见不散
热门文章
6.13每日一题题解
6.12每日一题题解
6.10每日一题题解
6.9每日一题题解
6.8每日一题题解
6.6每日一题题解
6.5 每日一题题解
6.3每日一题题解
6.2每日一题题解
【BZOJ4154】Generating Synergy【kd树】
Copyright © 2011-2022 走看看