Notify.php 4.8 KB

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