sifangpay/app/ServicePay/BasePay.php

69 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}
}
protected function checkWhiteIP($gate_way){
$ip = request()->getClientIp();
if (isset($gate_way['whiteip'])) {
$whiteip = $gate_way['whiteip'];
if(empty($whiteip)){
return true;
}
$ipArr = explode(',', $whiteip);
$this->debugLog('回调IP', [$ip, $whiteip]);
if (is_array($ipArr)) {
if (!in_array($ip, $ipArr)) {
return false;
}
}
}
return true;
}
}