mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-23 13:42:25 +08:00
Compare commits
4 Commits
c5c5eb50e1
...
69ce11dd75
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69ce11dd75 | ||
|
|
06719f77b7 | ||
|
|
b70ecd93a7 | ||
|
|
de92dc0dcd |
60
openplatform/miniprogram/auth/auth.go
Normal file
60
openplatform/miniprogram/auth/auth.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
stdContext "context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/openplatform/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
code2SessionURL = "https://api.weixin.qq.com/sns/component/jscode2session?appid=%s&js_code=%s&grant_type=authorization_code&component_appid=%s&component_access_token=%s"
|
||||
)
|
||||
|
||||
// Auth 登录/用户信息
|
||||
type Auth struct {
|
||||
*context.Context
|
||||
authorizerAppID string
|
||||
}
|
||||
|
||||
// NewAuth new auth (授权方appID)
|
||||
func NewAuth(ctx *context.Context, appID string) *Auth {
|
||||
return &Auth{ctx, appID}
|
||||
}
|
||||
|
||||
// ResCode2Session 登录凭证校验的返回结果
|
||||
type ResCode2Session struct {
|
||||
util.CommonError
|
||||
OpenID string `json:"openid"` // 用户唯一标识
|
||||
SessionKey string `json:"session_key"` // 会话密钥
|
||||
UnionID string `json:"unionid"` // 用户在开放平台的唯一标识符,在满足UnionID下发条件的情况下会返回
|
||||
}
|
||||
|
||||
// Code2Session 登录凭证校验。
|
||||
func (auth *Auth) Code2Session(jsCode string) (result ResCode2Session, err error) {
|
||||
return auth.Code2SessionContext(stdContext.Background(), jsCode)
|
||||
}
|
||||
|
||||
// Code2SessionContext 登录凭证校验。
|
||||
func (auth *Auth) Code2SessionContext(ctx stdContext.Context, jsCode string) (result ResCode2Session, err error) {
|
||||
var response []byte
|
||||
var componentAccessToken string
|
||||
componentAccessToken, err = auth.GetComponentAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
parse := fmt.Sprintf(code2SessionURL, auth.authorizerAppID, jsCode, auth.Context.AppID, componentAccessToken)
|
||||
if response, err = util.HTTPGetContext(ctx, parse); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(response, &result); err != nil {
|
||||
return
|
||||
}
|
||||
if result.ErrCode != 0 {
|
||||
err = fmt.Errorf("Code2Session error : errcode=%v , errmsg=%v", result.ErrCode, result.ErrMsg)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
miniContext "github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/urllink"
|
||||
openContext "github.com/silenceper/wechat/v2/openplatform/context"
|
||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/auth"
|
||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/basic"
|
||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/component"
|
||||
)
|
||||
@@ -72,6 +73,11 @@ func (miniProgram *MiniProgram) GetURLLink() *urllink.URLLink {
|
||||
})
|
||||
}
|
||||
|
||||
// GetAuth 登录/用户信息相关接口
|
||||
func (miniProgram *MiniProgram) GetAuth() *auth.Auth {
|
||||
return auth.NewAuth(miniProgram.openContext, miniProgram.AppID)
|
||||
}
|
||||
|
||||
// DefaultAuthrAccessToken 默认获取授权ak的方法
|
||||
type DefaultAuthrAccessToken struct {
|
||||
opCtx *openContext.Context
|
||||
|
||||
@@ -25,6 +25,10 @@ const (
|
||||
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"
|
||||
// remindGroupMsgSendURL 提醒成员群发
|
||||
remindGroupMsgSendURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remind_groupmsg_send?access_token=%s"
|
||||
// cancelGroupMsgSendURL 停止企业群发
|
||||
cancelGroupMsgSendURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/cancel_groupmsg_send?access_token=%s"
|
||||
)
|
||||
|
||||
// AddMsgTemplateRequest 创建企业群发请求
|
||||
@@ -422,3 +426,47 @@ func (r *Client) DelGroupWelcomeTemplate(req *DelGroupWelcomeTemplateRequest) er
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemindGroupMsgSendRequest 提醒成员群发请求
|
||||
type RemindGroupMsgSendRequest struct {
|
||||
MsgID string `json:"msgid"`
|
||||
}
|
||||
|
||||
// RemindGroupMsgSend 提醒成员群发
|
||||
// see https://developer.work.weixin.qq.com/document/path/97610
|
||||
func (r *Client) RemindGroupMsgSend(req *RemindGroupMsgSendRequest) 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(remindGroupMsgSendURL, accessToken), req); err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "RemindGroupMsgSend")
|
||||
}
|
||||
|
||||
// CancelGroupMsgSendRequest 停止企业群发请求
|
||||
type CancelGroupMsgSendRequest struct {
|
||||
MsgID string `json:"msgid"`
|
||||
}
|
||||
|
||||
// CancelGroupMsgSend 提醒成员群发
|
||||
// see https://developer.work.weixin.qq.com/document/path/97611
|
||||
func (r *Client) CancelGroupMsgSend(req *CancelGroupMsgSendRequest) 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(cancelGroupMsgSendURL, accessToken), req); err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "CancelGroupMsgSend")
|
||||
}
|
||||
|
||||
127
work/kf/statistic.go
Normal file
127
work/kf/statistic.go
Normal file
@@ -0,0 +1,127 @@
|
||||
package kf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// getCorpStatisticURL 获取「客户数据统计」企业汇总数据
|
||||
getCorpStatisticURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/get_corp_statistic?access_token=%s"
|
||||
// getServicerStatisticURL 获取「客户数据统计」接待人员明细数据
|
||||
getServicerStatisticURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/get_servicer_statistic?access_token=%s"
|
||||
)
|
||||
|
||||
// GetCorpStatisticRequest 获取「客户数据统计」企业汇总数据请求
|
||||
type GetCorpStatisticRequest struct {
|
||||
OpenKfID string `json:"open_kfid"`
|
||||
StartTime int64 `json:"start_time"`
|
||||
EndTime int64 `json:"end_time"`
|
||||
}
|
||||
|
||||
// GetCorpStatisticResponse 获取「客户数据统计」企业汇总数据响应
|
||||
type GetCorpStatisticResponse struct {
|
||||
util.CommonError
|
||||
StatisticList []CorpStatisticList `json:"statistic_list"`
|
||||
}
|
||||
|
||||
// CorpStatisticList 企业汇总统计数据列表
|
||||
type CorpStatisticList struct {
|
||||
StatTime int64 `json:"stat_time"`
|
||||
Statistic CorpStatistic `json:"statistic"`
|
||||
}
|
||||
|
||||
// CorpStatistic 企业汇总统计一天的统计数据
|
||||
type CorpStatistic struct {
|
||||
SessionCnt int64 `json:"session_cnt"`
|
||||
CustomerCnt int64 `json:"customer_cnt"`
|
||||
CustomerMsgCnt int64 `json:"customer_msg_cnt"`
|
||||
UpgradeServiceCustomerCnt int64 `json:"upgrade_service_customer_cnt"`
|
||||
AiSessionReplyCnt int64 `json:"ai_session_reply_cnt"`
|
||||
AiTransferRate float64 `json:"ai_transfer_rate"`
|
||||
AiKnowledgeHitRate float64 `json:"ai_knowledge_hit_rate"`
|
||||
MsgRejectedCustomerCnt int64 `json:"msg_rejected_customer_cnt"`
|
||||
}
|
||||
|
||||
// GetCorpStatistic 获取「客户数据统计」企业汇总数据
|
||||
// see https://developer.work.weixin.qq.com/document/path/95489
|
||||
func (r *Client) GetCorpStatistic(req *GetCorpStatisticRequest) (*GetCorpStatisticResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(getCorpStatisticURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetCorpStatisticResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetCorpStatistic"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetServicerStatisticRequest 获取「客户数据统计」接待人员明细数据请求
|
||||
type GetServicerStatisticRequest struct {
|
||||
OpenKfID string `json:"open_kfid"`
|
||||
ServicerUserID string `json:"servicer_userid"`
|
||||
StartTime int64 `json:"start_time"`
|
||||
EndTime int64 `json:"end_time"`
|
||||
}
|
||||
|
||||
// GetServicerStatisticResponse 获取「客户数据统计」接待人员明细数据响应
|
||||
type GetServicerStatisticResponse struct {
|
||||
util.CommonError
|
||||
StatisticList []ServicerStatisticList `json:"statistic_list"`
|
||||
}
|
||||
|
||||
// ServicerStatisticList 接待人员明细统计数据列表
|
||||
type ServicerStatisticList struct {
|
||||
StatTime int64 `json:"stat_time"`
|
||||
Statistic ServicerStatistic `json:"statistic"`
|
||||
}
|
||||
|
||||
// ServicerStatistic 接待人员明细统计一天的统计数据
|
||||
type ServicerStatistic struct {
|
||||
SessionCnt int64 `json:"session_cnt"`
|
||||
CustomerCnt int64 `json:"customer_cnt"`
|
||||
CustomerMsgCnt int64 `json:"customer_msg_cnt"`
|
||||
ReplyRate float64 `json:"reply_rate"`
|
||||
FirstReplyAverageSec float64 `json:"first_reply_average_sec"`
|
||||
SatisfactionInvestgateCnt int64 `json:"satisfaction_investgate_cnt"`
|
||||
SatisfactionParticipationRate float64 `json:"satisfaction_participation_rate"`
|
||||
SatisfiedRate float64 `json:"satisfied_rate"`
|
||||
MiddlingRate float64 `json:"middling_rate"`
|
||||
DissatisfiedRate float64 `json:"dissatisfied_rate"`
|
||||
UpgradeServiceCustomerCnt int64 `json:"upgrade_service_customer_cnt"`
|
||||
UpgradeServiceMemberInviteCnt int64 `json:"upgrade_service_member_invite_cnt"`
|
||||
UpgradeServiceMemberCustomerCnt int64 `json:"upgrade_service_member_customer_cnt"`
|
||||
UpgradeServiceGroupChatInviteCnt int64 `json:"upgrade_service_groupchat_invite_cnt"`
|
||||
UpgradeServiceGroupChatCustomerCnt int64 `json:"upgrade_service_groupchat_customer_cnt"`
|
||||
MsgRejectedCustomerCnt int64 `json:"msg_rejected_customer_cnt"`
|
||||
}
|
||||
|
||||
// GetServicerStatistic 获取「客户数据统计」接待人员明细数据
|
||||
// see https://developer.work.weixin.qq.com/document/path/95490
|
||||
func (r *Client) GetServicerStatistic(req *GetServicerStatisticRequest) (*GetServicerStatisticResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(getServicerStatisticURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetServicerStatisticResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetServicerStatistic"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user