| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 | 
							- <?php namespace Pay\Lib;
 
- use Dever;
 
- Dever::apply('sdk/alipay', 'pay');
 
- class Alipay extends Core
 
- {
 
- 	private $signType = 'RSA2';
 
- 	public function __construct($config)
 
- 	{
 
- 		$project = Dever::project('pay');
 
- 		# 通知接口
 
- 		$config['notify'] = $this->url($config['type'], $config['id']);
 
- 		$this->config = $config;
 
- 	}
 
- 	/**
 
- 	 * 通知
 
- 	 */
 
- 	public function notify()
 
- 	{
 
- 		$type = Dever::input('type');
 
- 		if ($type == 1) {
 
- 			$input = $_GET;
 
- 			unset($input['account_id']);
 
- 			$result = $this->check($input);
 
- 			if ($result) {
 
- 				$status = 1;
 
- 			} else {
 
- 				$status = 2;
 
- 			}
 
- 			$refer = Dever::input('refer');
 
- 			$refer = urldecode($refer) . '&status=' . $status;
 
- 			Dever::location($refer);
 
- 		} else {
 
- 			$input = $_POST;
 
- 			if (!$input) {
 
- 				echo 'fail';die;
 
- 			}
 
- 			unset($input['account_id']);
 
- 			$this->log('支付回调-初始化', $input);
 
- 			$result = $this->check($input);
 
- 			if ($result) {
 
- 				$this->log('支付回调-获取数据', $result);
 
- 				if($input['trade_status'] == 'TRADE_FINISHED') {
 
- 					#退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
 
- 					$this->updateOrder($result['out_trade_no'], $result['total_amount'], '已超过退款期限');
 
- 				} elseif ($input['trade_status'] == 'TRADE_SUCCESS') {
 
- 					#付款完成后,支付宝系统发送该交易状态通知
 
- 					$this->updateOrder($result['out_trade_no'], $result['total_amount']);
 
- 				}
 
- 				
 
- 				echo 'success';die;
 
- 			} else {
 
- 				echo 'fail';die;
 
- 			}
 
- 		}
 
- 	}
 
- 	/**
 
- 	 * 获取统一下单的基本信息
 
- 	 */
 
- 	public function order($account_id, $project_id, $uid, $username, $product_id, $name, $cash, $openid = false, $type = 1, $order_id = false)
 
- 	{
 
- 		$order_id = $this->createOrder($uid, $username, $account_id, $project_id, $product_id, $name, $cash, $this->config['type'], $order_id);
 
- 		$aop = new \AopClient();
 
- 		$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
 
- 		if ($this->config['box'] == 2) {
 
- 			$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
 
- 		}
 
- 		
 
- 		$aop->appId = $this->config['appid'];
 
- 		$aop->rsaPrivateKey = $this->config['private_key'];
 
- 		$aop->alipayrsaPublicKey = $this->config['public_key'];
 
- 		$aop->signType = $this->signType;
 
- 		// 开启页面信息输出
 
- 		$aop->debugInfo = true;
 
- 		$request['out_trade_no'] = $order_id;
 
- 		$request['body'] = $name;
 
- 		$request['total_amount'] = $cash;
 
- 		$request['subject'] = $name;
 
- 		$request['timeout_express'] = $this->config['timeout'];
 
- 		$content = json_encode($request, JSON_UNESCAPED_UNICODE);
 
- 		$request = new \AlipayTradeWapPayRequest();
 
- 	
 
- 		$request->setNotifyUrl($this->config['notify']);
 
- 		$request->setReturnUrl($this->config['refer']);
 
- 		$request->setBizContent($content);
 
- 		if ($type == 1) {
 
- 			$result = $aop->pageExecute($request, 'post');
 
- 		} else {
 
- 			$result = $aop->Execute($request);
 
- 		}
 
- 		return $result;
 
- 	}
 
- 	/**
 
- 	 * 获取二维码支付
 
- 	 */
 
- 	public function qrcode($order, $refer)
 
- 	{
 
- 		$notify = new \NativePay();
 
- 		$result = $notify->GetPayUrl($order);
 
- 		$url = $result['code_url'];
 
- 		return $url;
 
- 	}
 
- 	/**
 
- 	 * 获取小程序支付
 
- 	 */
 
- 	public function applet($order)
 
- 	{
 
- 		$result = array();
 
- 		return $result;
 
- 	}
 
- 	/**
 
- 	 * 获取页面支付
 
- 	 */
 
- 	public function page($order, $refer)
 
- 	{
 
- 		return $order;
 
- 	}
 
- 	private function check($data)
 
- 	{
 
- 		$aop = new \AopClient();
 
- 		$aop->alipayrsaPublicKey = $this->config['public_key'];
 
- 		$result = $aop->rsaCheckV1($data, $this->config['public_key'], $this->signType);
 
- 		return $result;
 
- 	}
 
- }
 
 
  |