| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- /**
- * 微信支付
- */
- namespace app\api\services;
- use utils\WxPay;
- /**
- * Class WxPayServices
- * @package app\services
- * @method $this data($data)
- * @method $this trade_type(string $trade_type)
- * @method $this uid(int $uid)
- */
- class WxPayServices extends BasePayServices
- {
- /**
- * 用户id
- * @var
- */
- protected $uid;
- /**
- * 数据体
- * @var
- */
- protected $data;
- protected static $instance = null;
- public static function instance ()
- {
- if (is_null(self::$instance)) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 微信统一下单
- * @return mixed
- */
- public function getUnifiedOrder ()
- {
- $uid = $this->uid;
- if (!$uid || !$this->data)
- return app('json')->json_error('下单失败');
- list($body, $total_amount, $order_type, $remarks, $trade_type, $pay_way) = $this->_payConf($uid, $this->data, 2);
- $out_trade_no = rand(1000000000, 9999999999) . (string)date('ymdhis', time()) . (int)microtime(true); // 订单号
- /** @var WxPay $pay */
- $pay = app()->make(WxPay::class);
- $rpm = $pay->unifiedOrder(compact('uid', 'body', 'out_trade_no', 'total_amount'));
- if (!$rpm['flag']) {
- return app('json')->json_error($rpm['msg']);
- }
- $this->setPaymentOrder(compact('body', 'out_trade_no', 'total_amount', 'remarks', 'uid', 'trade_type', 'order_type', 'pay_way'), 2);
- return app('json')->json_success('微信统一下单成功', $rpm['data']);
- }
- /**
- * 支付回调
- * @return $this
- */
- public function getNotifyInfo ()
- {
- $pay = new WxPay();
- if ($pay->checkSign($this->data)) {
- if ($this->data['trade_status'] == 'TRADE_SUCCESS') {
- $this->notify_info = $this->data;
- $this->pay_status = true;
- $this->pay_way = 2;
- }
- }
- return $this;
- }
- /**
- * 魔术方法
- * @param $name
- * @param $arguments
- * @return $this
- */
- public function __call ($name, $arguments)
- {
- // TODO: Implement __call() method.
- if ($name == 'data') {
- $this->{$name} = $arguments[0];
- } else {
- $this->{$name} = $arguments[0];
- }
- return $this;
- }
- }
|