CodePay.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Controllers\Gateway;
  3. use Auth;
  4. use Illuminate\Http\JsonResponse;
  5. use Log;
  6. use Response;
  7. class CodePay extends AbstractPayment
  8. {
  9. public function purchase($request): JsonResponse
  10. {
  11. $payment = $this->creatNewPayment(Auth::id(), $request->input('id'), $request->input('amount'));
  12. $data = [
  13. 'id' => sysConfig('codepay_id'),
  14. 'pay_id' => $payment->trade_no,
  15. 'type' => $request->input('type'), //1支付宝支付 2QQ钱包 3微信支付
  16. 'price' => $payment->amount,
  17. 'page' => 1,
  18. 'outTime' => 900,
  19. 'notify_url' => route('payment.notify', ['method' => 'codepay']),
  20. 'return_url' => route('invoice'),
  21. ];
  22. $data['sign'] = $this->aliStyleSign($data, sysConfig('codepay_key'));
  23. $url = sysConfig('codepay_url').http_build_query($data);
  24. $payment->update(['url' => $url]);
  25. return Response::json(['status' => 'success', 'url' => $url, 'message' => '创建订单成功!']);
  26. }
  27. public function notify($request): void
  28. {
  29. $tradeNo = $request->input('pay_id');
  30. if ($tradeNo && $request->input('pay_no')
  31. && $this->verify($request->except('method'), sysConfig('codepay_key'), $request->input('sign'), false)) {
  32. if ($this->paymentReceived($tradeNo)) {
  33. exit('success');
  34. }
  35. } else {
  36. Log::info('码支付:交易失败');
  37. }
  38. exit('fail');
  39. }
  40. }