Semantic.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the overtrue/wechat.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. /**
  11. * Semantic.php.
  12. *
  13. * @author overtrue <i@overtrue.me>
  14. * @copyright 2015 overtrue <i@overtrue.me>
  15. *
  16. * @see https://github.com/overtrue
  17. * @see http://overtrue.me
  18. */
  19. namespace EasyWeChat\Semantic;
  20. use EasyWeChat\Core\AbstractAPI;
  21. /**
  22. * Class Semantic.
  23. */
  24. class Semantic extends AbstractAPI
  25. {
  26. const API_SEARCH = 'https://api.weixin.qq.com/semantic/semproxy/search';
  27. /**
  28. * Get the semantic content of giving string.
  29. *
  30. * @param string $keyword
  31. * @param array|string $categories
  32. * @param array $other
  33. *
  34. * @return array
  35. */
  36. public function query($keyword, $categories, array $other = [])
  37. {
  38. $params = [
  39. 'query' => $keyword,
  40. 'category' => implode(',', (array) $categories),
  41. 'appid' => $this->getAccessToken()->getAppId(),
  42. ];
  43. return $this->parseJSON('json', [self::API_SEARCH, array_merge($params, $other)]);
  44. }
  45. }