iOS应用内支付(IAP)php后端验证代码
2021/9/6 17:07:03
本文主要是介绍iOS应用内支付(IAP)php后端验证代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
$is_sandbox = input('is_sandbox', 0, 'intval'); $receipt = urlencode($_REQUEST['receipt-data']); $receipt = str_replace('%2F','/',$receipt); $receipt = str_replace('%5C','',$receipt); $receipt = str_replace('%3D','=',$receipt); $receipt = str_replace('%2B','+',$receipt); if ($is_sandbox == 1) { $url = "https://sandbox.itunes.apple.com/verifyReceipt"; } else { $url = "https://buy.itunes.apple.com/verifyReceipt"; } $json = '{"receipt-data":"'.$receipt.'"}'; $result = $this->http_post_json($url, $json); if (isset($result['status']) && $result['status'] == 0 && !empty($result['receipt']['in_app'])) { $pay_log_insert = []; $time = time(); foreach ($result['receipt']['in_app'] as $key => $val) { $pay_log_insert[] = [ 'user_id' => $user_id, 'order_id' => 0, 'title' => $title, 'price' => $price, 'article_type' => $type, 'log_type' => 2, 'question_num' => $num, 'create_time' => $time, 'delete_time' => 0, 'receipt_data' => $receipt, ]; } private function http_post_json($url, $json) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS,$json); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($json)) ); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_POST, 1); // curl_setopt($ch, CURLOPT_POSTFIELDS, $json); 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 (!$response) { return $errmsg; } $data = json_decode($response, true); return $data; }
这篇关于iOS应用内支付(IAP)php后端验证代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-11开源 PHP 商城项目 CRMEB 二次开发和部署教程
- 2024-11-09怎么使用php在kaufland平台刊登商品?-icode9专业技术文章分享
- 2024-11-05PHP的抽象类和接口是什么,有什么区别-icode9专业技术文章分享
- 2024-11-01开源 PHP 商城项目 CRMEB 安装和使用教程
- 2024-11-01用php和mysql写无限分类,有哪几种方法-icode9专业技术文章分享
- 2024-10-31php数据分表导出时部分数据无法导出什么原因-icode9专业技术文章分享
- 2024-10-30有经验的 PHP 开发者学习一门新的编程语言,有哪些推荐的有前景的语言-icode9专业技术文章分享
- 2024-10-21php 检测图片是否篡改过-icode9专业技术文章分享
- 2024-10-20fruitcake/php-cors 该怎么使用-icode9专业技术文章分享
- 2024-10-18PHP7.1可以使用哪个版本的swoole-icode9专业技术文章分享