Notify.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\controller\mini;
  3. use app\extra\basic\Base;
  4. use app\model\saas\SaasGoods;
  5. use app\model\saas\SaasOrderLife;
  6. use LinFly\Annotation\Route\Controller;
  7. use LinFly\Annotation\Route\Route;
  8. use support\Request;
  9. use support\Response;
  10. #[Controller(prefix: "/notify")]
  11. class Notify extends Base
  12. {
  13. /**
  14. * 小程序webhook
  15. * @param Request $request
  16. * @return Response
  17. */
  18. #[Route(path: "hook",methods: "post")]
  19. public function webhook(Request $request): Response
  20. {
  21. try {
  22. $param = $request->post();
  23. if (empty($param['event'])) return error("参数错误");
  24. if (empty($param['content'])) return error("参数错误");
  25. $content = json_decode($param['content'], true);
  26. switch ($param['event']) {
  27. case "verify_token":
  28. return json(['challenge' => $content['challenge']]);
  29. break;
  30. default:
  31. break;
  32. }
  33. return json([]);
  34. } catch (\Throwable $e) {
  35. return error($e->getMessage());
  36. }
  37. }
  38. /**
  39. * 核销工具解决方案-spi
  40. * @param Request $request
  41. * @return Response
  42. */
  43. #[Route(path: "pay",methods: "post")]
  44. public function getPayStatue(Request $request): Response
  45. {
  46. try {
  47. $param = $request->post();
  48. echo getDateFull()."==支付结果回调==\n";
  49. print_r($param);
  50. return json([
  51. "err_no" => 0,
  52. "err_tips" => "success"
  53. ]);
  54. } catch (\Throwable $throwable) {
  55. return error($throwable->getMessage());
  56. }
  57. }
  58. /**
  59. * 核销工具解决方案-spi
  60. * @param Request $request
  61. * @return Response
  62. */
  63. #[Route(path: "mini",methods: "post")]
  64. public function getSpiData(Request $request): Response
  65. {
  66. try {
  67. $param = $request->post();
  68. echo getDateFull()."=={$param['type']}==\n";
  69. print_r($param);
  70. return json([
  71. "err_no" => 0,
  72. "err_tips" => "success"
  73. ]);
  74. } catch (\Throwable $throwable) {
  75. return error($throwable->getMessage());
  76. }
  77. }
  78. /**
  79. * 核销工具解决方案-扩展点-spi
  80. * @param Request $request
  81. * @return Response
  82. */
  83. #[Route(path: "expand",methods: "post")]
  84. public function getExpandData(Request $request): Response
  85. {
  86. try {
  87. $param = $request->post();
  88. switch ($param['type'])
  89. {
  90. case "pre_create_order": // 预下单回调
  91. $orderData = json_decode($param['msg']);
  92. $orderGoods = (new SaasGoods)->where("out_id",$orderData['goods'][0]['goods_id'])->findOrEmpty();
  93. if ($orderGoods->isEmpty()) return json([
  94. "err_no" => 0,
  95. "err_tips" => "success"
  96. ]);
  97. (new SaasOrderLife)->insertGetId([
  98. "open_id" => $orderData['open_id'],
  99. "agent_id" => $orderGoods['agent_id'],
  100. "store_id" => $orderGoods['agent_id'],
  101. "order_id" => $orderData['order_id'],
  102. "product_name" => $orderData['goods'][0]['title'],
  103. "product_img" => $orderData['goods'][0]['img_url'],
  104. "out_id" => $orderData['goods'][0]['goods_id'],
  105. "order_amount" => $orderData['goods'][0]['price'],
  106. "pay_amount" => $orderData['goods'][0]['price'],
  107. "count" => $orderData['goods'][0]['quantity'],
  108. "status" => 0
  109. ]);
  110. return json([
  111. "out_order_no" => $orderData['order_id'],
  112. "order_entry_schema" => [
  113. "path" => "page/order/detail",
  114. "params" => ['order' => $orderData['order_id']]
  115. ],
  116. "pay_notify_url" => "https://hx-mini-api.jsshuita.com.cn/notify/pay"
  117. ]);
  118. break;
  119. case "pre_create_refund": // 退款审核回调
  120. break;
  121. }
  122. echo getDateFull()."=={$param['type']}==\n";
  123. print_r($param);
  124. return json([
  125. "err_no" => 0,
  126. "err_tips" => "success"
  127. ]);
  128. } catch (\Throwable $throwable) {
  129. return error($throwable->getMessage());
  130. }
  131. }
  132. }