123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace app\common\service;
- use addons\epay\library\Service;
- use app\common\model\Orders;
- use app\common\model\Payment;
- use fast\Arr;
- use think\App;
- use think\Cache;
- class OrderPayService{
- /** @var Payment */
- protected $payment;
- /** @var string */
- protected $body;
- protected $expire=null;
- public static $methods=[
- Orders::PT_QYWY=>'companyBank',
- Orders::PT_WX=>'wechat',
- Orders::PT_ZFB=>'alipay',
- Orders::PT_YL=>'bankUnion',
- Orders::PT_DF=>'otherUser',
- Orders::PT_OFF=>'offline',
- ];
- /**
- * @param null $expire
- */
- public function setExpire($expire): void
- {
- $this->expire = $expire;
- }
- /**
- * @param Payment $payment
- */
- public function setPayment(Payment $payment): void
- {
- $this->payment = $payment;
- }
- /**
- * @param string $body
- */
- public function setBody(string $body): void
- {
- $this->body = $body;
- }
- /**
- * @return string
- */
- public function getBody(): string
- {
- return $this->body;
- }
- /**
- * @return mixed
- */
- public function getAmount($unit='y')
- {
- return moneyFormat($this->payment->amount,$unit);
- }
- public function companyBank(){}
- public function wechat(){
- $payData=Service::submitOrder(
- $this->getAmount('f'),
- $this->payment->order_no,
- 'wechat',
- $this->getBody(),
- $this->notifyUrl(),
- $this->returnUrl(),
- 'scan',
- '',
- $this->expire,
- );
- $str=$payData['code_url'];
- return [
- 'qr'=>makeQrcode($str),
- ];
- }
- public function notifyUrl(){
- return request()->root(true)."/index/payment/notify/order_no/".$this->payment->order_no;
- }
- public function returnUrl(){
- return h5_link('/user/order/success');
- }
- public function alipay(){
- $payData=Service::submitOrder(
- $this->getAmount(),
- $this->payment->order_no,
- 'alipay',
- $this->getBody(),
- $this->notifyUrl(),
- $this->returnUrl(),
- 'scan',
- '',
- $this->expire,
- );
- $str=$payData['qr_code'];
- return [
- 'qr'=>makeQrcode($str),
- ];
- }
- public function bankUnion(){
- require __DIR__.'/../library/upacp_demo_b2c/demo/api_01_gateway/Form_6_2_FrontConsume.php';
- $html=ylUnifyOrder($this->payment->order_no,$this->getAmount('f'),$this->expire,$this->notifyUrl(),$this->returnUrl());
- $cacheKey='payment_'.session_create_id();
- Cache::set($cacheKey,$html,60);
- return [
- 'url'=>sprintf('%s/%s?key=%s',request()->domain(),'redirect',$cacheKey),
- ];
- }
- public function otherUser(){}
- public function offline(){}
- public function pay(){
- $method=Arr::get(self::$methods,$this->payment->pay_type);
- return App::invokeMethod([$this,$method]);
- }
- }
|