linkedcorp.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package addresslist
  2. import (
  3. "fmt"
  4. "github.com/silenceper/wechat/v2/util"
  5. )
  6. const (
  7. // getPermListURL 获取应用的可见范围
  8. getPermListURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/agent/get_perm_list?access_token=%s"
  9. // getLinkedCorpUserURL 获取互联企业成员详细信息
  10. getLinkedCorpUserURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/user/get?access_token=%s"
  11. // linkedCorpSimpleListURL 获取互联企业部门成员
  12. linkedCorpSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/user/simplelist?access_token=%s"
  13. // linkedCorpUserListURL 获取互联企业部门成员详情
  14. linkedCorpUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/user/list?access_token=%s"
  15. // linkedCorpDepartmentListURL 获取互联企业部门列表
  16. linkedCorpDepartmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/department/list?access_token=%s"
  17. )
  18. // GetPermListResponse 获取应用的可见范围响应
  19. type GetPermListResponse struct {
  20. util.CommonError
  21. UserIDs []string `json:"userids"`
  22. DepartmentIDs []string `json:"department_ids"`
  23. }
  24. // GetPermList 获取应用的可见范围
  25. // see https://developer.work.weixin.qq.com/document/path/93172
  26. func (r *Client) GetPermList() (*GetPermListResponse, error) {
  27. var (
  28. accessToken string
  29. err error
  30. )
  31. if accessToken, err = r.GetAccessToken(); err != nil {
  32. return nil, err
  33. }
  34. var response []byte
  35. if response, err = util.HTTPPost(fmt.Sprintf(getPermListURL, accessToken), ""); err != nil {
  36. return nil, err
  37. }
  38. result := &GetPermListResponse{}
  39. if err = util.DecodeWithError(response, result, "GetPermList"); err != nil {
  40. return nil, err
  41. }
  42. return result, nil
  43. }
  44. // GetLinkedCorpUserRequest 获取互联企业成员详细信息请求
  45. type GetLinkedCorpUserRequest struct {
  46. UserID string `json:"userid"`
  47. }
  48. // GetLinkedCorpUserResponse 获取互联企业成员详细信息响应
  49. type GetLinkedCorpUserResponse struct {
  50. util.CommonError
  51. UserInfo LinkedCorpUserInfo `json:"user_info"`
  52. }
  53. // LinkedCorpUserInfo 互联企业成员详细信息
  54. type LinkedCorpUserInfo struct {
  55. UserID string `json:"userid"`
  56. Name string `json:"name"`
  57. Department []string `json:"department"`
  58. Mobile string `json:"mobile"`
  59. Telephone string `json:"telephone"`
  60. Email string `json:"email"`
  61. Position string `json:"position"`
  62. CorpID string `json:"corpid"`
  63. Extattr Extattr `json:"extattr"`
  64. }
  65. // Extattr 互联企业成员详细信息扩展属性
  66. type Extattr struct {
  67. Attrs []ExtattrItem `json:"attrs"`
  68. }
  69. // ExtattrItem 互联企业成员详细信息扩展属性条目
  70. type ExtattrItem struct {
  71. Name string `json:"name"`
  72. Value string `json:"value,omitempty"`
  73. Type int `json:"type"`
  74. Text ExtattrItemText `json:"text,omitempty"`
  75. Web ExtattrItemWeb `json:"web,omitempty"`
  76. }
  77. // ExtattrItemText 互联企业成员详细信息自定义属性(文本)
  78. type ExtattrItemText struct {
  79. Value string `json:"value"`
  80. }
  81. // ExtattrItemWeb 互联企业成员详细信息自定义属性(网页)
  82. type ExtattrItemWeb struct {
  83. URL string `json:"url"`
  84. Title string `json:"title"`
  85. }
  86. // GetLinkedCorpUser 获取互联企业成员详细信息
  87. // see https://developer.work.weixin.qq.com/document/path/93171
  88. func (r *Client) GetLinkedCorpUser(req *GetLinkedCorpUserRequest) (*GetLinkedCorpUserResponse, error) {
  89. var (
  90. accessToken string
  91. err error
  92. )
  93. if accessToken, err = r.GetAccessToken(); err != nil {
  94. return nil, err
  95. }
  96. var response []byte
  97. if response, err = util.PostJSON(fmt.Sprintf(getLinkedCorpUserURL, accessToken), req); err != nil {
  98. return nil, err
  99. }
  100. result := &GetLinkedCorpUserResponse{}
  101. if err = util.DecodeWithError(response, result, "GetLinkedCorpUser"); err != nil {
  102. return nil, err
  103. }
  104. return result, nil
  105. }
  106. // LinkedCorpSimpleListRequest 获取互联企业部门成员请求
  107. type LinkedCorpSimpleListRequest struct {
  108. DepartmentID string `json:"department_id"`
  109. }
  110. // LinkedCorpSimpleListResponse 获取互联企业部门成员响应
  111. type LinkedCorpSimpleListResponse struct {
  112. util.CommonError
  113. Userlist []LinkedCorpUser `json:"userlist"`
  114. }
  115. // LinkedCorpUser 企业部门成员
  116. type LinkedCorpUser struct {
  117. UserID string `json:"userid"`
  118. Name string `json:"name"`
  119. Department []string `json:"department"`
  120. CorpID string `json:"corpid"`
  121. }
  122. // LinkedCorpSimpleList 获取互联企业部门成员
  123. // see https://developer.work.weixin.qq.com/document/path/93168
  124. func (r *Client) LinkedCorpSimpleList(req *LinkedCorpSimpleListRequest) (*LinkedCorpSimpleListResponse, error) {
  125. var (
  126. accessToken string
  127. err error
  128. )
  129. if accessToken, err = r.GetAccessToken(); err != nil {
  130. return nil, err
  131. }
  132. var response []byte
  133. if response, err = util.PostJSON(fmt.Sprintf(linkedCorpSimpleListURL, accessToken), req); err != nil {
  134. return nil, err
  135. }
  136. result := &LinkedCorpSimpleListResponse{}
  137. if err = util.DecodeWithError(response, result, "LinkedCorpSimpleList"); err != nil {
  138. return nil, err
  139. }
  140. return result, nil
  141. }
  142. // LinkedCorpUserListRequest 获取互联企业部门成员详情请求
  143. type LinkedCorpUserListRequest struct {
  144. DepartmentID string `json:"department_id"`
  145. }
  146. // LinkedCorpUserListResponse 获取互联企业部门成员详情响应
  147. type LinkedCorpUserListResponse struct {
  148. util.CommonError
  149. UserList []LinkedCorpUserInfo `json:"userlist"`
  150. }
  151. // LinkedCorpUserList 获取互联企业部门成员详情
  152. // see https://developer.work.weixin.qq.com/document/path/93169
  153. func (r *Client) LinkedCorpUserList(req *LinkedCorpUserListRequest) (*LinkedCorpUserListResponse, error) {
  154. var (
  155. accessToken string
  156. err error
  157. )
  158. if accessToken, err = r.GetAccessToken(); err != nil {
  159. return nil, err
  160. }
  161. var response []byte
  162. if response, err = util.PostJSON(fmt.Sprintf(linkedCorpUserListURL, accessToken), req); err != nil {
  163. return nil, err
  164. }
  165. result := &LinkedCorpUserListResponse{}
  166. if err = util.DecodeWithError(response, result, "LinkedCorpUserList"); err != nil {
  167. return nil, err
  168. }
  169. return result, nil
  170. }
  171. // LinkedCorpDepartmentListRequest 获取互联企业部门列表请求
  172. type LinkedCorpDepartmentListRequest struct {
  173. DepartmentID string `json:"department_id"`
  174. }
  175. // LinkedCorpDepartmentListResponse 获取互联企业部门列表响应
  176. type LinkedCorpDepartmentListResponse struct {
  177. util.CommonError
  178. DepartmentList []LinkedCorpDepartment `json:"department_list"`
  179. }
  180. // LinkedCorpDepartment 互联企业部门
  181. type LinkedCorpDepartment struct {
  182. DepartmentID string `json:"department_id"`
  183. DepartmentName string `json:"department_name"`
  184. ParentID string `json:"parentid"`
  185. Order int `json:"order"`
  186. }
  187. // LinkedCorpDepartmentList 获取互联企业部门列表
  188. // see https://developer.work.weixin.qq.com/document/path/93170
  189. func (r *Client) LinkedCorpDepartmentList(req *LinkedCorpDepartmentListRequest) (*LinkedCorpDepartmentListResponse, error) {
  190. var (
  191. accessToken string
  192. err error
  193. )
  194. if accessToken, err = r.GetAccessToken(); err != nil {
  195. return nil, err
  196. }
  197. var response []byte
  198. if response, err = util.PostJSON(fmt.Sprintf(linkedCorpDepartmentListURL, accessToken), req); err != nil {
  199. return nil, err
  200. }
  201. result := &LinkedCorpDepartmentListResponse{}
  202. if err = util.DecodeWithError(response, result, "LinkedCorpDepartmentList"); err != nil {
  203. return nil, err
  204. }
  205. return result, nil
  206. }