Life.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\controller\notify;
  3. use app\extra\basic\Base;
  4. use app\extra\dyMini\PlanLive;
  5. use app\model\saas\SaasGoods;
  6. use LinFly\Annotation\Attributes\Route\Controller;
  7. use LinFly\Annotation\Attributes\Route\GetMapping;
  8. use LinFly\Annotation\Attributes\Route\PostMapping;
  9. use support\Request;
  10. use support\Response;
  11. use Webman\RedisQueue\Redis;
  12. /**
  13. * 生活应用解决方案接入
  14. */
  15. #[Controller("/life")]
  16. class Life extends Base
  17. {
  18. #[GetMapping("test")]
  19. public function test2data(Request $request): Response
  20. {
  21. try {
  22. // $param = $this->_valid([
  23. // "order.require" => trans("empty.require"),
  24. // ],$request->method());
  25. // if (!is_array($param)) return error($param);
  26. // Redis::send("order-done",['order' => $param['order']]);
  27. // return success('ok');
  28. $data = (new PlanLive)->config([
  29. "appid" => sConf("wechat.mini_appid"),
  30. "secret" => sConf("wechat.mini_secret"),
  31. ])->token()->getPlan2Goods([7663786142546708530]);
  32. return success('success',$data);
  33. } catch (\Throwable $throwable) {
  34. return error($throwable->getMessage());
  35. }
  36. }
  37. #[PostMapping("spi")]
  38. public function getLifeSpi(Request $request): Response
  39. {
  40. try {
  41. $param = $request->all();
  42. // echo getDateFull()."===自研应用回调===\n";
  43. // print_r($param);
  44. return error("ddd");
  45. } catch (\Throwable $throwable) {
  46. return error($throwable->getMessage());
  47. }
  48. }
  49. #[PostMapping("hook")]
  50. public function getLifeHook(Request $request): Response
  51. {
  52. try {
  53. $data = $request->all();
  54. // echo getDateFull()."===自研应用回调WebHook===\n";
  55. // print_r($data);
  56. if (isset($data['event']) && $data['event'] == "verify_webhook") {
  57. return json(['challenge' => $data['content']['challenge']]);
  58. }
  59. $content = json_decode($data['content'],true);
  60. switch ($data['event']) {
  61. case "life_product_status_change": // 商品状态变化
  62. if (in_array($content['status'],['GOODS_OFFLINE','GOODS_BAN','GOODS_DELETE'])) { // 商品下架
  63. (new SaasGoods)->where("goods_id",$content['product_id'])->update(['status' => 3]);
  64. }
  65. break;
  66. default:
  67. break;
  68. }
  69. return error("ddd");
  70. } catch (\Throwable $throwable) {
  71. return error($throwable->getMessage());
  72. }
  73. }
  74. #[PostMapping("mini")]
  75. public function getMiniHook(Request $request): Response
  76. {
  77. try {
  78. $data = $request->all();
  79. // echo getDateFull()."===小程序WebHook===\n";
  80. // print_r($data);
  81. if (isset($data['event']) && $data['event'] == "verify_webhook") {
  82. return json(['challenge' => $data['content']['challenge']]);
  83. }
  84. return error("ddd");
  85. } catch (\Throwable $throwable) {
  86. return error($throwable->getMessage());
  87. }
  88. }
  89. }