50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
||
namespace App\ServicePay;
|
||
class BasePay{
|
||
public $pay_gateway;//当前的支付通道实例
|
||
public $pay_config;//这个通道的支付配置信息
|
||
|
||
//第二部配置支付信息,payConfig
|
||
public function payConfig($type, $setConfig = [])
|
||
{
|
||
//number_format($pay_data['total_amount'], 2, '.', ''),
|
||
$config = [
|
||
'debug' => 1,//调试
|
||
'logDir' => to_linux_path(storage_path() . '/logs/'),
|
||
'mch_id' => $this->pay_gateway['app_id'], //客户交易者账号
|
||
'token' => $this->pay_gateway['app_key'],//密钥
|
||
'interface' => $this->pay_gateway['mch_id'],//账号名称 一般用来存放三方通道
|
||
'return_url' => action('Pay\PayController@returnNotify', ['type' => $type]),
|
||
'notify_url' => action('Pay\PayController@notify', ['type' => $type]),
|
||
];
|
||
$this->pay_config = $config;
|
||
}
|
||
|
||
/**
|
||
* 网关域名
|
||
* @return string
|
||
*/
|
||
protected function getGateUrl(): string
|
||
{
|
||
if (isset($this->pay_gateway['gateway_url']) && !empty(trim($this->pay_gateway['gateway_url']))) {
|
||
return rtrim(trim($this->pay_gateway['gateway_url']), '/');
|
||
}
|
||
return '';
|
||
}
|
||
|
||
protected function returnPayRes($re_type,$msg,$code,$url=''){
|
||
if ($code == 1) {
|
||
if ($re_type == 'json') {
|
||
return json_encode(['code' => 1, 'qrurl' => $url], 256);
|
||
} else {
|
||
return redirect()->away($url);
|
||
}
|
||
} else {
|
||
if ($re_type == 'json') {
|
||
return json_encode(['code' => 0, 'msg' => $msg], 256);
|
||
} else {
|
||
return $msg;
|
||
}
|
||
}
|
||
}
|
||
} |