91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Pay;
|
||
|
||
use App\ServicePay\PayApiInterface;
|
||
use App\ServicePay\PayApiProvidesTrait;
|
||
use App\ServicePay\TransCard\BaseCard;
|
||
use App\ServicePay\TransCard\FeilvbinCard;
|
||
use App\ServicePay\TransCard\KshCard;
|
||
use Illuminate\Http\Request;
|
||
|
||
class PayController extends BaseController
|
||
{
|
||
use PayApiProvidesTrait;
|
||
|
||
/**
|
||
* @var PayApiInterface
|
||
*/
|
||
public $pay_service;
|
||
|
||
/**
|
||
* 同步回调
|
||
* @param $type 支付类型:支付宝,微信
|
||
* @param Request $request
|
||
*/
|
||
public function returnNotify($type, Request $request)
|
||
{
|
||
$this->setPayService($type);
|
||
return $this->pay_service->notify(1, $type, $request);
|
||
}
|
||
|
||
/**
|
||
* 异步回调
|
||
* @param $type支付类型:支付宝,微信
|
||
* @param Request $request
|
||
*/
|
||
public function notify($type, Request $request)
|
||
{
|
||
$this->setPayService($type);
|
||
return $this->pay_service->notify(0, $type, $request);
|
||
}
|
||
|
||
/**
|
||
* 银行卡支付异步回调
|
||
* @param Request $request
|
||
* @return string
|
||
*/
|
||
public function bankCardNotify(Request $request){
|
||
//'http://20.24.96.41:8080/newbankPay/appBack.do?mobile=' + mobile + '&token=' + appCode + '&from=' + address + '&content=' + body + '&datetime=' + date
|
||
$type = 'tr_bank2';
|
||
$this->setPayService($type);
|
||
$appid = $request->get('token');//这个和短信的模板有关
|
||
$card = $this->getCard($appid);
|
||
if (is_null($card)) {
|
||
return '渠道参数异常';
|
||
}
|
||
if (method_exists($this->pay_service, 'cardNotify')) {
|
||
return $this->pay_service->cardNotify(0, $type, $request, $card);
|
||
} else {
|
||
return '系统异常';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @return array
|
||
*/
|
||
private function cardConfig():array{
|
||
return [
|
||
1 => 'FeilvbinCard',
|
||
2 => 'KshCard',
|
||
3 => 'AiJICard',
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @param $app_id
|
||
* @return BaseCard|null
|
||
*/
|
||
private function getCard($app_id): ?BaseCard
|
||
{
|
||
$card = null;
|
||
$configArr = $this->cardConfig();
|
||
if (isset($configArr[$app_id])) {
|
||
$namespace = '\\App\\ServicePay\TransCard\\';
|
||
$clazz = $namespace . $configArr[$app_id];
|
||
$card = new $clazz();
|
||
}
|
||
return $card;
|
||
}
|
||
}
|