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-12-19php8的协程和hyperf的协程有什么区别?-icode9专业技术文章分享
- 2024-12-19php8 的fiber是什么?-icode9专业技术文章分享
- 2024-12-05怎么在php8,1 里面开启 debug?-icode9专业技术文章分享
- 2024-12-05怎么在php8,1 里面开启 debug?-icode9专业技术文章分享
- 2024-11-29使用PHP 将ETH账户的资产汇集到一个账户
- 2024-11-23怎么实现安卓+php 热更新方案?-icode9专业技术文章分享
- 2024-11-22PHP 中怎么实现判断多个值是否为空、null 或者为 false?-icode9专业技术文章分享
- 2024-11-11开源 PHP 商城项目 CRMEB 二次开发和部署教程
- 2024-11-09怎么使用php在kaufland平台刊登商品?-icode9专业技术文章分享
- 2024-11-05PHP的抽象类和接口是什么,有什么区别-icode9专业技术文章分享