sifangpay/app/Http/Controllers/Pay/PayController.php

76 lines
1.8 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\Http\Controllers\Pay;
use App\ServicePay\PayApiInterface;
use App\ServicePay\PayApiProvidesTrait;
use App\ServicePay\TransCard\BaseCard;
use App\ServicePay\TransCard\FeilvbinCard;
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){
$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 '系统异常';
}
}
private function getCard($app_id): ?BaseCard
{
$card = null;
switch ($app_id) {
case 1:
$card = new FeilvbinCard();
break;
default:
break;
}
return $card;
}
}