dever 6 년 전
부모
커밋
bb353ebbd9
1개의 변경된 파일69개의 추가작업 그리고 0개의 파일을 삭제
  1. 69 0
      lib/Apple.php

+ 69 - 0
lib/Apple.php

@@ -0,0 +1,69 @@
+<?php namespace Pay\Lib;
+use Dever;
+# 苹果内购支付验证接口 代码摘自网络
+class Apple extends Core
+{
+	/**
+	 * 检测
+	 */
+	public function check($receipt_data)
+	{  
+		if (strlen($receipt_data) < 20) {
+			Dever::alert('参数非法');
+		}
+		$result = $this->curl($receipt_data);
+
+		//如果是沙盒数据 则验证沙盒模式  
+		if ($result['status'] == 21007) {
+			$result = $this->curl($receipt_data, true);    
+	        $result['sandbox'] = 1;	
+		}
+
+		if (Dever::input('debug')) {   
+	        exit(json_encode($result));   
+	    }
+
+		// 判断是否购买成功   
+	    if (intval($result['status']) ===0 ) {
+
+	    } else {   
+	       	Dever::alert('购买失败 status:'.$data['status']);
+	    }
+		$this->log('支付回调-初始化', $input);
+		
+		$tools = new \Cmbc\Handle();
+		$callback = $tools->get('notify', $this->config);
+		$result = $callback->request($input, $this);
+		if ($result) {
+			$this->log('支付回调-获取数据', $result);
+			$this->updateOrder($result['mhtOrderNo'], $result['mhtOrderAmt']);
+			echo 'success=Y';die;
+		} else {
+			echo 'success=N';die;
+		}
+		return;
+	}
+
+	private function curl($receipt_data, $sandbox = false)
+	{
+		//小票信息
+        $input = array("receipt-data" => $receipt_data);
+        $post = json_encode($input);
+    
+        //正式购买地址 沙盒购买地址
+        $url_buy     = "https://buy.itunes.apple.com/verifyReceipt";
+        $url_sandbox = "https://sandbox.itunes.apple.com/verifyReceipt";
+        $url = $sandbox ? $url_sandbox : $url_buy;
+    
+        //简单的curl
+        $ch = curl_init($url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
+        $result = curl_exec($ch);
+        curl_close($ch);
+        $input['url'] = $url;
+        $this->log('苹果内购支付-调用苹果接口', $input);
+        return Dever::json_decode($result);
+	}
+}