123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php namespace Pay\Src;
- use Dever;
- class Api
- {
- /**
- * 发起支付 下单 获取预支付信息
- *
- * @return mixed
- */
- public function get($type = 1, $param = array())
- {
- if (!$type) {
- $type = 1;
- }
- $this->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;
- }
- }
|