init($param); if ($this->order_id > 0) { $pay = Dever::db('pay/order')->one(array('order_id' => $this->order_id)); if ($pay && $pay['status'] == 1 && $pay['param']) { $order = Dever::array_decode($pay['param']); return $order; } } return $this->method->order($this->account_id, $this->project_id, $this->uid, $this->username, $this->product_id, $this->name, $this->cash, $this->openid, $type, $this->order_id); } /** * 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(); } /** * 发起支付 用于小程序支付 * * @return mixed */ public function applet($param = array()) { $this->init($param); return $this->method->applet($this->get(1)); } /** * 发起支付 用于app支付 * * @return mixed */ public function app($param = array()) { $this->init($param); $this->openid = -1; 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); } /** * 发起支付 用于页面支付 * * @return mixed */ public function page($param = array()) { $this->init($param); if (!$this->refer) { Dever::alert('没有回调refer'); } return $this->method->page($this->get(1), $this->refer); } /** * 发起支付 用于扫码支付 * * @return mixed */ public function qrcode($param = array()) { $this->init($param); $url = $this->method->qrcode($this->get(2), $this->refer); Dever::apply('sdk/qrcode'); return \QRcode::png($url); } /** * 初始化 设置参数 * * @return mixed */ private function init($param = array()) { if (isset($this->account_id)) { return; } $this->account_id = $this->getParam($param, 'account_id'); $this->project_id = $this->getParam($param, 'project_id'); $this->uid = $this->getParam($param, 'uid'); $this->username = $this->getParam($param, 'username'); $this->product_id = $this->getParam($param, 'product_id'); $this->name = $this->getParam($param, 'name'); $this->cash = $this->getParam($param, 'cash'); $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; } if (!$this->order_id) { $this->order_id = false; } if (!$this->account_id) { Dever::alert('没有账户信息'); } if (!$this->uid || !$this->username) { Dever::alert('没有用户信息'); } if (!$this->product_id) { Dever::alert('没有产品信息'); } if (!$this->name) { Dever::alert('没有支付信息'); } if (!$this->cash) { Dever::alert('没有支付金额'); } return $this->pay(); } /** * 初始化 * * @return mixed */ private function getParam($param, $key) { if (isset($param[$key])) { return $param[$key]; } return Dever::input($key, false); } /** * 获取支付类 * * @return mixed */ private function pay() { $pay = Dever::db('pay/account')->one($this->account_id); $method = '\\Pay\\Lib\\' . ucwords($pay['type']); $this->method = new $method($pay); return $this; } }