linkedcorp.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. err = util.DecodeWithError(response, result, "GetPermList")
  40. return result, err
  41. }
  42. // GetLinkedCorpUserRequest 获取互联企业成员详细信息请求
  43. type GetLinkedCorpUserRequest struct {
  44. UserID string `json:"userid"`
  45. }
  46. // GetLinkedCorpUserResponse 获取互联企业成员详细信息响应
  47. type GetLinkedCorpUserResponse struct {
  48. util.CommonError
  49. UserInfo LinkedCorpUserInfo `json:"user_info"`
  50. }
  51. // LinkedCorpUserInfo 互联企业成员详细信息
  52. type LinkedCorpUserInfo struct {
  53. UserID string `json:"userid"`
  54. Name string `json:"name"`
  55. Department []string `json:"department"`
  56. Mobile string `json:"mobile"`
  57. Telephone string `json:"telephone"`
  58. Email string `json:"email"`
  59. Position string `json:"position"`
  60. CorpID string `json:"corpid"`
  61. Extattr Extattr `json:"extattr"`
  62. }
  63. // Extattr 互联企业成员详细信息扩展属性
  64. type Extattr struct {
  65. Attrs []ExtattrItem `json:"attrs"`
  66. }
  67. // ExtattrItem 互联企业成员详细信息扩展属性条目
  68. type ExtattrItem struct {
  69. Name string `json:"name"`
  70. Value string `json:"value,omitempty"`
  71. Type int `json:"type"`
  72. Text ExtattrItemText `json:"text,omitempty"`
  73. Web ExtattrItemWeb `json:"web,omitempty"`
  74. }
  75. // ExtattrItemText 互联企业成员详细信息自定义属性(文本)
  76. type ExtattrItemText struct {
  77. Value string `json:"value"`
  78. }
  79. // ExtattrItemWeb 互联企业成员详细信息自定义属性(网页)
  80. type ExtattrItemWeb struct {
  81. URL string `json:"url"`
  82. Title string `json:"title"`
  83. }
  84. // GetLinkedCorpUser 获取互联企业成员详细信息
  85. // see https://developer.work.weixin.qq.com/document/path/93171
  86. func (r *Client) GetLinkedCorpUser(req *GetLinkedCorpUserRequest) (*GetLinkedCorpUserResponse, error) {
  87. var (
  88. accessToken string
  89. err error
  90. )
  91. if accessToken, err = r.GetAccessToken(); err != nil {
  92. return nil, err
  93. }
  94. var response []byte
  95. if response, err = util.PostJSON(fmt.Sprintf(getLinkedCorpUserURL, accessToken), req); err != nil {
  96. return nil, err
  97. }
  98. result := &GetLinkedCorpUserResponse{}
  99. err = util.DecodeWithError(response, result, "GetLinkedCorpUser")
  100. return result, err
  101. }
  102. // LinkedCorpSimpleListRequest 获取互联企业部门成员请求
  103. type LinkedCorpSimpleListRequest struct {
  104. DepartmentID string `json:"department_id"`
  105. }
  106. // LinkedCorpSimpleListResponse 获取互联企业部门成员响应
  107. type LinkedCorpSimpleListResponse struct {
  108. util.CommonError
  109. Userlist []LinkedCorpUser `json:"userlist"`
  110. }
  111. // LinkedCorpUser 企业部门成员
  112. type LinkedCorpUser struct {
  113. UserID string `json:"userid"`
  114. Name string `json:"name"`
  115. Department []string `json:"department"`
  116. CorpID string `json:"corpid"`
  117. }
  118. // LinkedCorpSimpleList 获取互联企业部门成员
  119. // see https://developer.work.weixin.qq.com/document/path/93168
  120. func (r *Client) LinkedCorpSimpleList(req *LinkedCorpSimpleListRequest) (*LinkedCorpSimpleListResponse, error) {
  121. var (
  122. accessToken string
  123. err error
  124. )
  125. if accessToken, err = r.GetAccessToken(); err != nil {
  126. return nil, err
  127. }
  128. var response []byte
  129. if response, err = util.PostJSON(fmt.Sprintf(linkedCorpSimpleListURL, accessToken), req); err != nil {
  130. return nil, err
  131. }
  132. result := &LinkedCorpSimpleListResponse{}
  133. err = util.DecodeWithError(response, result, "LinkedCorpSimpleList")
  134. return result, err
  135. }
  136. // LinkedCorpUserListRequest 获取互联企业部门成员详情请求
  137. type LinkedCorpUserListRequest struct {
  138. DepartmentID string `json:"department_id"`
  139. }
  140. // LinkedCorpUserListResponse 获取互联企业部门成员详情响应
  141. type LinkedCorpUserListResponse struct {
  142. util.CommonError
  143. UserList []LinkedCorpUserInfo `json:"userlist"`
  144. }
  145. // LinkedCorpUserList 获取互联企业部门成员详情
  146. // see https://developer.work.weixin.qq.com/document/path/93169
  147. func (r *Client) LinkedCorpUserList(req *LinkedCorpUserListRequest) (*LinkedCorpUserListResponse, error) {
  148. var (
  149. accessToken string
  150. err error
  151. )
  152. if accessToken, err = r.GetAccessToken(); err != nil {
  153. return nil, err
  154. }
  155. var response []byte
  156. if response, err = util.PostJSON(fmt.Sprintf(linkedCorpUserListURL, accessToken), req); err != nil {
  157. return nil, err
  158. }
  159. result := &LinkedCorpUserListResponse{}
  160. err = util.DecodeWithError(response, result, "LinkedCorpUserList")
  161. return result, err
  162. }
  163. // LinkedCorpDepartmentListRequest 获取互联企业部门列表请求
  164. type LinkedCorpDepartmentListRequest struct {
  165. DepartmentID string `json:"department_id"`
  166. }
  167. // LinkedCorpDepartmentListResponse 获取互联企业部门列表响应
  168. type LinkedCorpDepartmentListResponse struct {
  169. util.CommonError
  170. DepartmentList []LinkedCorpDepartment `json:"department_list"`
  171. }
  172. // LinkedCorpDepartment 互联企业部门
  173. type LinkedCorpDepartment struct {
  174. DepartmentID string `json:"department_id"`
  175. DepartmentName string `json:"department_name"`
  176. ParentID string `json:"parentid"`
  177. Order int `json:"order"`
  178. }
  179. // LinkedCorpDepartmentList 获取互联企业部门列表
  180. // see https://developer.work.weixin.qq.com/document/path/93170
  181. func (r *Client) LinkedCorpDepartmentList(req *LinkedCorpDepartmentListRequest) (*LinkedCorpDepartmentListResponse, error) {
  182. var (
  183. accessToken string
  184. err error
  185. )
  186. if accessToken, err = r.GetAccessToken(); err != nil {
  187. return nil, err
  188. }
  189. var response []byte
  190. if response, err = util.PostJSON(fmt.Sprintf(linkedCorpDepartmentListURL, accessToken), req); err != nil {
  191. return nil, err
  192. }
  193. result := &LinkedCorpDepartmentListResponse{}
  194. err = util.DecodeWithError(response, result, "LinkedCorpDepartmentList")
  195. return result, err
  196. }