You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.4 KiB

  1. <?php
  2. namespace App\Controller;
  3. use App\Constants\LogLabel;
  4. use App\Model\OrderMain;
  5. use EasyWeChat\Factory;
  6. use Hyperf\Guzzle\CoroutineHandler;
  7. class NotifyController extends BaseController
  8. {
  9. public function wxminiOnline()
  10. {
  11. $config = config('wxpay');
  12. $app = Factory::payment($config);
  13. $app['guzzle_handler'] = CoroutineHandler::class;
  14. // 通知回调,进行业务处理
  15. $response = $app->handlePaidNotify(function ($message, $fail) use ($app) {
  16. $this->log->event(
  17. LogLabel::PAY_NOTIFY_WXMINI,
  18. $message
  19. );
  20. // 查询订单
  21. $orderMain = OrderMain::query()
  22. ->where(['global_order_id' => $message['out_trade_no'], 'type' => OrderMain::ORDER_TYPE_ONLINE, 'state' => OrderMain::ORDER_STATE_UNPAY])
  23. ->where('time', '>=', date('Y-m-d H:i:s', (time()-900)))
  24. ->first();
  25. if (empty($orderMain)) {
  26. // 去查一下微信订单
  27. $wxOrder = $app->order->queryByOutTradeNumber($orderMain->global_order_id);
  28. $this->log->event(
  29. LogLabel::PAY_NOTIFY_WXMINI,
  30. $wxOrder
  31. );
  32. // return true;
  33. }
  34. });
  35. $response->send();
  36. }
  37. public function wxminiOffline()
  38. {
  39. $config = config('wxpay');
  40. $app = Factory::payment($config);
  41. $app['guzzle_handler'] = CoroutineHandler::class;
  42. // 通知回调,进行业务处理
  43. $response = $app->handlePaidNotify(function ($message, $fail) use ($app) {
  44. $this->log->event(
  45. LogLabel::PAY_NOTIFY_WXMINI,
  46. $message
  47. );
  48. // 查询订单
  49. $orderMain = OrderMain::query()
  50. ->where(['global_order_id' => $message['out_trade_no'], 'type' => OrderMain::ORDER_TYPE_OFFLINE, 'state' => OrderMain::ORDER_STATE_UNPAY])
  51. ->where('time', '>=', date('Y-m-d H:i:s', (time()-900)))
  52. ->first();
  53. if (empty($orderMain)) {
  54. // 去查一下微信订单
  55. $wxOrder = $app->order->queryByOutTradeNumber($orderMain->global_order_id);
  56. $this->log->event(
  57. LogLabel::PAY_NOTIFY_WXMINI,
  58. $wxOrder
  59. );
  60. // return true;
  61. }
  62. });
  63. $response->send();
  64. }
  65. }