You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

107 lines
2.5 KiB

  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. * Session.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\Staff;
  20. use EasyWeChat\Core\AbstractAPI;
  21. /**
  22. * Class Session.
  23. */
  24. class Session extends AbstractAPI
  25. {
  26. const API_CREATE = 'https://api.weixin.qq.com/customservice/kfsession/create';
  27. const API_CLOSE = 'https://api.weixin.qq.com/customservice/kfsession/close';
  28. const API_GET = 'https://api.weixin.qq.com/customservice/kfsession/getsession';
  29. const API_LISTS = 'https://api.weixin.qq.com/customservice/kfsession/getsessionlist';
  30. const API_WAITERS = 'https://api.weixin.qq.com/customservice/kfsession/getwaitcase';
  31. /**
  32. * List all sessions of $account.
  33. *
  34. * @param string $account
  35. *
  36. * @return \EasyWeChat\Support\Collection
  37. */
  38. public function lists($account)
  39. {
  40. return $this->parseJSON('get', [self::API_LISTS, ['kf_account' => $account]]);
  41. }
  42. /**
  43. * List all waiters of $account.
  44. *
  45. * @return \EasyWeChat\Support\Collection
  46. */
  47. public function waiters()
  48. {
  49. return $this->parseJSON('get', [self::API_WAITERS]);
  50. }
  51. /**
  52. * Create a session.
  53. *
  54. * @param string $account
  55. * @param string $openId
  56. *
  57. * @return \EasyWeChat\Support\Collection
  58. */
  59. public function create($account, $openId)
  60. {
  61. $params = [
  62. 'kf_account' => $account,
  63. 'openid' => $openId,
  64. ];
  65. return $this->parseJSON('json', [self::API_CREATE, $params]);
  66. }
  67. /**
  68. * Close a session.
  69. *
  70. * @param string $account
  71. * @param string $openId
  72. *
  73. * @return \EasyWeChat\Support\Collection
  74. */
  75. public function close($account, $openId)
  76. {
  77. $params = [
  78. 'kf_account' => $account,
  79. 'openid' => $openId,
  80. ];
  81. return $this->parseJSON('json', [self::API_CLOSE, $params]);
  82. }
  83. /**
  84. * Get a session.
  85. *
  86. * @param string $openId
  87. *
  88. * @return \EasyWeChat\Support\Collection
  89. */
  90. public function get($openId)
  91. {
  92. return $this->parseJSON('get', [self::API_GET, ['openid' => $openId]]);
  93. }
  94. }