-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
增加[企业微信-客户联系-统计管理]相关接口 #598
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
package externalcontact | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/silenceper/wechat/v2/util" | ||
) | ||
|
||
const ( | ||
// GetUserBehaviorDataURL 获取「联系客户统计」数据 | ||
GetUserBehaviorDataURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_user_behavior_data" | ||
// GetGroupChatStatURL 获取「群聊数据统计」数据 按群主聚合的方式 | ||
GetGroupChatStatURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/statistic" | ||
// GetGroupChatStatByDayURL 获取「群聊数据统计」数据 按自然日聚合的方式 | ||
GetGroupChatStatByDayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/statistic_group_by_day" | ||
) | ||
|
||
type ( | ||
// GetUserBehaviorRequest 获取「联系客户统计」数据请求 | ||
GetUserBehaviorRequest struct { | ||
UserID []string `json:"userid"` | ||
PartyID []int `json:"partyid"` | ||
StartTime int `json:"start_time"` | ||
EndTime int `json:"end_time"` | ||
} | ||
// GetUserBehaviorResponse 获取「联系客户统计」数据响应 | ||
GetUserBehaviorResponse struct { | ||
util.CommonError | ||
BehaviorData []BehaviorData `json:"behavior_data"` | ||
} | ||
// BehaviorData 联系客户统计数据 | ||
BehaviorData struct { | ||
StatTime int `json:"stat_time"` | ||
ChatCnt int `json:"chat_cnt"` | ||
MessageCnt int `json:"message_cnt"` | ||
ReplyPercentage float64 `json:"reply_percentage"` | ||
AvgReplyTime int `json:"avg_reply_time"` | ||
NegativeFeedbackCnt int `json:"negative_feedback_cnt"` | ||
NewApplyCnt int `json:"new_apply_cnt"` | ||
NewContactCnt int `json:"new_contact_cnt"` | ||
} | ||
) | ||
|
||
// GetUserBehaviorData 获取「联系客户统计」数据 | ||
// @see https://developer.work.weixin.qq.com/document/path/92132 | ||
func (r *Client) GetUserBehaviorData(req *GetUserBehaviorRequest) ([]BehaviorData, error) { | ||
accessToken, err := r.GetAccessToken() | ||
if err != nil { | ||
return nil, err | ||
} | ||
var response []byte | ||
jsonData, err := json.Marshal(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", GetUserBehaviorDataURL, accessToken), string(jsonData)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var result GetUserBehaviorResponse | ||
err = util.DecodeWithError(response, &result, "GetUserBehaviorData") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return result.BehaviorData, nil | ||
} | ||
|
||
type ( | ||
// GetGroupChatStatRequest 获取「群聊数据统计」数据 按群主聚合的方式 请求 | ||
GetGroupChatStatRequest struct { | ||
DayBeginTime int `json:"day_begin_time"` | ||
DayEndTime int `json:"day_end_time"` | ||
OwnerFilter OwnerFilter `json:"owner_filter"` | ||
OrderBy int `json:"order_by"` | ||
OrderAsc int `json:"order_asc"` | ||
Offset int `json:"offset"` | ||
Limit int `json:"limit"` | ||
} | ||
// GetGroupChatStatResponse 获取「群聊数据统计」数据 按群主聚合的方式 响应 | ||
GetGroupChatStatResponse struct { | ||
util.CommonError | ||
Total int `json:"total"` | ||
NextOffset int `json:"next_offset"` | ||
Items []GroupChatStatItem `json:"items"` | ||
} | ||
// GroupChatStatItem 群聊数据统计(按群主聚合)条目 | ||
GroupChatStatItem struct { | ||
Owner string `json:"owner"` | ||
Data GroupChatStatItemData `json:"data"` | ||
} | ||
) | ||
|
||
// OwnerFilter 群主过滤 | ||
type OwnerFilter struct { | ||
UseridList []string `json:"userid_list"` | ||
} | ||
|
||
// GroupChatStatItemData 群聊数据统计条目数据 | ||
type GroupChatStatItemData struct { | ||
NewChatCnt int `json:"new_chat_cnt"` | ||
ChatTotal int `json:"chat_total"` | ||
ChatHasMsg int `json:"chat_has_msg"` | ||
NewMemberCnt int `json:"new_member_cnt"` | ||
MemberTotal int `json:"member_total"` | ||
MemberHasMsg int `json:"member_has_msg"` | ||
MsgTotal int `json:"msg_total"` | ||
MigrateTraineeChatCnt int `json:"migrate_trainee_chat_cnt"` | ||
} | ||
|
||
// GetGroupChatStat 获取「群聊数据统计」数据 按群主聚合的方式 | ||
// @see https://developer.work.weixin.qq.com/document/path/92133 | ||
func (r *Client) GetGroupChatStat(req *GetGroupChatStatRequest) (*GetGroupChatStatResponse, error) { | ||
accessToken, err := r.GetAccessToken() | ||
if err != nil { | ||
return nil, err | ||
} | ||
var response []byte | ||
jsonData, err := json.Marshal(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", GetGroupChatStatURL, accessToken), string(jsonData)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
result := &GetGroupChatStatResponse{} | ||
err = util.DecodeWithError(response, result, "GetGroupChatStat") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return result, nil | ||
} | ||
|
||
type ( | ||
// GetGroupChatStatByDayRequest 获取「群聊数据统计」数据 按自然日聚合的方式 请求 | ||
GetGroupChatStatByDayRequest struct { | ||
DayBeginTime int `json:"day_begin_time"` | ||
DayEndTime int `json:"day_end_time"` | ||
OwnerFilter OwnerFilter `json:"owner_filter"` | ||
} | ||
// GetGroupChatStatByDayResponse 获取「群聊数据统计」数据 按自然日聚合的方式 响应 | ||
GetGroupChatStatByDayResponse struct { | ||
util.CommonError | ||
Items []GetGroupChatStatByDayItem `json:"items"` | ||
} | ||
// GetGroupChatStatByDayItem 群聊数据统计(按自然日聚合)条目 | ||
GetGroupChatStatByDayItem struct { | ||
StatTime int `json:"stat_time"` | ||
Data GroupChatStatItemData `json:"data"` | ||
} | ||
) | ||
|
||
// GetGroupChatStatByDay 获取「群聊数据统计」数据 按自然日聚合的方式 | ||
// @see https://developer.work.weixin.qq.com/document/path/92133 | ||
func (r *Client) GetGroupChatStatByDay(req *GetGroupChatStatByDayRequest) ([]GetGroupChatStatByDayItem, error) { | ||
accessToken, err := r.GetAccessToken() | ||
if err != nil { | ||
return nil, err | ||
} | ||
var response []byte | ||
jsonData, err := json.Marshal(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", GetGroupChatStatByDayURL, accessToken), string(jsonData)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var result GetGroupChatStatByDayResponse | ||
err = util.DecodeWithError(response, &result, "GetGroupChatStatByDay") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return result.Items, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
发现这个地址也是无法访问,提示参数异常