PayNotifyController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Models\PaymentLogModel;
  4. use App\Services\PayService;
  5. use Illuminate\Support\Facades\Log;
  6. use PHPUnit\Util\Exception;
  7. use Yansongda\Pay\Pay;
  8. class PayNotifyController extends Controller
  9. {
  10. /**
  11. * 微信支付回调
  12. */
  13. public function wx_notify(){
  14. $wxpay = Pay::wechat(PayService::wx_config());
  15. try{
  16. $data = $wxpay->verify();
  17. Log::info($data);
  18. $order_no = $data->out_trade_no;
  19. $this->order_do_sth($order_no);
  20. Log::debug('Wechat notify', $data->all());
  21. } catch (\Exception $e) {
  22. Log::info($e->getMessage());
  23. }
  24. return $wxpay->success();
  25. }
  26. /**
  27. * 支付宝支付回调
  28. */
  29. public function ali_notify(){
  30. $alipay = Pay::alipay(PayService::ali_config());
  31. try{
  32. $data = $alipay->verify();
  33. Log::info($data);
  34. $order_no = $data->out_trade_no;
  35. $this->order_do_sth($order_no);
  36. Log::debug('Wechat notify', $data->all());
  37. } catch (\Exception $e) {
  38. Log::info($e->getMessage());
  39. }
  40. return $alipay->success();
  41. }
  42. /**
  43. * 支付回调业务处理
  44. */
  45. public function order_do_sth($order_no){
  46. $order = PaymentLogModel::query()->where(['order_no'=>$order_no])->first();
  47. if(!$order){
  48. throw new Exception("订单不存在");
  49. }
  50. if($order['status']==1){
  51. return true;
  52. }
  53. }
  54. }