151 lines
3.4 KiB
PHP
151 lines
3.4 KiB
PHP
<?php
|
||
|
||
namespace App\ServicePay;
|
||
|
||
use App\Models\Merchant;
|
||
use App\Models\Order;
|
||
use Illuminate\Support\Facades\Log;
|
||
use Yansongda\Pay\Pay;
|
||
use Yansongda\Pay\Gateways\Wechat\Support;
|
||
use Illuminate\Support\Collection;
|
||
use Illuminate\Http\Request;
|
||
use Ixudra\Curl\Facades\Curl;
|
||
|
||
class GuMaPayServices implements PayApiInterface
|
||
{
|
||
|
||
use PayTrait;
|
||
public $gateway_list;//当前类型的支付通道列表
|
||
public $pay_type;//支付类型
|
||
public $pay_method;//支付方法
|
||
public $pay_gateway;//当前的支付通道实例
|
||
public $pay_config;//这个通道的支付配置信息
|
||
public $pay_model;//支付接口实例模型
|
||
public $order;
|
||
public $request;
|
||
public $gateway_id;
|
||
public $pay_data;
|
||
public $log_name;
|
||
public static $result;
|
||
public $timeOut=15;
|
||
|
||
//支付第一步:getGateway
|
||
//第二payConfig
|
||
//3:pay
|
||
|
||
/**
|
||
* 检查通道是否存在错误
|
||
*/
|
||
public function checkGatewayConfig()
|
||
{
|
||
$pay_method = $this->pay_method;
|
||
if (count($this->gateway_list) <= 0) {
|
||
self::addError(['msg' => '通道支付不存在']);
|
||
}
|
||
if (!isset($this->gateway_list[$pay_method])) {
|
||
self::addError(['msg' => '通道支付类型不存在']);
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 支付包配置实列化
|
||
* @param $type
|
||
* @param array $setConfig
|
||
* @return $this
|
||
*/
|
||
public function payConfig($type, $setConfig = [])
|
||
{
|
||
|
||
$this->pay_config = [
|
||
'username'=>$this->gateway['username'],
|
||
'source'=>$this->gateway['source'],
|
||
'url'=>$this->gateway['url'],
|
||
'thumb'=>$this->gateway['thumb'],
|
||
'mch_id'=>$this->gateway['mch_id']
|
||
];
|
||
$this->pay_model=$this->pay_config;
|
||
return $this;
|
||
}
|
||
|
||
//回调指定通道配置信息gateway
|
||
public function getConfig($gateway_id, $pay_method)
|
||
{
|
||
$this->pay_method = $pay_method;
|
||
return $this->pay_model = config('gateway.config')[$gateway_id];
|
||
}
|
||
|
||
public function getPayConfig()
|
||
{
|
||
return $this->pay_config;
|
||
}
|
||
|
||
|
||
public function pay($pay_data)
|
||
{
|
||
|
||
//订单开始时间,倒计时
|
||
$time_only = ((strtotime($this->order->created_at) + $this->timeOut * 60) - time());
|
||
|
||
|
||
$config=config('adconfig.pay_type');
|
||
|
||
$data = [
|
||
'gateway'=>$this->pay_gateway,
|
||
'title' => $config[$this->order->pay_type],
|
||
'pay_name' => $config[$this->order->pay_type],
|
||
'bank' => $this->pay_gateway,
|
||
'order' => $this->order,
|
||
'pay_type' => $this->order->pay_type,
|
||
'is_mobile' => is_mobile_client(),
|
||
'pay_status' => $this->order->pay_status == 1 ? '已支付' : '等待支付',
|
||
'only_time' =>$time_only
|
||
];
|
||
|
||
|
||
|
||
return view('web.order.code', $data);
|
||
|
||
|
||
}
|
||
|
||
/*
|
||
* 验证签名
|
||
*/
|
||
public function verify()
|
||
{
|
||
|
||
return $this->pay_model->verify();
|
||
|
||
}
|
||
|
||
|
||
|
||
public function setLogName($pay_type)
|
||
{
|
||
$name = '';
|
||
switch ($pay_type) {
|
||
case 'alipay':
|
||
$name = 'alipay_';
|
||
break;
|
||
case 'weixin':
|
||
$name = 'weixin_';
|
||
break;
|
||
|
||
}
|
||
$this->log_name = $name;
|
||
}
|
||
|
||
public function notify($return = 1, $pay_type, $request)
|
||
{
|
||
|
||
|
||
}
|
||
|
||
public function success()
|
||
{
|
||
// TODO: Implement success() method.
|
||
}
|
||
|
||
|
||
} |