dever 6 years ago
parent
commit
90582d366b
3 changed files with 32 additions and 11 deletions
  1. 5 4
      lib/Core.php
  2. 12 7
      lib/Wechat.php
  3. 15 0
      src/Api.php

+ 5 - 4
lib/Core.php

@@ -6,7 +6,7 @@ class Core
 	/**
 	 * 更新订单状态
 	 */
-	protected function updateOrder($order_id, $cash, $desc = '')
+	public function updateOrder($order_id, $cash, $desc = '')
 	{
 		$db = Dever::db('pay/order');
 		$info = $db->one(array('order_id' => $order_id, 'status' => 1));
@@ -68,10 +68,11 @@ class Core
 	/**
 	 * 获取回调url
 	 */
-	protected function url($type)
+	protected function url($type, $account_id)
 	{
-		$project = Dever::project('pay');
-		return $project['url'] . 'daemon/notify/'.$type.'.php';
+		//$project = Dever::project('pay');
+		//return $project['url'] . 'daemon/notify/'.$type.'.php';
+		return Dever::url('api.notify?account_id=' . $account_id, 'pay');
 	}
 
 	/**

+ 12 - 7
lib/Wechat.php

@@ -9,7 +9,7 @@ class Wechat extends Core
 		$project = Dever::project('pay');
 		$this->config = new \WxPayConfig();
 		# 通知接口
-		$config['notify'] = $this->url($config['type']);
+		$config['notify'] = $this->url($config['type'], $config['id']);
 		# 证书
 		$config['ssl'] = array
 		(
@@ -164,21 +164,25 @@ class Callback extends \WxPayNotify
 	public function NotifyProcess($objData, $config, &$msg)
 	{
 		$data = $objData->GetValues();
-		$obj = Dever::load('pay/lib/wechat');
+		$obj = Dever::load('pay/lib/core');
 		$callback = function($msg = '') use ($obj, $data) {
 			if ($msg) {
 				$msg = $data['transaction_id'] . ':' . $msg;
 			}
 			$obj->updateOrder($data['out_trade_no'], $data['cash_fee'], $msg);
 		};
+
+		if(!array_key_exists("transaction_id", $data)){
+			$msg = '输入参数不正确';
+			$callback($msg);
+			return false;
+		}
+
 		# 参数校验
 		if(!array_key_exists("return_code", $data) 
 			||(array_key_exists("return_code", $data) && $data['return_code'] != "SUCCESS")) {
-			$msg = '异常';
-			return false;
-		}
-		if(!array_key_exists("transaction_id", $data)){
-			$msg = '输入参数不正确';
+			$msg = $data['return_code'] . '(异常)';
+			$callback($msg);
 			return false;
 		}
 
@@ -196,6 +200,7 @@ class Callback extends \WxPayNotify
 			return false;
 		}
 
+
 		# 查询订单,判断订单真实性
 		if(!$this->Queryorder($data["transaction_id"])){
 			$msg = '订单查询失败';

+ 15 - 0
src/Api.php

@@ -25,6 +25,21 @@ class Api
 		return $this->method->order($this->account_id, $this->uid, $this->username, $this->product_id, $this->name, $this->cash, $this->openid, $type);
 	}
 
+	/**
+	 * notify
+	 *
+	 * @return mixed
+	 */
+	public function notify($param = array())
+	{
+		$this->account_id = Dever::input('account_id', false);
+		if (!$this->account_id) {
+			Dever::alert('没有账户信息');
+		}
+		$this->pay();
+		return $this->method->notify();
+	}
+
 	/**
 	 * 发起支付 用于小程序支付
 	 *