User.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace WeWork\Api;
  3. use WeWork\Traits\HttpClientTrait;
  4. class User
  5. {
  6. use HttpClientTrait;
  7. /**
  8. * 创建成员
  9. *
  10. * @param array $json
  11. * @return array
  12. */
  13. public function create(array $json): array
  14. {
  15. return $this->httpClient->postJson('user/create', $json);
  16. }
  17. /**
  18. * 读取成员
  19. *
  20. * @param string $id
  21. * @return array
  22. */
  23. public function get(string $id): array
  24. {
  25. return $this->httpClient->get('user/get', ['userid' => $id]);
  26. }
  27. /**
  28. * 更新成员
  29. *
  30. * @param array $json
  31. * @return array
  32. */
  33. public function update(array $json): array
  34. {
  35. return $this->httpClient->postJson('user/update', $json);
  36. }
  37. /**
  38. * 删除成员
  39. *
  40. * @param string $id
  41. * @return array
  42. */
  43. public function delete(string $id): array
  44. {
  45. return $this->httpClient->get('user/delete', ['userid' => $id]);
  46. }
  47. /**
  48. * 批量删除成员
  49. *
  50. * @param array $idList
  51. * @return array
  52. */
  53. public function batchDelete(array $idList): array
  54. {
  55. return $this->httpClient->postJson('user/batchdelete', ['useridlist' => $idList]);
  56. }
  57. /**
  58. * 获取部门成员
  59. *
  60. * @param int $departmentId
  61. * @param bool $fetchChild
  62. * @param bool $needDetail
  63. * @return array
  64. */
  65. public function list(int $departmentId, bool $fetchChild = false, bool $needDetail = false): array
  66. {
  67. $uri = 'user/' . ($needDetail ? 'list' : 'simplelist');
  68. return $this->httpClient->get($uri, ['department_id' => $departmentId, 'fetch_child' => (int)$fetchChild]);
  69. }
  70. /**
  71. * userid转openid
  72. *
  73. * @param string $id
  74. * @return array
  75. */
  76. public function convertIdToOpenid(string $id): array
  77. {
  78. return $this->httpClient->postJson('user/convert_to_openid', ['userid' => $id]);
  79. }
  80. /**
  81. * openid转userid
  82. *
  83. * @param string $openid
  84. * @return array
  85. */
  86. public function convertOpenidToUserId(string $openid): array
  87. {
  88. return $this->httpClient->postJson('user/convert_to_userid', compact('openid'));
  89. }
  90. /**
  91. * 二次验证
  92. *
  93. * @param string $id
  94. * @return array
  95. */
  96. public function authSuccess(string $id): array
  97. {
  98. return $this->httpClient->get('user/authsucc', ['userid' => $id]);
  99. }
  100. /**
  101. * 根据code获取成员信息
  102. *
  103. * @param string $code
  104. * @return array
  105. */
  106. public function getInfo(string $code): array
  107. {
  108. return $this->httpClient->get('user/getuserinfo', compact('code'));
  109. }
  110. /**
  111. * 使用user_ticket获取成员详情
  112. *
  113. * @param string $ticket
  114. * @return array
  115. */
  116. public function getDetail(string $ticket): array
  117. {
  118. return $this->httpClient->postJson('user/getuserdetail', ['user_ticket' => $ticket]);
  119. }
  120. }