FeieyunController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace ghs\controllers;
  3. use common\components\feiePrintLogUtil;
  4. use common\components\feieyunCallbackUtil;
  5. use common\components\util;
  6. use Yii;
  7. /**
  8. * 飞鹅云打印回调
  9. */
  10. class FeieyunController extends BaseController
  11. {
  12. /** 飞鹅回调无需登录 */
  13. public $guestAccess = ['call-back'];
  14. /**
  15. * 飞鹅打印状态回调
  16. * POST application/x-www-form-urlencoded
  17. */
  18. public function actionCallBack()
  19. {
  20. $post = Yii::$app->request->post();
  21. if (empty($post)) {
  22. $raw = file_get_contents('php://input');
  23. if (!empty($raw)) {
  24. parse_str($raw, $post);
  25. }
  26. }
  27. Yii::info('飞鹅打印回调: ' . json_encode($post, JSON_UNESCAPED_UNICODE), __METHOD__);
  28. if (!feieyunCallbackUtil::verify($post)) {
  29. Yii::warning('飞鹅打印回调验签失败: ' . json_encode($post, JSON_UNESCAPED_UNICODE), __METHOD__);
  30. util::stop('飞鹅打印回调验签失败');
  31. }
  32. $feieOrderId = trim((string)($post['orderId'] ?? ''));
  33. $status = intval($post['status'] ?? 0);
  34. $stime = intval($post['stime'] ?? 0);
  35. if ($feieOrderId !== '') {
  36. feiePrintLogUtil::updateByCallback($feieOrderId, $stime, $status, $post);
  37. }
  38. // 飞鹅要求 5 秒内返回 SUCCESS
  39. util::stop('SUCCESS');
  40. }
  41. }