12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- use App\Services\DgPayService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- /**
- * 大观支付回调控制器
- */
- class DgPayController extends Controller
- {
- /**
- * @var DgPayService
- */
- protected DgPayService $payService;
- /**
- * 构造函数
- */
- public function __construct(DgPayService $payService)
- {
- $this->payService = $payService;
- }
- /**
- * 支付异步通知
- *
- * @param Request $request
- * @return \Illuminate\Http\Response
- */
- public function notify(Request $request)
- {
- // 记录通知数据
- $data = $request->all();
- Log::info('DgPay notify:', $data);
- // 验证签名
- if (!$this->payService->verifySign($data)) {
- Log::error('DgPay notify sign verify failed');
- return response('sign error');
- }
- // 处理支付结果
- try {
- // 支付成功
- if ($data['trade_status'] === 'SUCCESS') {
- // TODO: 在这里处理您的业务逻辑
- // 1. 验证订单金额是否正确
- // 2. 修改订单状态
- // 3. 发送通知等
- // 处理成功后返回成功标识
- return response('success');
- }
- // 其他状态直接返回成功
- return response('success');
- } catch (\Exception $e) {
- Log::error('DgPay notify process error: ' . $e->getMessage());
- return response('fail');
- }
- }
- /**
- * 支付同步跳转
- *
- * @param Request $request
- * @return \Illuminate\Http\Response
- */
- public function return(Request $request)
- {
- // 记录跳转数据
- $data = $request->all();
- Log::info('DgPay return:', $data);
- // 验证签名
- if (!$this->payService->verifySign($data)) {
- Log::error('DgPay return sign verify failed');
- return response('签名验证失败');
- }
- // TODO: 在这里处理跳转逻辑
- // 1. 可以跳转到订单详情页
- // 2. 可以跳转到支付成功页
- // 3. 可以根据业务需求自定义跳转
- return response()->json([
- 'message' => '支付成功'
- ]);
- }
- }
|