moment.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. package externalcontact
  2. import (
  3. "fmt"
  4. "github.com/silenceper/wechat/v2/util"
  5. )
  6. const (
  7. // addMomentTaskURL 创建发表任务
  8. addMomentTaskURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_moment_task?access_token=%s"
  9. // getMomentTaskResultURL 获取任务创建结果
  10. getMomentTaskResultURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_task_result?access_token=%s&jobid=%s"
  11. // cancelMomentTaskURL 停止发表企业朋友圈
  12. cancelMomentTaskURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/cancel_moment_task?access_token=%s"
  13. // getMomentListURL 获取企业全部的发表列表
  14. getMomentListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_list?access_token=%s"
  15. // getMomentTaskURL 获取客户朋友圈企业发表的列表
  16. getMomentTaskURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_task?access_token=%s"
  17. // getMomentCustomerListURL 获取客户朋友圈发表时选择的可见范围
  18. getMomentCustomerListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_customer_list?access_token=%s"
  19. // getMomentSendResultURL 获取客户朋友圈发表后的可见客户列表
  20. getMomentSendResultURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_send_result?access_token=%s"
  21. // getMomentCommentsURL 获取客户朋友圈的互动数据
  22. getMomentCommentsURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_comments?access_token=%s"
  23. // listMomentStrategyURL 获取规则组列表
  24. listMomentStrategyURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/list?access_token=%s"
  25. // getMomentStrategyURL 获取规则组详情
  26. getMomentStrategyURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/get?access_token=%s"
  27. // getRangeMomentStrategyURL 获取规则组管理范围
  28. getRangeMomentStrategyURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/get_range?access_token=%s"
  29. // createMomentStrategyURL 创建新的规则组
  30. createMomentStrategyURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/create?access_token=%s"
  31. // editMomentStrategyURL 编辑规则组及其管理范围
  32. editMomentStrategyURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/edit?access_token=%s"
  33. // delMomentStrategyURL 删除规则组
  34. delMomentStrategyURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/moment_strategy/del?access_token=%s"
  35. )
  36. // AddMomentTaskRequest 创建发表任务请求
  37. type AddMomentTaskRequest struct {
  38. Text MomentTaskText `json:"text"`
  39. Attachments []MomentTaskAttachment `json:"attachments"`
  40. VisibleRange MomentVisibleRange `json:"visible_range"`
  41. }
  42. // MomentTaskText 发表任务文本消息
  43. type MomentTaskText struct {
  44. Content string `json:"content"`
  45. }
  46. // MomentTaskImage 发表任务图片消息
  47. type MomentTaskImage struct {
  48. MediaID string `json:"media_id"`
  49. }
  50. // MomentTaskVideo 发表任务视频消息
  51. type MomentTaskVideo struct {
  52. MediaID string `json:"media_id"`
  53. }
  54. // MomentTaskLink 发表任务图文消息
  55. type MomentTaskLink struct {
  56. Title string `json:"title"`
  57. URL string `json:"url"`
  58. MediaID string `json:"media_id"`
  59. }
  60. // MomentTaskAttachment 发表任务附件
  61. type MomentTaskAttachment struct {
  62. MsgType string `json:"msgtype"`
  63. Image MomentTaskImage `json:"image,omitempty"`
  64. Video MomentTaskVideo `json:"video,omitempty"`
  65. Link MomentTaskLink `json:"link,omitempty"`
  66. }
  67. // MomentVisibleRange 朋友圈指定的发表范围
  68. type MomentVisibleRange struct {
  69. SenderList MomentSenderList `json:"sender_list"`
  70. ExternalContactList MomentExternalContactList `json:"external_contact_list"`
  71. }
  72. // MomentSenderList 发表任务的执行者列表
  73. type MomentSenderList struct {
  74. UserList []string `json:"user_list"`
  75. DepartmentList []int `json:"department_list"`
  76. }
  77. // MomentExternalContactList 可见到该朋友圈的客户列表
  78. type MomentExternalContactList struct {
  79. TagList []string `json:"tag_list"`
  80. }
  81. // AddMomentTaskResponse 创建发表任务响应
  82. type AddMomentTaskResponse struct {
  83. util.CommonError
  84. JobID string `json:"jobid"`
  85. }
  86. // AddMomentTask 创建发表任务
  87. // see https://developer.work.weixin.qq.com/document/path/95094#%E5%88%9B%E5%BB%BA%E5%8F%91%E8%A1%A8%E4%BB%BB%E5%8A%A1
  88. func (r *Client) AddMomentTask(req *AddMomentTaskRequest) (*AddMomentTaskResponse, 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(addMomentTaskURL, accessToken), req); err != nil {
  98. return nil, err
  99. }
  100. result := &AddMomentTaskResponse{}
  101. err = util.DecodeWithError(response, result, "AddMomentTask")
  102. return result, err
  103. }
  104. // GetMomentTaskResultResponse 获取任务创建结果响应
  105. type GetMomentTaskResultResponse struct {
  106. util.CommonError
  107. Status int `json:"status"`
  108. Type string `json:"type"`
  109. Result MomentTaskResult `json:"result"`
  110. }
  111. // MomentTaskResult 任务创建结果
  112. type MomentTaskResult struct {
  113. ErrCode int64 `json:"errcode"`
  114. ErrMsg string `json:"errmsg"`
  115. MomentID string `json:"moment_id"`
  116. InvalidSenderList MomentInvalidSenderList `json:"invalid_sender_list"`
  117. InvalidExternalContactList MomentInvalidExternalContactList `json:"invalid_external_contact_list"`
  118. }
  119. // MomentInvalidSenderList 不合法的执行者列表
  120. type MomentInvalidSenderList struct {
  121. UserList []string `json:"user_list"`
  122. DepartmentList []int `json:"department_list"`
  123. }
  124. // MomentInvalidExternalContactList 不合法的可见到该朋友圈的客户列表
  125. type MomentInvalidExternalContactList struct {
  126. TagList []string `json:"tag_list"`
  127. }
  128. // GetMomentTaskResult 获取任务创建结果
  129. // see https://developer.work.weixin.qq.com/document/path/95094#%E8%8E%B7%E5%8F%96%E4%BB%BB%E5%8A%A1%E5%88%9B%E5%BB%BA%E7%BB%93%E6%9E%9C
  130. func (r *Client) GetMomentTaskResult(jobID string) (*GetMomentTaskResultResponse, error) {
  131. var (
  132. accessToken string
  133. err error
  134. )
  135. if accessToken, err = r.GetAccessToken(); err != nil {
  136. return nil, err
  137. }
  138. var response []byte
  139. if response, err = util.HTTPGet(fmt.Sprintf(getMomentTaskResultURL, accessToken, jobID)); err != nil {
  140. return nil, err
  141. }
  142. result := &GetMomentTaskResultResponse{}
  143. err = util.DecodeWithError(response, result, "GetMomentTaskResult")
  144. return result, err
  145. }
  146. // CancelMomentTaskRequest 停止发表企业朋友圈请求
  147. type CancelMomentTaskRequest struct {
  148. MomentID string `json:"moment_id"`
  149. }
  150. // CancelMomentTask 停止发表企业朋友圈
  151. // see https://developer.work.weixin.qq.com/document/path/97612
  152. func (r *Client) CancelMomentTask(req *CancelMomentTaskRequest) error {
  153. var (
  154. accessToken string
  155. err error
  156. )
  157. if accessToken, err = r.GetAccessToken(); err != nil {
  158. return err
  159. }
  160. var response []byte
  161. if response, err = util.PostJSON(fmt.Sprintf(cancelMomentTaskURL, accessToken), req); err != nil {
  162. return err
  163. }
  164. return util.DecodeWithCommonError(response, "CancelMomentTask")
  165. }
  166. // GetMomentListRequest 获取企业全部的发表列表请求
  167. type GetMomentListRequest struct {
  168. StartTime int64 `json:"start_time"`
  169. EndTime int64 `json:"end_time"`
  170. Creator string `json:"creator"`
  171. FilterType int `json:"filter_type"`
  172. Cursor string `json:"cursor"`
  173. Limit int `json:"limit"`
  174. }
  175. // GetMomentListResponse 获取企业全部的发表列表响应
  176. type GetMomentListResponse struct {
  177. util.CommonError
  178. NextCursor string `json:"next_cursor"`
  179. MomentList []MomentItem `json:"moment_list"`
  180. }
  181. // MomentItem 朋友圈
  182. type MomentItem struct {
  183. MomentID string `json:"moment_id"`
  184. Creator string `json:"creator"`
  185. CreateTime int64 `json:"create_time"`
  186. CreateType int `json:"create_type"`
  187. VisibleType int `json:"visible_type"`
  188. Text MomentText `json:"text"`
  189. Image []MomentImage `json:"image"`
  190. Video MomentVideo `json:"video"`
  191. Link MomentLink `json:"link"`
  192. Location MomentLocation `json:"location"`
  193. }
  194. // MomentText 朋友圈文本消息
  195. type MomentText struct {
  196. Content string `json:"content"`
  197. }
  198. // MomentImage 朋友圈图片
  199. type MomentImage struct {
  200. MediaID string `json:"media_id"`
  201. }
  202. // MomentVideo 朋友圈视频
  203. type MomentVideo struct {
  204. MediaID string `json:"media_id"`
  205. ThumbMediaID string `json:"thumb_media_id"`
  206. }
  207. // MomentLink 朋友圈网页链接
  208. type MomentLink struct {
  209. Title string `json:"title"`
  210. URL string `json:"url"`
  211. }
  212. // MomentLocation 朋友圈地理位置
  213. type MomentLocation struct {
  214. Latitude string `json:"latitude"`
  215. Longitude string `json:"longitude"`
  216. Name string `json:"name"`
  217. }
  218. // GetMomentList 获取企业全部的发表列表
  219. // see https://developer.work.weixin.qq.com/document/path/93333#%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E5%85%A8%E9%83%A8%E7%9A%84%E5%8F%91%E8%A1%A8%E5%88%97%E8%A1%A8
  220. func (r *Client) GetMomentList(req *GetMomentListRequest) (*GetMomentListResponse, error) {
  221. var (
  222. accessToken string
  223. err error
  224. )
  225. if accessToken, err = r.GetAccessToken(); err != nil {
  226. return nil, err
  227. }
  228. var response []byte
  229. if response, err = util.PostJSON(fmt.Sprintf(getMomentListURL, accessToken), req); err != nil {
  230. return nil, err
  231. }
  232. result := &GetMomentListResponse{}
  233. err = util.DecodeWithError(response, result, "GetMomentList")
  234. return result, err
  235. }
  236. // GetMomentTaskRequest 获取客户朋友圈企业发表的列表请求
  237. type GetMomentTaskRequest struct {
  238. MomentID string `json:"moment_id"`
  239. Cursor string `json:"cursor"`
  240. Limit int `json:"limit"`
  241. }
  242. // GetMomentTaskResponse 获取客户朋友圈企业发表的列表响应
  243. type GetMomentTaskResponse struct {
  244. util.CommonError
  245. NextCursor string `json:"next_cursor"`
  246. TaskList []MomentTask `json:"task_list"`
  247. }
  248. // MomentTask 发表任务
  249. type MomentTask struct {
  250. UserID string `json:"userid"`
  251. PublishStatus int `json:"publish_status"`
  252. }
  253. // GetMomentTask 获取客户朋友圈企业发表的列表
  254. // see https://developer.work.weixin.qq.com/document/path/93333#%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%88%B7%E6%9C%8B%E5%8F%8B%E5%9C%88%E4%BC%81%E4%B8%9A%E5%8F%91%E8%A1%A8%E7%9A%84%E5%88%97%E8%A1%A8
  255. func (r *Client) GetMomentTask(req *GetMomentTaskRequest) (*GetMomentTaskResponse, error) {
  256. var (
  257. accessToken string
  258. err error
  259. )
  260. if accessToken, err = r.GetAccessToken(); err != nil {
  261. return nil, err
  262. }
  263. var response []byte
  264. if response, err = util.PostJSON(fmt.Sprintf(getMomentTaskURL, accessToken), req); err != nil {
  265. return nil, err
  266. }
  267. result := &GetMomentTaskResponse{}
  268. err = util.DecodeWithError(response, result, "GetMomentTask")
  269. return result, err
  270. }
  271. // GetMomentCustomerListRequest 获取客户朋友圈发表时选择的可见范围请求
  272. type GetMomentCustomerListRequest struct {
  273. MomentID string `json:"moment_id"`
  274. UserID string `json:"userid"`
  275. Cursor string `json:"cursor"`
  276. Limit int `json:"limit"`
  277. }
  278. // GetMomentCustomerListResponse 获取客户朋友圈发表时选择的可见范围响应
  279. type GetMomentCustomerListResponse struct {
  280. util.CommonError
  281. NextCursor string `json:"next_cursor"`
  282. CustomerList []MomentCustomer `json:"customer_list"`
  283. }
  284. // MomentCustomer 成员可见客户列表
  285. type MomentCustomer struct {
  286. UserID string `json:"userid"`
  287. ExternalUserID string `json:"external_userid"`
  288. }
  289. // GetMomentCustomerList 获取客户朋友圈发表时选择的可见范围
  290. // see https://developer.work.weixin.qq.com/document/path/93333#%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%88%B7%E6%9C%8B%E5%8F%8B%E5%9C%88%E5%8F%91%E8%A1%A8%E6%97%B6%E9%80%89%E6%8B%A9%E7%9A%84%E5%8F%AF%E8%A7%81%E8%8C%83%E5%9B%B4
  291. func (r *Client) GetMomentCustomerList(req *GetMomentCustomerListRequest) (*GetMomentCustomerListResponse, error) {
  292. var (
  293. accessToken string
  294. err error
  295. )
  296. if accessToken, err = r.GetAccessToken(); err != nil {
  297. return nil, err
  298. }
  299. var response []byte
  300. if response, err = util.PostJSON(fmt.Sprintf(getMomentCustomerListURL, accessToken), req); err != nil {
  301. return nil, err
  302. }
  303. result := &GetMomentCustomerListResponse{}
  304. err = util.DecodeWithError(response, result, "GetMomentCustomerList")
  305. return result, err
  306. }
  307. // GetMomentSendResultRequest 获取客户朋友圈发表后的可见客户列表请求
  308. type GetMomentSendResultRequest struct {
  309. MomentID string `json:"moment_id"`
  310. UserID string `json:"userid"`
  311. Cursor string `json:"cursor"`
  312. Limit int `json:"limit"`
  313. }
  314. // GetMomentSendResultResponse 获取客户朋友圈发表后的可见客户列表响应
  315. type GetMomentSendResultResponse struct {
  316. util.CommonError
  317. NextCursor string `json:"next_cursor"`
  318. CustomerList []MomentSendCustomer `json:"customer_list"`
  319. }
  320. // MomentSendCustomer 成员发送成功客户
  321. type MomentSendCustomer struct {
  322. ExternalUserID string `json:"external_userid"`
  323. }
  324. // GetMomentSendResult 获取客户朋友圈发表后的可见客户列表
  325. // see https://developer.work.weixin.qq.com/document/path/93333#%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%88%B7%E6%9C%8B%E5%8F%8B%E5%9C%88%E5%8F%91%E8%A1%A8%E5%90%8E%E7%9A%84%E5%8F%AF%E8%A7%81%E5%AE%A2%E6%88%B7%E5%88%97%E8%A1%A8
  326. func (r *Client) GetMomentSendResult(req *GetMomentSendResultRequest) (*GetMomentSendResultResponse, error) {
  327. var (
  328. accessToken string
  329. err error
  330. )
  331. if accessToken, err = r.GetAccessToken(); err != nil {
  332. return nil, err
  333. }
  334. var response []byte
  335. if response, err = util.PostJSON(fmt.Sprintf(getMomentSendResultURL, accessToken), req); err != nil {
  336. return nil, err
  337. }
  338. result := &GetMomentSendResultResponse{}
  339. err = util.DecodeWithError(response, result, "GetMomentSendResult")
  340. return result, err
  341. }
  342. // GetMomentCommentsRequest 获取客户朋友圈的互动数据请求
  343. type GetMomentCommentsRequest struct {
  344. MomentID string `json:"moment_id"`
  345. UserID string `json:"userid"`
  346. }
  347. // GetMomentCommentsResponse 获取客户朋友圈的互动数据响应
  348. type GetMomentCommentsResponse struct {
  349. util.CommonError
  350. CommentList []MomentComment `json:"comment_list"`
  351. LikeList []MomentLike `json:"like_list"`
  352. }
  353. // MomentComment 朋友圈评论
  354. type MomentComment struct {
  355. ExternalUserID string `json:"external_userid,omitempty"`
  356. UserID string `json:"userid,omitempty"`
  357. CreateTime int64 `json:"create_time"`
  358. }
  359. // MomentLike 朋友圈点赞
  360. type MomentLike struct {
  361. ExternalUserID string `json:"external_userid,omitempty"`
  362. UserID string `json:"userid,omitempty"`
  363. CreateTime int64 `json:"create_time"`
  364. }
  365. // GetMomentComments 获取客户朋友圈的互动数据
  366. // see https://developer.work.weixin.qq.com/document/path/93333#%E8%8E%B7%E5%8F%96%E5%AE%A2%E6%88%B7%E6%9C%8B%E5%8F%8B%E5%9C%88%E7%9A%84%E4%BA%92%E5%8A%A8%E6%95%B0%E6%8D%AE
  367. func (r *Client) GetMomentComments(req *GetMomentCommentsRequest) (*GetMomentCommentsResponse, error) {
  368. var (
  369. accessToken string
  370. err error
  371. )
  372. if accessToken, err = r.GetAccessToken(); err != nil {
  373. return nil, err
  374. }
  375. var response []byte
  376. if response, err = util.PostJSON(fmt.Sprintf(getMomentCommentsURL, accessToken), req); err != nil {
  377. return nil, err
  378. }
  379. result := &GetMomentCommentsResponse{}
  380. err = util.DecodeWithError(response, result, "GetMomentComments")
  381. return result, err
  382. }
  383. // ListMomentStrategyRequest 获取规则组列表请求
  384. type ListMomentStrategyRequest struct {
  385. Cursor string `json:"cursor"`
  386. Limit int `json:"limit"`
  387. }
  388. // ListMomentStrategyResponse 获取规则组列表响应
  389. type ListMomentStrategyResponse struct {
  390. util.CommonError
  391. Strategy []MomentStrategyID `json:"strategy"`
  392. NextCursor string `json:"next_cursor"`
  393. }
  394. // MomentStrategyID 规则组 ID
  395. type MomentStrategyID struct {
  396. StrategyID int `json:"strategy_id"`
  397. }
  398. // ListMomentStrategy 获取规则组列表
  399. // see https://developer.work.weixin.qq.com/document/path/94890#%E8%8E%B7%E5%8F%96%E8%A7%84%E5%88%99%E7%BB%84%E5%88%97%E8%A1%A8
  400. func (r *Client) ListMomentStrategy(req *ListMomentStrategyRequest) (*ListMomentStrategyResponse, error) {
  401. var (
  402. accessToken string
  403. err error
  404. )
  405. if accessToken, err = r.GetAccessToken(); err != nil {
  406. return nil, err
  407. }
  408. var response []byte
  409. if response, err = util.PostJSON(fmt.Sprintf(listMomentStrategyURL, accessToken), req); err != nil {
  410. return nil, err
  411. }
  412. result := &ListMomentStrategyResponse{}
  413. err = util.DecodeWithError(response, result, "ListMomentStrategy")
  414. return result, err
  415. }
  416. // GetMomentStrategyRequest 获取规则组详情请求
  417. type GetMomentStrategyRequest struct {
  418. StrategyID int `json:"strategy_id"`
  419. }
  420. // GetMomentStrategyResponse 获取规则组详情响应
  421. type GetMomentStrategyResponse struct {
  422. util.CommonError
  423. Strategy MomentStrategy `json:"strategy"`
  424. }
  425. // MomentStrategy 规则组
  426. type MomentStrategy struct {
  427. StrategyID int `json:"strategy_id"`
  428. ParentID int `json:"parent_id"`
  429. StrategyName string `json:"strategy_name"`
  430. CreateTime int64 `json:"create_time"`
  431. AdminList []string `json:"admin_list"`
  432. Privilege MomentPrivilege `json:"privilege"`
  433. }
  434. // MomentPrivilege 规则组权限
  435. type MomentPrivilege struct {
  436. ViewMomentList bool `json:"view_moment_list"`
  437. SendMoment bool `json:"send_moment"`
  438. ManageMomentCoverAndSign bool `json:"manage_moment_cover_and_sign"`
  439. }
  440. // GetMomentStrategy 获取规则组详情
  441. // see https://developer.work.weixin.qq.com/document/path/94890#%E8%8E%B7%E5%8F%96%E8%A7%84%E5%88%99%E7%BB%84%E8%AF%A6%E6%83%85
  442. func (r *Client) GetMomentStrategy(req *GetMomentStrategyRequest) (*GetMomentStrategyResponse, error) {
  443. var (
  444. accessToken string
  445. err error
  446. )
  447. if accessToken, err = r.GetAccessToken(); err != nil {
  448. return nil, err
  449. }
  450. var response []byte
  451. if response, err = util.PostJSON(fmt.Sprintf(getMomentStrategyURL, accessToken), req); err != nil {
  452. return nil, err
  453. }
  454. result := &GetMomentStrategyResponse{}
  455. err = util.DecodeWithError(response, result, "GetMomentStrategy")
  456. return result, err
  457. }
  458. // GetRangeMomentStrategyRequest 获取规则组管理范围请求
  459. type GetRangeMomentStrategyRequest struct {
  460. StrategyID int `json:"strategy_id"`
  461. Cursor string `json:"cursor"`
  462. Limit int `json:"limit"`
  463. }
  464. // GetRangeMomentStrategyResponse 获取规则组管理范围响应
  465. type GetRangeMomentStrategyResponse struct {
  466. util.CommonError
  467. Range []RangeMomentStrategy `json:"range"`
  468. NextCursor string `json:"next_cursor"`
  469. }
  470. // RangeMomentStrategy 管理范围内配置的成员或部门
  471. type RangeMomentStrategy struct {
  472. Type int `json:"type"`
  473. UserID string `json:"userid,omitempty"`
  474. PartyID int `json:"partyid,omitempty"`
  475. }
  476. // GetRangeMomentStrategy 获取规则组管理范围
  477. // see https://developer.work.weixin.qq.com/document/path/94890#%E8%8E%B7%E5%8F%96%E8%A7%84%E5%88%99%E7%BB%84%E7%AE%A1%E7%90%86%E8%8C%83%E5%9B%B4
  478. func (r *Client) GetRangeMomentStrategy(req *GetRangeMomentStrategyRequest) (*GetRangeMomentStrategyResponse, error) {
  479. var (
  480. accessToken string
  481. err error
  482. )
  483. if accessToken, err = r.GetAccessToken(); err != nil {
  484. return nil, err
  485. }
  486. var response []byte
  487. if response, err = util.PostJSON(fmt.Sprintf(getRangeMomentStrategyURL, accessToken), req); err != nil {
  488. return nil, err
  489. }
  490. result := &GetRangeMomentStrategyResponse{}
  491. err = util.DecodeWithError(response, result, "GetRangeMomentStrategy")
  492. return result, err
  493. }
  494. // CreateMomentStrategyRequest 创建新的规则组请求
  495. type CreateMomentStrategyRequest struct {
  496. ParentID int `json:"parent_id"`
  497. StrategyName string `json:"strategy_name"`
  498. AdminList []string `json:"admin_list"`
  499. Privilege MomentPrivilege `json:"privilege"`
  500. Range []RangeMomentStrategy `json:"range"`
  501. }
  502. // CreateMomentStrategyResponse 创建新的规则组响应
  503. type CreateMomentStrategyResponse struct {
  504. util.CommonError
  505. StrategyID int `json:"strategy_id"`
  506. }
  507. // CreateMomentStrategy 创建新的规则组
  508. // see https://developer.work.weixin.qq.com/document/path/94890#%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E8%A7%84%E5%88%99%E7%BB%84
  509. func (r *Client) CreateMomentStrategy(req *CreateMomentStrategyRequest) (*CreateMomentStrategyResponse, error) {
  510. var (
  511. accessToken string
  512. err error
  513. )
  514. if accessToken, err = r.GetAccessToken(); err != nil {
  515. return nil, err
  516. }
  517. var response []byte
  518. if response, err = util.PostJSON(fmt.Sprintf(createMomentStrategyURL, accessToken), req); err != nil {
  519. return nil, err
  520. }
  521. result := &CreateMomentStrategyResponse{}
  522. err = util.DecodeWithError(response, result, "CreateMomentStrategy")
  523. return result, err
  524. }
  525. // EditMomentStrategyRequest 编辑规则组及其管理范围请求
  526. type EditMomentStrategyRequest struct {
  527. StrategyID int `json:"strategy_id"`
  528. StrategyName string `json:"strategy_name"`
  529. AdminList []string `json:"admin_list"`
  530. Privilege MomentPrivilege `json:"privilege"`
  531. RangeAdd []RangeMomentStrategy `json:"range_add"`
  532. RangeDel []RangeMomentStrategy `json:"range_del"`
  533. }
  534. // EditMomentStrategy 编辑规则组及其管理范围
  535. // see https://developer.work.weixin.qq.com/document/path/94890#%E7%BC%96%E8%BE%91%E8%A7%84%E5%88%99%E7%BB%84%E5%8F%8A%E5%85%B6%E7%AE%A1%E7%90%86%E8%8C%83%E5%9B%B4
  536. func (r *Client) EditMomentStrategy(req *EditMomentStrategyRequest) error {
  537. var (
  538. accessToken string
  539. err error
  540. )
  541. if accessToken, err = r.GetAccessToken(); err != nil {
  542. return err
  543. }
  544. var response []byte
  545. if response, err = util.PostJSON(fmt.Sprintf(editMomentStrategyURL, accessToken), req); err != nil {
  546. return err
  547. }
  548. return util.DecodeWithCommonError(response, "EditMomentStrategy")
  549. }
  550. // DelMomentStrategyRequest 删除规则组请求
  551. type DelMomentStrategyRequest struct {
  552. StrategyID int `json:"strategy_id"`
  553. }
  554. // DelMomentStrategy 删除规则组
  555. // see https://developer.work.weixin.qq.com/document/path/94890#%E5%88%A0%E9%99%A4%E8%A7%84%E5%88%99%E7%BB%84
  556. func (r *Client) DelMomentStrategy(req *DelMomentStrategyRequest) error {
  557. var (
  558. accessToken string
  559. err error
  560. )
  561. if accessToken, err = r.GetAccessToken(); err != nil {
  562. return err
  563. }
  564. var response []byte
  565. if response, err = util.PostJSON(fmt.Sprintf(delMomentStrategyURL, accessToken), req); err != nil {
  566. return err
  567. }
  568. return util.DecodeWithCommonError(response, "DelMomentStrategy")
  569. }