mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-14 12:21:27 +08:00
* !6 develop->master 1.1.0 * 更新版本号 * 完善后台今日统计,增加权限白名单,增加后台首页菜单,调整后台登录页样式 * Merge branch 'koogua/I1XFCF' of https://gitee.com/koogua/course-tencen… * 前台学习资料部分完成 * !2 后台运营统计合并 * 后台学习资料部分完成 * Merge branch 'master' into develop * Merge branch 'master' of https://github.com/xiaochong0302/course-tencent-cloud * 1.增加changelog.md * 1.简化部分路由地址 * Merge pull request #2 from xiaochong0302/dependabot/composer/symfony/h… * Bump symfony/http-foundation from 4.3.4 to 5.1.6 * !7 纠正迁移文件和代码实际使用字段不一致 * 纠正迁移文件和时间代码中字段不一致 * 更新版本号 * 完善后台今日统计,增加权限白名单,增加后台首页菜单,调整后台登录页样式 * Merge branch 'koogua/I1XFCF' of https://gitee.com/koogua/course-tencen… * 前台学习资料部分完成 * !2 后台运营统计合并 * 后台学习资料部分完成 * Merge branch 'master' into develop * Merge branch 'master' of https://github.com/xiaochong0302/course-tencent-cloud * 1.增加changelog.md * 1.简化部分路由地址 * Merge pull request #2 from xiaochong0302/dependabot/composer/symfony/h… * Bump symfony/http-foundation from 4.3.4 to 5.1.6 * !9 修正插入数据不一致以及后台菜单参数类型报错 * 1.修正插入的管理帐号数据 * 纠正迁移文件和时间代码中字段不一致 * 更新版本号 * 完善后台今日统计,增加权限白名单,增加后台首页菜单,调整后台登录页样式 * Merge branch 'koogua/I1XFCF' of https://gitee.com/koogua/course-tencen… * 前台学习资料部分完成 * !2 后台运营统计合并 * 后台学习资料部分完成 * Merge branch 'master' into develop * Merge branch 'master' of https://github.com/xiaochong0302/course-tencent-cloud * 1.增加changelog.md * 1.简化部分路由地址 * Merge pull request #2 from xiaochong0302/dependabot/composer/symfony/h… * Bump symfony/http-foundation from 4.3.4 to 5.1.6 * !12 修正退款项目空白以及弹窗自适应 * 修复退款项目空白,以及弹窗高度自适应 * !13 修正退款项目空白以及弹窗自适应 * 修复退款项目空白,以及弹窗高度自适应 * !14 修正点击退款404 * 修复退款项目空白,以及弹窗高度自适应,取消退款内部错误 * 删除文件 LICENSE * add LICENSE. * update app/Http/Admin/Controllers/UploadController.php. 去除重复的signatureAction方法 * !19 v1.2.0阶段性合并 * 增加微信H5支付需要的Referer头信息 * 更新H5支付方式 * 更新H5支付方式 * 更新H5支付方式 * !23 修复添加课时后进入编辑页面500错误 * 修复添加课时后进入编辑页面500错误 * !24 修复添加课时后进入编辑页面500错误 * 修复添加课时后进入编辑页面500错误 * !33 开放登录阶段性合并 * Merge remote-tracking branch 'gitee/xiaochong0302/I280IZ' into xiaocho… * 初步完成开放登录,待线上测试7 * Merge branch 'demo' of gitee.com:koogua/course-tencent-cloud into xiao… * 初步完成开放登录,待线上测试6 * !30 开放登录线上测试5 * !29 开放登录线上测试5 * 初步完成开放登录,待线上测试5 * !28 开放登录线上测试4 * 初步完成开放登录,待线上测试4 * !27 开放登录线上测试3 * 初步完成开放登录,待线上测试3 * !26 开放登录线上测试2 * 初步完成开放登录,待线上测试2 * !25 开放登录线上测试 * 初步完成开放登录,待线上测试 * !22 验证更新h5支付 * Merge remote-tracking branch 'remotes/gitee/develop' into demo * !20 验证更新h5支付 * Merge branch 'develop' of https://gitee.com/koogua/course-tencent-clou… * !16 v1.2.0阶段性合并 * 删除调试断点代码 * 删除重复的signature方法 * Merge branch 'develop' of https://gitee.com/koogua/course-tencent-clou… * demo后台增加统计 * !5 更新版本号1.1.0 * !4 v1.1.0版本develop->demo * Merge branch 'develop' into demo * 1.增加changelog.md * Merge branch 'develop' into demo * Merge branch 'develop' into demo * Merge branch 'develop' into demo * !1 精简优化代码 * Merge branch 'develop' into demo * 合并修改 * !34 修复创建课时相关属性表数据未生成的问题 * 修复创建课时相关属性表数据未生成的问题 * !35 修复腾讯云回调数据结构改变导致的错误 * 修复腾讯云回调数据结构改变导致的错误,缩短vod_event计划任务时间 * !36 修复添加课程后进入列表500错误 * 修复未填充教师和分类的列表错误 * 优化第三方登录,修复注册密码加密问题 * !38 修复课程分类未过滤 * 过滤课程分类 * !39 修复课程分类未过滤 * 过滤课程分类 * !40 修复课程分类未过滤2 * 过滤课程分类 * 过滤课程分类 * !41 修复课程分类未过滤2 * 过滤课程分类 * 过滤课程分类 * 优化开发登录,计划任务执行路径,周期
325 lines
7.1 KiB
PHP
325 lines
7.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Pay;
|
|
|
|
use App\Models\Refund as RefundModel;
|
|
use App\Models\Trade as TradeModel;
|
|
use App\Repos\Trade as TradeRepo;
|
|
use App\Services\Pay as PayService;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Yansongda\Pay\Log;
|
|
use Yansongda\Supports\Collection;
|
|
|
|
class Alipay extends PayService
|
|
{
|
|
|
|
/**
|
|
* @var \Yansongda\Pay\Gateways\Alipay
|
|
*/
|
|
protected $gateway;
|
|
|
|
public function __construct($gateway = null)
|
|
{
|
|
$gateway = $gateway instanceof AlipayGateway ? $gateway : new AlipayGateway();
|
|
|
|
$this->gateway = $gateway->getInstance();
|
|
}
|
|
|
|
/**
|
|
* 扫码下单
|
|
*
|
|
* @param TradeModel $trade
|
|
* @return bool|string
|
|
*/
|
|
public function scan(TradeModel $trade)
|
|
{
|
|
try {
|
|
|
|
$response = $this->gateway->scan([
|
|
'out_trade_no' => $trade->sn,
|
|
'total_amount' => $trade->amount,
|
|
'subject' => $trade->subject,
|
|
]);
|
|
|
|
$result = $response->qr_code ?? false;
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error('Alipay Qrcode Exception', [
|
|
'code' => $e->getCode(),
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
$result = false;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* app支付
|
|
*
|
|
* @param TradeModel $trade
|
|
* @return Response|bool
|
|
*/
|
|
public function app(TradeModel $trade)
|
|
{
|
|
try {
|
|
|
|
$result = $this->gateway->app([
|
|
'out_trade_no' => $trade->sn,
|
|
'total_amount' => $trade->amount,
|
|
'subject' => $trade->subject,
|
|
]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error('Alipay app Exception', [
|
|
'code' => $e->getCode(),
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
$result = false;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* wap支付
|
|
*
|
|
* @param TradeModel $trade
|
|
* @return Response|bool
|
|
*/
|
|
public function wap(TradeModel $trade)
|
|
{
|
|
try {
|
|
|
|
$result = $this->gateway->wap([
|
|
'out_trade_no' => $trade->sn,
|
|
'total_amount' => $trade->amount,
|
|
'subject' => $trade->subject,
|
|
'http_method' => 'GET',
|
|
]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error('Alipay Wap Exception', [
|
|
'code' => $e->getCode(),
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
$result = false;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 小程序支付
|
|
*
|
|
* @param TradeModel $trade
|
|
* @param string $buyerId
|
|
* @return Collection|bool
|
|
*/
|
|
public function mini(TradeModel $trade, $buyerId)
|
|
{
|
|
try {
|
|
|
|
$result = $this->gateway->mini([
|
|
'out_trade_no' => $trade->sn,
|
|
'total_amount' => $trade->amount,
|
|
'subject' => $trade->subject,
|
|
'buyer_id' => $buyerId,
|
|
]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error('Alipay Mini Exception', [
|
|
'code' => $e->getCode(),
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
$result = false;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 异步通知
|
|
*
|
|
* @return Response|bool
|
|
*/
|
|
public function notify()
|
|
{
|
|
try {
|
|
|
|
$data = $this->gateway->verify();
|
|
|
|
Log::debug('Alipay Verify Data', $data->all());
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error('Alipay Verify Exception', [
|
|
'code' => $e->getCode(),
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
return false;
|
|
}
|
|
|
|
if ($data->trade_status != 'TRADE_SUCCESS') {
|
|
return false;
|
|
}
|
|
|
|
$tradeRepo = new TradeRepo();
|
|
|
|
$trade = $tradeRepo->findBySn($data->out_trade_no);
|
|
|
|
if (!$trade) return false;
|
|
|
|
if ($data->total_amount != $trade->amount) {
|
|
return false;
|
|
}
|
|
|
|
if ($trade->status == TradeModel::STATUS_FINISHED) {
|
|
return $this->gateway->success();
|
|
}
|
|
|
|
if ($trade->status != TradeModel::STATUS_PENDING) {
|
|
return false;
|
|
}
|
|
|
|
$trade->channel_sn = $data->trade_no;
|
|
|
|
$this->eventsManager->fire('pay:afterPay', $this, $trade);
|
|
|
|
$trade = $tradeRepo->findById($trade->id);
|
|
|
|
if ($trade->status == TradeModel::STATUS_FINISHED) {
|
|
return $this->gateway->success();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 查询交易(扫码生成订单后可执行)
|
|
*
|
|
* @param string $outTradeNo
|
|
* @param string $type
|
|
* @return Collection|bool
|
|
*/
|
|
public function find($outTradeNo, $type = 'wap')
|
|
{
|
|
try {
|
|
|
|
$order = ['out_trade_no' => $outTradeNo];
|
|
|
|
$result = $this->gateway->find($order, $type);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error('Alipay Find Order Exception', [
|
|
'code' => $e->getCode(),
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
$result = false;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 关闭交易(扫码生成订单后可执行)
|
|
*
|
|
* @param string $outTradeNo
|
|
* @return bool
|
|
*/
|
|
public function close($outTradeNo)
|
|
{
|
|
try {
|
|
|
|
$response = $this->gateway->close(['out_trade_no' => $outTradeNo]);
|
|
|
|
$result = $response->code == '10000';
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error('Alipay Close Order Exception', [
|
|
'code' => $e->getCode(),
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
$result = false;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 撤销交易(未生成订单也可执行)
|
|
*
|
|
* @param string $outTradeNo
|
|
* @return bool
|
|
*/
|
|
public function cancel($outTradeNo)
|
|
{
|
|
try {
|
|
|
|
$response = $this->gateway->cancel(['out_trade_no' => $outTradeNo]);
|
|
|
|
$result = $response->code == '10000';
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error('Alipay Cancel Order Exception', [
|
|
'code' => $e->getCode(),
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
$result = false;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 申请退款
|
|
*
|
|
* @param RefundModel $refund
|
|
* @return bool
|
|
*/
|
|
public function refund(RefundModel $refund)
|
|
{
|
|
try {
|
|
|
|
$tradeRepo = new TradeRepo();
|
|
|
|
$trade = $tradeRepo->findById($refund->trade_id);
|
|
|
|
$response = $this->gateway->refund([
|
|
'out_trade_no' => $trade->sn,
|
|
'out_request_no' => $refund->sn,
|
|
'refund_amount' => $refund->amount,
|
|
]);
|
|
|
|
$result = $response->code == '10000';
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error('Alipay Refund Order Exception', [
|
|
'code' => $e->getCode(),
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
$result = false;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
}
|