dever 6 lat temu
rodzic
commit
a8ceabb2ca
2 zmienionych plików z 24 dodań i 23 usunięć
  1. 11 23
      lib/Apple.php
  2. 13 0
      src/Api.php

+ 11 - 23
lib/Apple.php

@@ -6,9 +6,11 @@ class Apple extends Core
 	/**
 	 * 检测
 	 */
-	public function check($receipt_data)
-	{  
+	public function check($receipt_data, $order_id, $cash = 0)
+	{
+        $this->log('苹果支付-初始化', $receipt_data);
 		if (strlen($receipt_data) < 20) {
+            $this->updateOrder($order_id, $cash, '参数非法');
 			Dever::alert('参数非法');
 		}
 		$result = $this->curl($receipt_data);
@@ -19,29 +21,15 @@ class Apple extends Core
 	        $result['sandbox'] = 1;	
 		}
 
-		if (Dever::input('debug')) {   
-	        exit(json_encode($result));   
-	    }
-
 		// 判断是否购买成功   
-	    if (intval($result['status']) ===0 ) {
-
+	    if (intval($result['status']) === 0) {
+            $this->updateOrder($order_id, $cash);
+            $result['yes'] = 1;
 	    } else {   
-	       	Dever::alert('购买失败 status:'.$data['status']);
+	       	$this->updateOrder($order_id, $cash, 'error');
+            $result['yes'] = 2;
 	    }
-		$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;
+		return $result;
 	}
 
 	private function curl($receipt_data, $sandbox = false)
@@ -63,7 +51,7 @@ class Apple extends Core
         $result = curl_exec($ch);
         curl_close($ch);
         $input['url'] = $url;
-        $this->log('苹果内购支付-调用苹果接口', $input);
+        $this->log('苹果支付-调用苹果接口', $input);
         return Dever::json_decode($result);
 	}
 }

+ 13 - 0
src/Api.php

@@ -63,6 +63,18 @@ class Api
 		return $this->method->app($this->get(3));
 	}
 
+	/**
+	 * 发起支付 用于苹果内购支付
+	 *
+	 * @return mixed
+	 */
+	public function apple($param = array())
+	{
+		$this->init($param);
+		# 只需验证苹果过来的参数即可
+		return Dever::load('pay/lib/apple')->check($this->other, $this->order_id, $this->cash);
+	}
+
 	/**
 	 * 发起支付 用于页面支付
 	 *
@@ -110,6 +122,7 @@ class Api
 		$this->refer = $this->getParam($param, 'refer');
 		$this->order_id = $this->getParam($param, 'order_id');
 		$this->openid = $this->getParam($param, 'openid');
+		$this->other = $this->getParam($param, 'other');
 
 		if (!$this->project_id) {
 			$this->project_id = false;