94 lines
2.4 KiB
PHP
Executable File
94 lines
2.4 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm
|
|
* User: wild
|
|
* Date: 2021/4/13
|
|
* Time: 1:11 下午
|
|
*/
|
|
|
|
|
|
namespace App\Supports\Pay;
|
|
|
|
use App\Enums\PayType;
|
|
use App\Supports\Facades\Alipay;
|
|
|
|
class Pay
|
|
{
|
|
protected $payType;
|
|
|
|
public function __construct($payType)
|
|
{
|
|
if ($payType != PayType::ALIPAY) {
|
|
throw new \Exception('不支持该支付类型。');
|
|
}
|
|
$this->payType = $payType;
|
|
}
|
|
|
|
public static function create($payType)
|
|
{
|
|
return new Pay($payType);
|
|
}
|
|
|
|
/**
|
|
* 发起支付
|
|
* @param $orderNo
|
|
* @param $money
|
|
* @param string $subject
|
|
* @return string|void
|
|
* @throws \Exception
|
|
*/
|
|
public function pay($orderNo, $money, $subject)
|
|
{
|
|
switch ($this->payType) {
|
|
// case EPayType::WECHAT:{
|
|
// return PayWechat::payCodeUrl($orderNo, $money, $description, $returnUrl);
|
|
// }
|
|
case PayType::ALIPAY:
|
|
{
|
|
return Alipay::pay($orderNo, $money, $subject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function tradeQuery($rechargeSn)
|
|
{
|
|
switch ($this->payType) {
|
|
// case EPayType::WECHAT:{
|
|
// return PayWechat::payCodeUrl($orderNo, $money, $description, $returnUrl);
|
|
// }
|
|
case PayType::ALIPAY:
|
|
{
|
|
return Alipay::tradeQuery($rechargeSn);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 交易信息的状态
|
|
* @param $tradeInfo tradeQuery的结果
|
|
* @return bool
|
|
*/
|
|
public function tradeSuccessed($tradeInfo) {
|
|
return $tradeInfo['trade_status'] == 'TRADE_SUCCESS';
|
|
}
|
|
|
|
public function tradeUnSuccessMessage($tradeInfo)
|
|
{
|
|
switch ($this->payType) {
|
|
// case EPayType::WECHAT:{
|
|
// return PayWechat::payCodeUrl($orderNo, $money, $description, $returnUrl);
|
|
// }
|
|
case PayType::ALIPAY:
|
|
{
|
|
// https://opendocs.alipay.com/open/02ivbt?scene=common&ref=api
|
|
switch ($tradeInfo['trade_status']) {
|
|
case 'WAIT_BUYER_PAY': return '交易创建,等待买家付款';
|
|
case 'TRADE_CLOSED': return '交易已关闭';
|
|
case 'TRADE_FINISHED': return '交易结束';
|
|
}
|
|
return '未知错误:'.$tradeInfo['trade_status'];
|
|
}
|
|
}
|
|
}
|
|
}
|