فهرست منبع

ios内购支付,password不传入,改用写死,沙盒模式防止数据找不到

lizhen_gitee 1 سال پیش
والد
کامیت
f274f1f516
1فایلهای تغییر یافته به همراه25 افزوده شده و 25 حذف شده
  1. 25 25
      application/api/controller/Payios.php

+ 25 - 25
application/api/controller/Payios.php

@@ -214,7 +214,6 @@ class Payios extends Api
 
         //苹果内购的验证收据
         $receipt_data = input('apple_receipt', '', 'trim');
-        $password     = input('password', '', 'trim');
         $out_trade_no = input('out_trade_no', '', 'trim');
         $transaction_id = input('transaction_id', '', 'trim');
 
@@ -246,7 +245,7 @@ class Payios extends Api
         }
 
         // 验证支付状态
-        $result = $this->validate_apple_pay($receipt_data,$password);
+        $result = $this->validate_apple_pay($receipt_data);
         if (!$result['status']) {// 验证不通过
             Db::rollback();
             filePut($prefix.'验证'.$result['message']);
@@ -457,7 +456,7 @@ class Payios extends Api
      * @param string $receipt_data 付款后凭证
      * @return array                验证是否成功
      */
-    function validate_apple_pay($receipt_data = '',$password = '') {
+    function validate_apple_pay($receipt_data = '') {
         // 验证参数
         if (strlen($receipt_data) < 20) {
             $result = array(
@@ -467,12 +466,12 @@ class Payios extends Api
             return $result;
         }
         // 请求验证
-        $html = $this->curl($receipt_data,$password);
+        $html = $this->curl($receipt_data);
         $data = json_decode($html, true);
+        $data['sandbox'] = '0';
 //        p($data);die;
 
         if ($data['status'] == '21002') {
-//            $this->error('21002');
             $result = array(
                 'status' => false,
                 'message' => 'status:21002'
@@ -481,16 +480,17 @@ class Payios extends Api
         }
 
         // 如果是沙盒数据 则验证沙盒模式 21008;正式数据 21007
-//        if ($data['status'] == '21007') {
-//            // 请求验证
-//            $html = $this->curl($receipt_data, 1);
-//            $data = json_decode($html, true);
-//            $data['sandbox'] = '1';
-//        }
+        if ($data['status'] == '21007') {
+            // 请求验证
+            $html = $this->curl($receipt_data, 1);
+            $data = json_decode($html, true);
+            $data['sandbox'] = '1';
+        }
+
         if (isset($_GET['debug'])) {
             exit(json_encode($data));
         }
-//        if ($data['receipt']['bundle_id'] != 'com.liuniukeji.mayivideo') {
+
         if ($data['receipt']['bundle_id'] != 'com.huxiu.tken') {
             $result = array(
                 'status' => false,
@@ -529,29 +529,29 @@ class Payios extends Api
      */
 
     //苹果也是建议这个校验逻辑由服务端完成。服务器需要先去请求正式环境。如果receipt是正式环境的,那么这个时候苹果会返回(21007)告诉我们这个是沙盒的receipt,那么服务器再去请求sandbox环境。
-    function curl($receipt_data, $password = '') {
+    function curl($receipt_data,$sandbox = 0) {
         //小票信息
-        $POSTFIELDS = array("receipt-data" => $receipt_data);
-
-        if(!empty($password)){
-            $POSTFIELDS['password'] = $password;
-        }
+        $POSTFIELDS = [
+            'receipt-data' => $receipt_data,
+            'password'     => '09ef214173a944808ac648b15fa02167'
+        ];
 
         $POSTFIELDS = json_encode($POSTFIELDS, 320);
-//        $POSTFIELDS = '{' . '"receipt-data":' . '"' . $receipt_data . '"' .'}';
-//        p($POSTFIELDS);die;
+
         //正式购买地址 沙盒购买地址
         $url_buy = "https://buy.itunes.apple.com/verifyReceipt";
         $url_sandbox = "https://sandbox.itunes.apple.com/verifyReceipt";
-//        if ($sandbox > 0) {
-        if (config('site.ios_pay_sandbox') > 0) {
+
+        //默认后台控制
+        if (config('site.ios_pay_sandbox') > 0 ) {
             $url = $url_buy;
         } else {
             $url = $url_sandbox;
         }
-
-        // 上架通过直接使用正式地址
-//        $url = $url_sandbox;
+        //强制沙盒
+        if($sandbox == 1){
+            $url = $url_sandbox;
+        }
 
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);