Life.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\controller\notify;
  3. use app\extra\basic\Base;
  4. use app\extra\dyMini\PlanLive;
  5. use LinFly\Annotation\Attributes\Route\Controller;
  6. use LinFly\Annotation\Attributes\Route\GetMapping;
  7. use LinFly\Annotation\Attributes\Route\PostMapping;
  8. use support\Request;
  9. use support\Response;
  10. /**
  11. * 生活应用解决方案接入
  12. */
  13. #[Controller("/life")]
  14. class Life extends Base
  15. {
  16. #[GetMapping("test")]
  17. public function test2data(Request $request): Response
  18. {
  19. try {
  20. $param = $this->_valid([
  21. "order.require" => trans("empty.require"),
  22. ],$request->method());
  23. if (!is_array($param)) return error($param);
  24. $data = (new PlanLive)->config([
  25. "appid" => sConf("wechat.mini_appid"),
  26. "secret" => sConf("wechat.mini_secret"),
  27. ])->token()->planOrder($param['order']);
  28. return success('success',$data);
  29. } catch (\Throwable $throwable) {
  30. return error($throwable->getMessage());
  31. }
  32. }
  33. #[PostMapping("spi")]
  34. public function getLifeSpi(Request $request): Response
  35. {
  36. try {
  37. $param = $request->all();
  38. echo getDateFull()."===自研应用回调===\n";
  39. print_r($param);
  40. return error("ddd");
  41. } catch (\Throwable $throwable) {
  42. return error($throwable->getMessage());
  43. }
  44. }
  45. #[PostMapping("hook")]
  46. public function getLifeHook(Request $request): Response
  47. {
  48. try {
  49. $data = $request->all();
  50. echo getDateFull()."===自研应用回调WebHook===\n";
  51. print_r($data);
  52. if (isset($data['event']) && $data['event'] == "verify_webhook") {
  53. return json(['challenge' => $data['content']['challenge']]);
  54. }
  55. return error("ddd");
  56. } catch (\Throwable $throwable) {
  57. return error($throwable->getMessage());
  58. }
  59. }
  60. #[PostMapping("mini")]
  61. public function getMiniHook(Request $request): Response
  62. {
  63. try {
  64. $data = $request->all();
  65. echo getDateFull()."===小程序WebHook===\n";
  66. print_r($data);
  67. if (isset($data['event']) && $data['event'] == "verify_webhook") {
  68. return json(['challenge' => $data['content']['challenge']]);
  69. }
  70. return error("ddd");
  71. } catch (\Throwable $throwable) {
  72. return error($throwable->getMessage());
  73. }
  74. }
  75. }