Преглед изворни кода

企业微信-[联系我]方式列表、删除 (#606)

markwang пре 3 година
родитељ
комит
86e036a55b
2 измењених фајлова са 79 додато и 2 уклоњено
  1. 2 2
      doc/api/work.md
  2. 77 0
      work/externalcontact/contact_way.go

+ 2 - 2
doc/api/work.md

@@ -70,6 +70,8 @@ host: https://qyapi.weixin.qq.com/
 | 配置客户联系「联系我」方式 | POST      |  /cgi-bin/externalcontact/add_contact_way      | YES        | (r *Client) AddContactWay  | MARKWANG  |
 | 获取企业已配置的「联系我」方式 | POST      |  /cgi-bin/externalcontact/get_contact_way      | YES        | (r *Client) GetContactWay  | MARKWANG  |
 | 更新企业已配置的「联系我」方式 | POST      |  /cgi-bin/externalcontact/update_contact_way      | YES        | (r *Client) UpdateContactWay  | MARKWANG  |
+| 获取企业已配置的「联系我」列表 | POST      |  /cgi-bin/externalcontact/list_contact_way      | YES        | (r *Client) ListContactWay  | MARKWANG  |
+| 删除企业已配置的「联系我」方式 | POST      |  /cgi-bin/externalcontact/del_contact_way      | YES        | (r *Client) DelContactWay  | MARKWANG  |
 
 ## 通讯录管理
 [官方文档](https://developer.work.weixin.qq.com/document/path/95350/90200)
@@ -83,5 +85,3 @@ host: https://qyapi.weixin.qq.com/
 ## 应用管理
 
 TODO
-
-

+ 77 - 0
work/externalcontact/contact_way.go

@@ -13,6 +13,10 @@ const (
 	GetContactWayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_contact_way?access_token=%s"
 	// UpdateContactWayURL 更新企业已配置的「联系我」方式
 	UpdateContactWayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_contact_way?access_token=%s"
+	// ListContactWayURL 获取企业已配置的「联系我」列表
+	ListContactWayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list_contact_way?access_token=%s"
+	// DelContactWayURL 删除企业已配置的「联系我」方式
+	DelContactWayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_contact_way?access_token=%s"
 )
 
 type (
@@ -196,3 +200,76 @@ func (r *Client) UpdateContactWay(req *UpdateContactWayRequest) (*UpdateContactW
 	}
 	return result, nil
 }
+
+type (
+	//ListContactWayRequest 获取企业已配置的「联系我」列表请求
+	ListContactWayRequest struct {
+		StartTime int    `json:"start_time"`
+		EndTime   int    `json:"end_time"`
+		Cursor    string `json:"cursor"`
+		Limit     int    `json:"limit"`
+	}
+	//ListContactWayResponse 获取企业已配置的「联系我」列表响应
+	ListContactWayResponse struct {
+		util.CommonError
+		ContactWay []*ContactWayForList `json:"contact_way"`
+		NextCursor string               `json:"next_cursor"`
+	}
+	// ContactWayForList 「联系我」配置
+	ContactWayForList struct {
+		ConfigID string `json:"config_id"`
+	}
+)
+
+// ListContactWay 获取企业已配置的「联系我」列表
+// see https://developer.work.weixin.qq.com/document/path/92228
+func (r *Client) ListContactWay(req *ListContactWayRequest) (*ListContactWayResponse, error) {
+	var (
+		accessToken string
+		err         error
+	)
+	if accessToken, err = r.GetAccessToken(); err != nil {
+		return nil, err
+	}
+	var response []byte
+	if response, err = util.PostJSON(fmt.Sprintf(ListContactWayURL, accessToken), req); err != nil {
+		return nil, err
+	}
+	result := &ListContactWayResponse{}
+	if err = util.DecodeWithError(response, result, "ListContactWay"); err != nil {
+		return nil, err
+	}
+	return result, nil
+}
+
+type (
+	// DelContactWayRequest 删除企业已配置的「联系我」方式请求
+	DelContactWayRequest struct {
+		ConfigID string `json:"config_id"`
+	}
+	// DelContactWayResponse 删除企业已配置的「联系我」方式响应
+	DelContactWayResponse struct {
+		util.CommonError
+	}
+)
+
+// DelContactWay 删除企业已配置的「联系我」方式
+// see https://developer.work.weixin.qq.com/document/path/92228
+func (r *Client) DelContactWay(req *DelContactWayRequest) (*DelContactWayResponse, error) {
+	var (
+		accessToken string
+		err         error
+	)
+	if accessToken, err = r.GetAccessToken(); err != nil {
+		return nil, err
+	}
+	var response []byte
+	if response, err = util.PostJSON(fmt.Sprintf(DelContactWayURL, accessToken), req); err != nil {
+		return nil, err
+	}
+	result := &DelContactWayResponse{}
+	if err = util.DecodeWithError(response, result, "DelContactWay"); err != nil {
+		return nil, err
+	}
+	return result, nil
+}