Factory.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CatchAdmin [Just Like ~ ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
  8. // +----------------------------------------------------------------------
  9. // | Author: JaguarJack [ njphper@gmail.com ]
  10. // +----------------------------------------------------------------------
  11. namespace catchAdmin\wechat\library\messages;
  12. class Factory
  13. {
  14. /**
  15. * 对象生产
  16. *
  17. * @time 2020年06月26日
  18. * @param $message
  19. * @return mixed
  20. */
  21. public static function make($message)
  22. {
  23. return self::parse($message);
  24. }
  25. /**
  26. * 解析
  27. *
  28. * @time 2020年06月26日
  29. * @param $message
  30. * @return mixed
  31. */
  32. protected static function parse($message)
  33. {
  34. // 事件类型
  35. if ($message['MsgType'] == 'event') {
  36. $event = __NAMESPACE__ . '\\events\\' . ucfirst($message['Event']);
  37. return new $event($message);
  38. }
  39. $messageClass = __NAMESPACE__ . '\\' . ucfirst($message['MsgType']);
  40. return new $messageClass($message);
  41. }
  42. }