mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
Compare commits
4 Commits
v2.1.4-rc.
...
v2.1.5-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3cb741ae1a | ||
|
|
da3859261b | ||
|
|
86ceb6af2f | ||
|
|
243f8198ae |
@@ -62,21 +62,25 @@ host: https://qyapi.weixin.qq.com/
|
|||||||
### 客户联系
|
### 客户联系
|
||||||
[官方文档](https://developer.work.weixin.qq.com/document/path/92132/92133/92228)
|
[官方文档](https://developer.work.weixin.qq.com/document/path/92132/92133/92228)
|
||||||
|
|
||||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|
||||||
|:------------------------:| -------- | :---------------------------------------| ---------- | ------------------------------- |----------|
|
|:------------------------:| -------- |:-------------------------------------------------------------| ---------- | ------------------------------- |----------|
|
||||||
| 获取「联系客户统计」数据 | POST | /cgi-bin/externalcontact/get_user_behavior_data | YES | (r *Client) GetUserBehaviorData | MARKWANG |
|
| 获取「联系客户统计」数据 | POST | /cgi-bin/externalcontact/get_user_behavior_data | YES | (r *Client) GetUserBehaviorData | MARKWANG |
|
||||||
| 获取「群聊数据统计」数据 (按群主聚合的方式) | POST | /cgi-bin/externalcontact/groupchat/statistic | YES | (r *Client) GetGroupChatStat | MARKWANG |
|
| 获取「群聊数据统计」数据 (按群主聚合的方式) | POST | /cgi-bin/externalcontact/groupchat/statistic | YES | (r *Client) GetGroupChatStat | MARKWANG |
|
||||||
| 获取「群聊数据统计」数据 (按自然日聚合的方式) | POST | /cgi-bin/externalcontact/groupchat/statistic_group_by_day | YES | (r *Client) GetGroupChatStatByDay | MARKWANG |
|
| 获取「群聊数据统计」数据 (按自然日聚合的方式) | POST | /cgi-bin/externalcontact/groupchat/statistic_group_by_day | YES | (r *Client) GetGroupChatStatByDay | MARKWANG |
|
||||||
| 配置客户联系「联系我」方式 | POST | /cgi-bin/externalcontact/add_contact_way | YES | (r *Client) AddContactWay | MARKWANG |
|
| 配置客户联系「联系我」方式 | 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/get_contact_way | YES | (r *Client) GetContactWay | MARKWANG |
|
||||||
| 更新企业已配置的「联系我」方式 | POST | /cgi-bin/externalcontact/update_contact_way | YES | (r *Client) UpdateContactWay | 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/list_contact_way | YES | (r *Client) ListContactWay | MARKWANG |
|
||||||
| 删除企业已配置的「联系我」方式 | POST | /cgi-bin/externalcontact/del_contact_way | YES | (r *Client) DelContactWay | MARKWANG |
|
| 删除企业已配置的「联系我」方式 | POST | /cgi-bin/externalcontact/del_contact_way | YES | (r *Client) DelContactWay | MARKWANG |
|
||||||
| 创建企业群发 | POST | /cgi-bin/externalcontact/add_msg_template | YES | (r *Client) AddMsgTemplate | MARKWANG |
|
| 创建企业群发 | POST | /cgi-bin/externalcontact/add_msg_template | YES | (r *Client) AddMsgTemplate | MARKWANG |
|
||||||
| 获取群发记录列表 | POST | /cgi-bin/externalcontact/get_groupmsg_list_v2 | YES | (r *Client) GetGroupMsgListV2 | MARKWANG |
|
| 获取群发记录列表 | POST | /cgi-bin/externalcontact/get_groupmsg_list_v2 | YES | (r *Client) GetGroupMsgListV2 | MARKWANG |
|
||||||
| 获取群发成员发送任务列表 | POST | /cgi-bin/externalcontact/get_groupmsg_task | YES | (r *Client) GetGroupMsgTask | MARKWANG |
|
| 获取群发成员发送任务列表 | POST | /cgi-bin/externalcontact/get_groupmsg_task | YES | (r *Client) GetGroupMsgTask | MARKWANG |
|
||||||
| 获取企业群发成员执行结果 | POST | /cgi-bin/externalcontact/get_groupmsg_send_result | YES | (r *Client) GetGroupMsgSendResult | MARKWANG |
|
| 获取企业群发成员执行结果 | POST | /cgi-bin/externalcontact/get_groupmsg_send_result | YES | (r *Client) GetGroupMsgSendResult | MARKWANG |
|
||||||
| 发送新客户欢迎语 | POST | /cgi-bin/externalcontact/send_welcome_msg | YES | (r *Client) SendWelcomeMsg | MARKWANG |
|
| 发送新客户欢迎语 | POST | /cgi-bin/externalcontact/send_welcome_msg | YES | (r *Client) SendWelcomeMsg | MARKWANG |
|
||||||
|
| 添加入群欢迎语素材 | POST | /cgi-bin/externalcontact/group_welcome_template/add | YES | (r *Client) AddGroupWelcomeTemplate | MARKWANG |
|
||||||
|
| 编辑入群欢迎语素材 | POST | /cgi-bin/externalcontact/group_welcome_template/edit | YES | (r *Client) EditGroupWelcomeTemplate | MARKWANG |
|
||||||
|
| 获取入群欢迎语素材 | POST | /cgi-bin/externalcontact/group_welcome_template/get | YES | (r *Client) GetGroupWelcomeTemplate | MARKWANG |
|
||||||
|
| 删除入群欢迎语素材 | POST | /cgi-bin/externalcontact/group_welcome_template/del | YES | (r *Client) DelGroupWelcomeTemplate | MARKWANG |
|
||||||
|
|
||||||
## 通讯录管理
|
## 通讯录管理
|
||||||
[官方文档](https://developer.work.weixin.qq.com/document/path/90193)
|
[官方文档](https://developer.work.weixin.qq.com/document/path/90193)
|
||||||
@@ -87,6 +91,7 @@ host: https://qyapi.weixin.qq.com/
|
|||||||
|:---------:|------|:----------------------------------------| ---------- | ------------------------------- |----------|
|
|:---------:|------|:----------------------------------------| ---------- | ------------------------------- |----------|
|
||||||
| 获取子部门ID列表 | GET | /cgi-bin/department/simplelist | YES | (r *Client) DepartmentSimpleList| MARKWANG |
|
| 获取子部门ID列表 | GET | /cgi-bin/department/simplelist | YES | (r *Client) DepartmentSimpleList| MARKWANG |
|
||||||
| 获取部门成员 | GET | /cgi-bin/user/simplelist | YES | (r *Client) UserSimpleList | MARKWANG |
|
| 获取部门成员 | GET | /cgi-bin/user/simplelist | YES | (r *Client) UserSimpleList | MARKWANG |
|
||||||
|
| 获取成员ID列表 | Post | /cgi-bin/user/list_id | YES | (r *Client) UserListId | MARKWANG |
|
||||||
|
|
||||||
|
|
||||||
## 素材管理
|
## 素材管理
|
||||||
|
|||||||
@@ -80,6 +80,12 @@ const (
|
|||||||
EventSubscribeMsgPopupEvent EventType = "subscribe_msg_popup_event"
|
EventSubscribeMsgPopupEvent EventType = "subscribe_msg_popup_event"
|
||||||
// EventPublishJobFinish 发布任务完成
|
// EventPublishJobFinish 发布任务完成
|
||||||
EventPublishJobFinish EventType = "PUBLISHJOBFINISH"
|
EventPublishJobFinish EventType = "PUBLISHJOBFINISH"
|
||||||
|
// EventWeappAuditSuccess 审核通过
|
||||||
|
EventWeappAuditSuccess EventType = "weapp_audit_success"
|
||||||
|
// EventWeappAuditFail 审核不通过
|
||||||
|
EventWeappAuditFail EventType = "weapp_audit_fail"
|
||||||
|
// EventWeappAuditDelay 审核延后
|
||||||
|
EventWeappAuditDelay EventType = "weapp_audit_delay"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -209,6 +215,13 @@ type MixMessage struct {
|
|||||||
|
|
||||||
// 设备相关
|
// 设备相关
|
||||||
device.MsgDevice
|
device.MsgDevice
|
||||||
|
|
||||||
|
//小程序审核通知
|
||||||
|
SuccTime int `xml:"SuccTime"` //审核成功时的时间戳
|
||||||
|
FailTime int `xml:"FailTime"` //审核不通过的时间戳
|
||||||
|
DelayTime int `xml:"DelayTime"` //审核延后时的时间戳
|
||||||
|
Reason string `xml:"Reason"` //审核不通过的原因
|
||||||
|
ScreenShot string `xml:"ScreenShot"` //审核不通过的截图示例。用 | 分隔的 media_id 的列表,可通过获取永久素材接口拉取截图内容
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubscribeMsgPopupEvent 订阅通知事件推送的消息体
|
// SubscribeMsgPopupEvent 订阅通知事件推送的消息体
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ const (
|
|||||||
UserSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=%s&department_id=%d"
|
UserSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=%s&department_id=%d"
|
||||||
// UserGetURL 读取成员
|
// UserGetURL 读取成员
|
||||||
UserGetURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=%s&userid=%s"
|
UserGetURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=%s&userid=%s"
|
||||||
|
// UserListIDURL 获取成员ID列表
|
||||||
|
UserListIDURL = "https://qyapi.weixin.qq.com/cgi-bin/user/list_id?access_token=%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -133,3 +135,43 @@ func (r *Client) UserGet(UserID string) (*UserGetResponse, error) {
|
|||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserListIDRequest 获取成员ID列表请求
|
||||||
|
type UserListIDRequest struct {
|
||||||
|
Cursor string `json:"cursor"`
|
||||||
|
Limit int `json:"limit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserListIDResponse 获取成员ID列表响应
|
||||||
|
type UserListIDResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
NextCursor string `json:"next_cursor"`
|
||||||
|
DeptUser []*DeptUser `json:"dept_user"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeptUser 用户-部门关系
|
||||||
|
type DeptUser struct {
|
||||||
|
UserID string `json:"userid"`
|
||||||
|
Department int `json:"department"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserListID 获取成员ID列表
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/96067
|
||||||
|
func (r *Client) UserListID(req *UserListIDRequest) (*UserListIDResponse, 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(UserListIDURL, accessToken), req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &UserListIDResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "UserListID"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,23 +47,23 @@ func (r *Client) GetExternalUserList(userID string) ([]string, error) {
|
|||||||
// ExternalUserDetailResponse 外部联系人详情响应
|
// ExternalUserDetailResponse 外部联系人详情响应
|
||||||
type ExternalUserDetailResponse struct {
|
type ExternalUserDetailResponse struct {
|
||||||
util.CommonError
|
util.CommonError
|
||||||
ExternalUser
|
ExternalContact ExternalUser `json:"external_contact"`
|
||||||
|
FollowUser []FollowUser `json:"follow_user"`
|
||||||
|
NextCursor string `json:"next_cursor"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExternalUser 外部联系人
|
// ExternalUser 外部联系人
|
||||||
type ExternalUser struct {
|
type ExternalUser struct {
|
||||||
ExternalUserID string `json:"external_userid"`
|
ExternalUserID string `json:"external_userid"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
Type int64 `json:"type"`
|
Type int64 `json:"type"`
|
||||||
Gender int64 `json:"gender"`
|
Gender int64 `json:"gender"`
|
||||||
UnionID string `json:"unionid"`
|
UnionID string `json:"unionid"`
|
||||||
Position string `json:"position"`
|
Position string `json:"position"`
|
||||||
CorpName string `json:"corp_name"`
|
CorpName string `json:"corp_name"`
|
||||||
CorpFullName string `json:"corp_full_name"`
|
CorpFullName string `json:"corp_full_name"`
|
||||||
ExternalProfile string `json:"external_profile"`
|
ExternalProfile string `json:"external_profile"`
|
||||||
FollowUser []FollowUser `json:"follow_user"`
|
|
||||||
NextCursor string `json:"next_cursor"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FollowUser 跟进用户(指企业内部用户)
|
// FollowUser 跟进用户(指企业内部用户)
|
||||||
@@ -96,7 +96,8 @@ type WechatChannel struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetExternalUserDetail 获取外部联系人详情
|
// GetExternalUserDetail 获取外部联系人详情
|
||||||
func (r *Client) GetExternalUserDetail(externalUserID string, nextCursor ...string) (*ExternalUser, error) {
|
// @see https://developer.work.weixin.qq.com/document/path/92114
|
||||||
|
func (r *Client) GetExternalUserDetail(externalUserID string, nextCursor ...string) (*ExternalUserDetailResponse, error) {
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -106,12 +107,12 @@ func (r *Client) GetExternalUserDetail(externalUserID string, nextCursor ...stri
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var result ExternalUserDetailResponse
|
result := &ExternalUserDetailResponse{}
|
||||||
err = util.DecodeWithError(response, &result, "get_external_user_detail")
|
err = util.DecodeWithError(response, result, "get_external_user_detail")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result.ExternalUser, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BatchGetExternalUserDetailsRequest 批量获取外部联系人详情请求
|
// BatchGetExternalUserDetailsRequest 批量获取外部联系人详情请求
|
||||||
@@ -161,6 +162,7 @@ type FollowInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BatchGetExternalUserDetails 批量获取外部联系人详情
|
// BatchGetExternalUserDetails 批量获取外部联系人详情
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/92994
|
||||||
func (r *Client) BatchGetExternalUserDetails(request BatchGetExternalUserDetailsRequest) ([]ExternalUserForBatch, error) {
|
func (r *Client) BatchGetExternalUserDetails(request BatchGetExternalUserDetailsRequest) ([]ExternalUserForBatch, error) {
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -195,6 +197,7 @@ type UpdateUserRemarkRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserRemark 修改客户备注信息
|
// UpdateUserRemark 修改客户备注信息
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/92115
|
||||||
func (r *Client) UpdateUserRemark(request UpdateUserRemarkRequest) error {
|
func (r *Client) UpdateUserRemark(request UpdateUserRemarkRequest) error {
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
143
work/externalcontact/groupchat.go
Normal file
143
work/externalcontact/groupchat.go
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
package externalcontact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OpengIDToChatIDURL 客户群opengid转换URL
|
||||||
|
const OpengIDToChatIDURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/opengid_to_chatid"
|
||||||
|
|
||||||
|
type (
|
||||||
|
//GroupChatListRequest 获取客户群列表的请求参数
|
||||||
|
GroupChatListRequest struct {
|
||||||
|
StatusFilter int `json:"status_filter"` // 非必填 客户群跟进状态过滤。0 - 所有列表(即不过滤) 1 - 离职待继承 2 - 离职继承中 3 - 离职继承完成
|
||||||
|
OwnerFilter OwnerFilter `json:"owner_filter"` //非必填 群主过滤。如果不填,表示获取应用可见范围内全部群主的数据(但是不建议这么用,如果可见范围人数超过1000人,为了防止数据包过大,会报错 81017)
|
||||||
|
Cursor string `json:"cursor"` //非必填 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用不填
|
||||||
|
Limit int `json:"limit"` //必填 分页,预期请求的数据量,取值范围 1 ~ 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
//GroupChatList 客户群列表
|
||||||
|
GroupChatList struct {
|
||||||
|
ChatID string `json:"chat_id"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
}
|
||||||
|
//GroupChatListResponse 获取客户群列表的返回值
|
||||||
|
GroupChatListResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
GroupChatList []GroupChatList `json:"group_chat_list"`
|
||||||
|
NextCursor string `json:"next_cursor"` //游标
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetGroupChatList 获取客户群列表
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/92120
|
||||||
|
func (r *Client) GetGroupChatList(req *GroupChatListRequest) (*GroupChatListResponse, error) {
|
||||||
|
accessToken, err := r.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var response []byte
|
||||||
|
response, err = util.PostJSON(fmt.Sprintf("%s/list?access_token=%s", GroupChatURL, accessToken), req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &GroupChatListResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "GetGroupChatList"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
//GroupChatDetailRequest 客户群详情 请求参数
|
||||||
|
GroupChatDetailRequest struct {
|
||||||
|
ChatID string `json:"chat_id"`
|
||||||
|
NeedName int `json:"need_name"`
|
||||||
|
}
|
||||||
|
//Invitor 邀请者
|
||||||
|
Invitor struct {
|
||||||
|
UserID string `json:"userid"` //邀请者的userid
|
||||||
|
}
|
||||||
|
//GroupChatMember 群成员
|
||||||
|
GroupChatMember struct {
|
||||||
|
UserID string `json:"userid"` //群成员id
|
||||||
|
Type int `json:"type"` //成员类型。 1 - 企业成员 2 - 外部联系人
|
||||||
|
JoinTime int `json:"join_time"` //入群时间
|
||||||
|
JoinScene int `json:"join_scene"` //入群方式 1 - 由群成员邀请入群(直接邀请入群) 2 - 由群成员邀请入群(通过邀请链接入群) 3 - 通过扫描群二维码入群
|
||||||
|
Invitor Invitor `json:"invitor,omitempty"` //邀请者。目前仅当是由本企业内部成员邀请入群时会返回该值
|
||||||
|
GroupNickname string `json:"group_nickname"` //在群里的昵称
|
||||||
|
Name string `json:"name"` //名字。仅当 need_name = 1 时返回 如果是微信用户,则返回其在微信中设置的名字 如果是企业微信联系人,则返回其设置对外展示的别名或实名
|
||||||
|
UnionID string `json:"unionid,omitempty"` //外部联系人在微信开放平台的唯一身份标识(微信unionid),通过此字段企业可将外部联系人与公众号/小程序用户关联起来。仅当群成员类型是微信用户(包括企业成员未添加好友),且企业绑定了微信开发者ID有此字段(查看绑定方法)。第三方不可获取,上游企业不可获取下游企业客户的unionid字段
|
||||||
|
}
|
||||||
|
//GroupChatAdmin 群管理员
|
||||||
|
GroupChatAdmin struct {
|
||||||
|
UserID string `json:"userid"` //群管理员userid
|
||||||
|
}
|
||||||
|
//GroupChat 客户群详情
|
||||||
|
GroupChat struct {
|
||||||
|
ChatID string `json:"chat_id"` //客户群ID
|
||||||
|
Name string `json:"name"` //群名
|
||||||
|
Owner string `json:"owner"` //群主ID
|
||||||
|
CreateTime int `json:"create_time"` //群的创建时间
|
||||||
|
Notice string `json:"notice"` //群公告
|
||||||
|
MemberList []GroupChatMember `json:"member_list"` //群成员列表
|
||||||
|
AdminList []GroupChatAdmin `json:"admin_list"` //群管理员列表
|
||||||
|
}
|
||||||
|
//GroupChatDetailResponse 客户群详情 返回值
|
||||||
|
GroupChatDetailResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
GroupChat GroupChat `json:"group_chat"` //客户群详情
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetGroupChatDetail 获取客户群详情
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/92122
|
||||||
|
func (r *Client) GetGroupChatDetail(req *GroupChatDetailRequest) (*GroupChatDetailResponse, error) {
|
||||||
|
accessToken, err := r.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var response []byte
|
||||||
|
response, err = util.PostJSON(fmt.Sprintf("%s/get?access_token=%s", GroupChatURL, accessToken), req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &GroupChatDetailResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "GetGroupChatDetail"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
//OpengIDToChatIDRequest 客户群opengid转换 请求参数
|
||||||
|
OpengIDToChatIDRequest struct {
|
||||||
|
OpengID string `json:"opengid"`
|
||||||
|
}
|
||||||
|
//OpengIDToChatIDResponse 客户群opengid转换 返回值
|
||||||
|
OpengIDToChatIDResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
ChatID string `json:"chat_id"` //客户群ID
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// OpengIDToChatID 客户群opengid转换
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/94828
|
||||||
|
func (r *Client) OpengIDToChatID(req *OpengIDToChatIDRequest) (*OpengIDToChatIDResponse, error) {
|
||||||
|
accessToken, err := r.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var response []byte
|
||||||
|
response, err = util.PostJSON(fmt.Sprintf("%s?access_token=%s", OpengIDToChatIDURL, accessToken), req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &OpengIDToChatIDResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "GetGroupChatDetail"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
146
work/externalcontact/join_way.go
Normal file
146
work/externalcontact/join_way.go
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package externalcontact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GroupChatURL 客户群
|
||||||
|
const GroupChatURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat"
|
||||||
|
|
||||||
|
type (
|
||||||
|
// AddJoinWayRequest 添加群配置请求参数
|
||||||
|
AddJoinWayRequest struct {
|
||||||
|
Scene int `json:"scene"` // 必填 1 - 群的小程序插件,2 - 群的二维码插件
|
||||||
|
Remark string `json:"remark"` //非必填 联系方式的备注信息,用于助记,超过30个字符将被截断
|
||||||
|
AutoCreateRoom int `json:"auto_create_room"` //非必填 当群满了后,是否自动新建群。0-否;1-是。 默认为1
|
||||||
|
RoomBaseName string `json:"room_base_name"` //非必填 自动建群的群名前缀,当auto_create_room为1时有效。最长40个utf8字符
|
||||||
|
RoomBaseID int `json:"room_base_id"` //非必填 自动建群的群起始序号,当auto_create_room为1时有效
|
||||||
|
ChatIDList []string `json:"chat_id_list"` //必填 使用该配置的客户群ID列表,支持5个。见客户群ID获取方法
|
||||||
|
State string `json:"state"` //非必填 企业自定义的state参数,用于区分不同的入群渠道。不超过30个UTF-8字符
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddJoinWayResponse 添加群配置返回值
|
||||||
|
AddJoinWayResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
ConfigID string `json:"config_id"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddJoinWay 加入群聊
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/92229
|
||||||
|
func (r *Client) AddJoinWay(req *AddJoinWayRequest) (*AddJoinWayResponse, error) {
|
||||||
|
var (
|
||||||
|
accessToken string
|
||||||
|
err error
|
||||||
|
response []byte
|
||||||
|
)
|
||||||
|
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response, err = util.PostJSON(fmt.Sprintf("%s/add_join_way?access_token=%s", GroupChatURL, accessToken), req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &AddJoinWayResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "AddJoinWay"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
//JoinWayConfigRequest 获取或删除群配置的请求参数
|
||||||
|
JoinWayConfigRequest struct {
|
||||||
|
ConfigID string `json:"config_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//JoinWay 群配置
|
||||||
|
JoinWay struct {
|
||||||
|
ConfigID string `json:"config_id"`
|
||||||
|
Scene int `json:"scene"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
AutoCreateRoom int `json:"auto_create_room"`
|
||||||
|
RoomBaseName string `json:"room_base_name"`
|
||||||
|
RoomBaseID int `json:"room_base_id"`
|
||||||
|
ChatIDList []string `json:"chat_id_list"`
|
||||||
|
QrCode string `json:"qr_code"`
|
||||||
|
State string `json:"state"`
|
||||||
|
}
|
||||||
|
//GetJoinWayResponse 获取群配置的返回值
|
||||||
|
GetJoinWayResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
JoinWay JoinWay `json:"join_way"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetJoinWay 获取客户群进群方式配置
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/92229
|
||||||
|
func (r *Client) GetJoinWay(req *JoinWayConfigRequest) (*GetJoinWayResponse, error) {
|
||||||
|
var (
|
||||||
|
accessToken string
|
||||||
|
err error
|
||||||
|
response []byte
|
||||||
|
)
|
||||||
|
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response, err = util.PostJSON(fmt.Sprintf("%s/get_join_way?access_token=%s", GroupChatURL, accessToken), req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &GetJoinWayResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "GetJoinWay"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateJoinWayRequest 更新群配置的请求参数
|
||||||
|
type UpdateJoinWayRequest struct {
|
||||||
|
ConfigID string `json:"config_id"`
|
||||||
|
Scene int `json:"scene"` // 必填 1 - 群的小程序插件,2 - 群的二维码插件
|
||||||
|
Remark string `json:"remark"` //非必填 联系方式的备注信息,用于助记,超过30个字符将被截断
|
||||||
|
AutoCreateRoom int `json:"auto_create_room"` //非必填 当群满了后,是否自动新建群。0-否;1-是。 默认为1
|
||||||
|
RoomBaseName string `json:"room_base_name"` //非必填 自动建群的群名前缀,当auto_create_room为1时有效。最长40个utf8字符
|
||||||
|
RoomBaseID int `json:"room_base_id"` //非必填 自动建群的群起始序号,当auto_create_room为1时有效
|
||||||
|
ChatIDList []string `json:"chat_id_list"` //必填 使用该配置的客户群ID列表,支持5个。见客户群ID获取方法
|
||||||
|
State string `json:"state"` //非必填 企业自定义的state参数,用于区分不同的入群渠道。不超过30个UTF-8字符
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateJoinWay 更新客户群进群方式配置
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/92229
|
||||||
|
func (r *Client) UpdateJoinWay(req *UpdateJoinWayRequest) error {
|
||||||
|
var (
|
||||||
|
accessToken string
|
||||||
|
err error
|
||||||
|
response []byte
|
||||||
|
)
|
||||||
|
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
response, err = util.PostJSON(fmt.Sprintf("%s/update_join_way?access_token=%s", GroupChatURL, accessToken), req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return util.DecodeWithCommonError(response, "UpdateJoinWay")
|
||||||
|
}
|
||||||
|
|
||||||
|
// DelJoinWay 删除客户群进群方式配置
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/92229
|
||||||
|
func (r *Client) DelJoinWay(req *JoinWayConfigRequest) error {
|
||||||
|
var (
|
||||||
|
accessToken string
|
||||||
|
err error
|
||||||
|
response []byte
|
||||||
|
)
|
||||||
|
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
response, err = util.PostJSON(fmt.Sprintf("%s/del_join_way?access_token=%s", GroupChatURL, accessToken), req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return util.DecodeWithCommonError(response, "DelJoinWay")
|
||||||
|
}
|
||||||
@@ -17,6 +17,14 @@ const (
|
|||||||
GetGroupMsgSendResultURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_send_result?access_token=%s"
|
GetGroupMsgSendResultURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_send_result?access_token=%s"
|
||||||
// SendWelcomeMsgURL 发送新客户欢迎语
|
// SendWelcomeMsgURL 发送新客户欢迎语
|
||||||
SendWelcomeMsgURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg?access_token=%s"
|
SendWelcomeMsgURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg?access_token=%s"
|
||||||
|
// AddGroupWelcomeTemplateURL 添加入群欢迎语素材
|
||||||
|
AddGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/add?access_token=%s"
|
||||||
|
// EditGroupWelcomeTemplateURL 编辑入群欢迎语素材
|
||||||
|
EditGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/edit?access_token=%s"
|
||||||
|
// GetGroupWelcomeTemplateURL 获取入群欢迎语素材
|
||||||
|
GetGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/get?access_token=%s"
|
||||||
|
// DelGroupWelcomeTemplateURL 删除入群欢迎语素材
|
||||||
|
DelGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/del?access_token=%s"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddMsgTemplateRequest 创建企业群发请求
|
// AddMsgTemplateRequest 创建企业群发请求
|
||||||
@@ -268,3 +276,149 @@ func (r *Client) SendWelcomeMsg(req *SendWelcomeMsgRequest) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddGroupWelcomeTemplateRequest 添加入群欢迎语素材请求
|
||||||
|
type AddGroupWelcomeTemplateRequest struct {
|
||||||
|
Text MsgText `json:"text"`
|
||||||
|
Image AttachmentImg `json:"image"`
|
||||||
|
Link AttachmentLink `json:"link"`
|
||||||
|
MiniProgram AttachmentMiniProgram `json:"miniprogram"`
|
||||||
|
File AttachmentFile `json:"file"`
|
||||||
|
Video AttachmentVideo `json:"video"`
|
||||||
|
AgentID int `json:"agentid"`
|
||||||
|
Notify int `json:"notify"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddGroupWelcomeTemplateResponse 添加入群欢迎语素材响应
|
||||||
|
type AddGroupWelcomeTemplateResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
TemplateID string `json:"template_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddGroupWelcomeTemplate 添加入群欢迎语素材
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/92366#%E6%B7%BB%E5%8A%A0%E5%85%A5%E7%BE%A4%E6%AC%A2%E8%BF%8E%E8%AF%AD%E7%B4%A0%E6%9D%90
|
||||||
|
func (r *Client) AddGroupWelcomeTemplate(req *AddGroupWelcomeTemplateRequest) (*AddGroupWelcomeTemplateResponse, 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(AddGroupWelcomeTemplateURL, accessToken), req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &AddGroupWelcomeTemplateResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "AddGroupWelcomeTemplate"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditGroupWelcomeTemplateRequest 编辑入群欢迎语素材请求
|
||||||
|
type EditGroupWelcomeTemplateRequest struct {
|
||||||
|
TemplateID string `json:"template_id"`
|
||||||
|
Text MsgText `json:"text"`
|
||||||
|
Image AttachmentImg `json:"image"`
|
||||||
|
Link AttachmentLink `json:"link"`
|
||||||
|
MiniProgram AttachmentMiniProgram `json:"miniprogram"`
|
||||||
|
File AttachmentFile `json:"file"`
|
||||||
|
Video AttachmentVideo `json:"video"`
|
||||||
|
AgentID int `json:"agentid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditGroupWelcomeTemplateResponse 编辑入群欢迎语素材响应
|
||||||
|
type EditGroupWelcomeTemplateResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditGroupWelcomeTemplate 编辑入群欢迎语素材
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/92366#%E7%BC%96%E8%BE%91%E5%85%A5%E7%BE%A4%E6%AC%A2%E8%BF%8E%E8%AF%AD%E7%B4%A0%E6%9D%90
|
||||||
|
func (r *Client) EditGroupWelcomeTemplate(req *EditGroupWelcomeTemplateRequest) error {
|
||||||
|
var (
|
||||||
|
accessToken string
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var response []byte
|
||||||
|
if response, err = util.PostJSON(fmt.Sprintf(EditGroupWelcomeTemplateURL, accessToken), req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
result := &EditGroupWelcomeTemplateResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "EditGroupWelcomeTemplate"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGroupWelcomeTemplateRequest 获取入群欢迎语素材请求
|
||||||
|
type GetGroupWelcomeTemplateRequest struct {
|
||||||
|
TemplateID string `json:"template_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGroupWelcomeTemplateResponse 获取入群欢迎语素材响应
|
||||||
|
type GetGroupWelcomeTemplateResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
Text MsgText `json:"text"`
|
||||||
|
Image AttachmentImg `json:"image"`
|
||||||
|
Link AttachmentLink `json:"link"`
|
||||||
|
MiniProgram AttachmentMiniProgram `json:"miniprogram"`
|
||||||
|
File AttachmentFile `json:"file"`
|
||||||
|
Video AttachmentVideo `json:"video"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGroupWelcomeTemplate 获取入群欢迎语素材
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/92366#%E8%8E%B7%E5%8F%96%E5%85%A5%E7%BE%A4%E6%AC%A2%E8%BF%8E%E8%AF%AD%E7%B4%A0%E6%9D%90
|
||||||
|
func (r *Client) GetGroupWelcomeTemplate(req *GetGroupWelcomeTemplateRequest) (*GetGroupWelcomeTemplateResponse, 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(GetGroupWelcomeTemplateURL, accessToken), req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &GetGroupWelcomeTemplateResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "GetGroupWelcomeTemplate"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DelGroupWelcomeTemplateRequest 删除入群欢迎语素材请求
|
||||||
|
type DelGroupWelcomeTemplateRequest struct {
|
||||||
|
TemplateID string `json:"template_id"`
|
||||||
|
AgentID int `json:"agentid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DelGroupWelcomeTemplateResponse 删除入群欢迎语素材响应
|
||||||
|
type DelGroupWelcomeTemplateResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
}
|
||||||
|
|
||||||
|
// DelGroupWelcomeTemplate 删除入群欢迎语素材
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/92366#%E5%88%A0%E9%99%A4%E5%85%A5%E7%BE%A4%E6%AC%A2%E8%BF%8E%E8%AF%AD%E7%B4%A0%E6%9D%90
|
||||||
|
func (r *Client) DelGroupWelcomeTemplate(req *DelGroupWelcomeTemplateRequest) error {
|
||||||
|
var (
|
||||||
|
accessToken string
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var response []byte
|
||||||
|
if response, err = util.PostJSON(fmt.Sprintf(DelGroupWelcomeTemplateURL, accessToken), req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
result := &DelGroupWelcomeTemplateResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "DelGroupWelcomeTemplate"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user