AppChat.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace WeWork\Api;
  3. use WeWork\Message\ResponseMessageInterface;
  4. use WeWork\Traits\HttpClientTrait;
  5. class AppChat
  6. {
  7. use HttpClientTrait;
  8. /**
  9. * 创建群聊会话
  10. *
  11. * @param array $json
  12. * @return array
  13. */
  14. public function create(array $json): array
  15. {
  16. return $this->httpClient->postJson('appchat/create', $json);
  17. }
  18. /**
  19. * 修改群聊会话
  20. *
  21. * @param array $json
  22. * @return array
  23. */
  24. public function update(array $json): array
  25. {
  26. return $this->httpClient->postJson('appchat/update', $json);
  27. }
  28. /**
  29. * 获取群聊会话
  30. *
  31. * @param string $id
  32. * @return array
  33. */
  34. public function get(string $id): array
  35. {
  36. return $this->httpClient->get('appchat/get', ['chatid' => $id]);
  37. }
  38. /**
  39. * 应用推送消息
  40. *
  41. * @param string $id
  42. * @param ResponseMessageInterface $responseMessage
  43. * @param bool $safe
  44. * @return array
  45. */
  46. public function send(string $id, ResponseMessageInterface $responseMessage, bool $safe = false): array
  47. {
  48. return $this->httpClient->postJson(
  49. 'appchat/send',
  50. array_merge(['chatid' => $id], $responseMessage->formatForResponse(), ['safe' => (int)$safe])
  51. );
  52. }
  53. }