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(); } ?>
查看全文
相关阅读:
WEBSERVICE 分析器错误信息: 未能创建类型
Powerdesigner中表导出sql语句关于字段注释乱码的问题
配置redis服务器允许远程连接
[转]ubuntu系统重新分区、根目录扩容
[转]自动驾驶平台Apollo 2.5环境搭建
[转]在ROS下使用zeroconf配置多机通信
ROS 安装完成后运行小乌龟示例程序
[转]RoboWare Studio的使用和发布器/订阅器的编写与测试
【转】ROS之topic和service通信比较
【转】贝叶斯公式的直观理解(先验概率/后验概率)
原文地址:https://www.cnblogs.com/javawebsoa/p/2458429.html
最新文章
*.app 无法打开或已损坏解决办法
mui IOS权限提示框修改
Java中split的用法
webpack3和webpack4区别
关于CommonsChunkPlugin的配置和用法
webpack--loaders
关于webpack4的使用
关于webpack的使用
vue.config.js配置
vue cli3--创建通用模版
热门文章
vue---导航栏点击跳转到对应位置
vue---顶部点击可居中导航(swiper)
HTML2Canvas---合成海报遇到问题总结
C#中DataTable删除多条数据
webform中配置服务器控件的样式
webform中按钮触发事件顺序
webform中jQuery获取checkboxlist的value值
webform中ajax.ajaxMethod使用方法
webform中Repeater中调用后台方法
webform中DropdownList绑定多个字段
Copyright © 2011-2022 走看看