mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-23 13:42:25 +08:00
Compare commits
5 Commits
c5c5eb50e1
...
feature/au
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1cee8868e | ||
|
|
aa1afc5a35 | ||
|
|
9e810be88a | ||
|
|
06719f77b7 | ||
|
|
b70ecd93a7 |
@@ -15,6 +15,8 @@ const (
|
||||
checkEncryptedDataURL = "https://api.weixin.qq.com/wxa/business/checkencryptedmsg?access_token=%s"
|
||||
|
||||
getPhoneNumber = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s"
|
||||
|
||||
checkSessionURL = "https://api.weixin.qq.com/wxa/checksession?access_token=%s&openid=%s&signature=%s&sig_method=hmac_sha256"
|
||||
)
|
||||
|
||||
// Auth 登录/用户信息
|
||||
@@ -33,7 +35,7 @@ type ResCode2Session struct {
|
||||
|
||||
OpenID string `json:"openid"` // 用户唯一标识
|
||||
SessionKey string `json:"session_key"` // 会话密钥
|
||||
UnionID string `json:"unionid"` // 用户在开放平台的唯一标识符,在满足UnionID下发条件的情况下会返回
|
||||
UnionID string `json:"unionid"` // 用户在开放平台的唯一标识符,在满足 UnionID 下发条件的情况下会返回
|
||||
}
|
||||
|
||||
// RspCheckEncryptedData .
|
||||
@@ -70,12 +72,12 @@ func (auth *Auth) GetPaidUnionID() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// CheckEncryptedData .检查加密信息是否由微信生成(当前只支持手机号加密数据),只能检测最近3天生成的加密数据
|
||||
// CheckEncryptedData .检查加密信息是否由微信生成(当前只支持手机号加密数据),只能检测最近 3 天生成的加密数据
|
||||
func (auth *Auth) CheckEncryptedData(encryptedMsgHash string) (result RspCheckEncryptedData, err error) {
|
||||
return auth.CheckEncryptedDataContext(context2.Background(), encryptedMsgHash)
|
||||
}
|
||||
|
||||
// CheckEncryptedDataContext .检查加密信息是否由微信生成(当前只支持手机号加密数据),只能检测最近3天生成的加密数据
|
||||
// CheckEncryptedDataContext .检查加密信息是否由微信生成(当前只支持手机号加密数据),只能检测最近 3 天生成的加密数据
|
||||
func (auth *Auth) CheckEncryptedDataContext(ctx context2.Context, encryptedMsgHash string) (result RspCheckEncryptedData, err error) {
|
||||
var response []byte
|
||||
var (
|
||||
@@ -85,7 +87,7 @@ func (auth *Auth) CheckEncryptedDataContext(ctx context2.Context, encryptedMsgHa
|
||||
return
|
||||
}
|
||||
|
||||
// 由于GetPhoneNumberContext需要传入JSON,所以HTTPPostContext入参改为[]byte
|
||||
// 由于 GetPhoneNumberContext 需要传入 JSON,所以 HTTPPostContext 入参改为 []byte
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(checkEncryptedDataURL, at), []byte("encrypted_msg_hash="+encryptedMsgHash), nil); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -113,38 +115,62 @@ type PhoneInfo struct {
|
||||
} `json:"watermark"` // 数据水印
|
||||
}
|
||||
|
||||
// GetPhoneNumberContext 小程序通过code获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (*GetPhoneNumberResponse, error) {
|
||||
var response []byte
|
||||
var (
|
||||
at string
|
||||
err error
|
||||
)
|
||||
if at, err = auth.GetAccessToken(); err != nil {
|
||||
// GetPhoneNumberContext 小程序通过 code 获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (result *GetPhoneNumberResponse, err error) {
|
||||
var accessToken string
|
||||
if accessToken, err = auth.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body := map[string]interface{}{
|
||||
"code": code,
|
||||
}
|
||||
|
||||
bodyBytes, err := json.Marshal(body)
|
||||
bodyBytes, err := json.Marshal(map[string]interface{}{
|
||||
"code": code,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
header := map[string]string{"Content-Type": "application/json;charset=utf-8"}
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(getPhoneNumber, at), bodyBytes, header); err != nil {
|
||||
var (
|
||||
header = map[string]string{"Content-Type": "application/json;charset=utf-8"}
|
||||
response []byte
|
||||
)
|
||||
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(getPhoneNumber, accessToken), bodyBytes, header); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result GetPhoneNumberResponse
|
||||
if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber")
|
||||
return
|
||||
}
|
||||
|
||||
// GetPhoneNumber 小程序通过code获取用户手机号
|
||||
// GetPhoneNumber 小程序通过 code 获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
||||
return auth.GetPhoneNumberContext(context2.Background(), code)
|
||||
}
|
||||
|
||||
// // CheckSession 检验登录态是否过期。
|
||||
// func (auth *Auth) CheckSession(sessionKey, openID string) (result *CheckSessionResponse, err error) {
|
||||
// return auth.CheckSessionContext(context2.Background(), sessionKey, openID)
|
||||
// }
|
||||
//
|
||||
// // CheckSessionContext 检验登录态是否过期。
|
||||
// func (auth *Auth) CheckSessionContext(ctx context2.Context, sessionKey, openID string) (result *CheckSessionResponse, err error) {
|
||||
// var accessToken string
|
||||
// if accessToken, err = auth.GetAccessToken(); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// var (
|
||||
// response []byte
|
||||
// signature string = sessionKey
|
||||
// )
|
||||
// if response, err = util.HTTPGetContext(ctx, fmt.Sprintf(checkSessionURL, accessToken, openID, signature)); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// err = util.DecodeWithError(response, &result, "CheckSessionContext")
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // CheckSessionResponse 检验登录态是否过期。
|
||||
// type CheckSessionResponse struct {
|
||||
// util.CommonError
|
||||
// }
|
||||
|
||||
@@ -117,6 +117,24 @@ const (
|
||||
|
||||
// queryPublishGoods 查询批量发布道具任务状态
|
||||
queryPublishGoods = "/xpay/query_publish_goods"
|
||||
|
||||
// queryBizBalance 查询商家账户里的可提现余额
|
||||
queryBizBalance = "/xpay/query_biz_balance"
|
||||
|
||||
// queryTransferAccount 查询广告金充值账户
|
||||
queryTransferAccount = "/xpay/query_transfer_account"
|
||||
|
||||
// queryAdverFunds 查询广告金发放记录
|
||||
queryAdverFunds = "/xpay/query_adver_funds"
|
||||
|
||||
// createFundsBill 充值广告金
|
||||
createFundsBill = "/xpay/create_funds_bill"
|
||||
|
||||
// bindTransferAccount 绑定广告金充值账户
|
||||
bindTransferAccount = "/xpay/bind_transfer_accout"
|
||||
|
||||
// defaultUnifiedOrderURL default unified order url
|
||||
defaultUnifiedOrderURL = "requestVirtualPayment"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -145,6 +145,8 @@ type OrderItem struct {
|
||||
WxOrderID string `json:"wx_order_id"` // 微信内部单号
|
||||
ChannelOrderID string `json:"channel_order_id"` // 渠道订单号,为用户微信支付详情页面上的商户单号
|
||||
WxPayOrderID string `json:"wxpay_order_id"` // 微信支付交易单号,为用户微信支付详情页面上的交易单号
|
||||
SettTime int64 `json:"sett_time"` // 结算时间,unix 秒级时间戳,结算时间的秒级时间戳,大于 0 表示结算成功
|
||||
SettState uint `json:"sett_state"` // 结算状态 0-未开始结算 1-结算中 2-结算成功
|
||||
}
|
||||
|
||||
// QueryOrderResponse 查询创建的订单(现金单,非代币单)响应参数
|
||||
|
||||
@@ -479,6 +479,7 @@ func (s *VirtualPayment) requestAddress(params URLParams) (url string, err error
|
||||
case queryUserBalance:
|
||||
case currencyPay:
|
||||
case cancelCurrencyPay:
|
||||
case defaultUnifiedOrderURL:
|
||||
if params.PaySign, params.Signature, err = s.PaySignature(params.Path, params.Content); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
359
work/kf/knowledge.go
Normal file
359
work/kf/knowledge.go
Normal file
@@ -0,0 +1,359 @@
|
||||
package kf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// addKnowledgeGroupURL 知识库分组添加
|
||||
addKnowledgeGroupURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/knowledge/add_group?access_token=%s"
|
||||
// delKnowledgeGroupURL 知识库分组删除
|
||||
delKnowledgeGroupURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/knowledge/del_group?access_token=%s"
|
||||
// modKnowledgeGroupURL 知识库分组修改
|
||||
modKnowledgeGroupURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/knowledge/mod_group?access_token=%s"
|
||||
// listKnowledgeGroupURL 知识库分组列表
|
||||
listKnowledgeGroupURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/knowledge/list_group?access_token=%s"
|
||||
// addKnowledgeIntentURL 知识库问答添加
|
||||
addKnowledgeIntentURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/knowledge/add_intent?access_token=%s"
|
||||
// delKnowledgeIntentURL 知识库问答删除
|
||||
delKnowledgeIntentURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/knowledge/del_intent?access_token=%s"
|
||||
// modKnowledgeIntentURL 知识库问答修改
|
||||
modKnowledgeIntentURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/knowledge/mod_intent?access_token=%s"
|
||||
// listKnowledgeIntentURL 知识库问答列表
|
||||
listKnowledgeIntentURL = "https://qyapi.weixin.qq.com/cgi-bin/kf/knowledge/list_intent?access_token=%s"
|
||||
)
|
||||
|
||||
// AddKnowledgeGroupRequest 知识库分组添加请求
|
||||
type AddKnowledgeGroupRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// AddKnowledgeGroupResponse 知识库分组添加响应
|
||||
type AddKnowledgeGroupResponse struct {
|
||||
util.CommonError
|
||||
GroupID string `json:"group_id"`
|
||||
}
|
||||
|
||||
// AddKnowledgeGroup 知识库分组添加
|
||||
// see https://developer.work.weixin.qq.com/document/path/95971#%E6%B7%BB%E5%8A%A0%E5%88%86%E7%BB%84
|
||||
func (r *Client) AddKnowledgeGroup(req *AddKnowledgeGroupRequest) (*AddKnowledgeGroupResponse, 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(addKnowledgeGroupURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &AddKnowledgeGroupResponse{}
|
||||
err = util.DecodeWithError(response, result, "AddKnowledgeGroup")
|
||||
return result, err
|
||||
}
|
||||
|
||||
// DelKnowledgeGroupRequest 知识库分组删除请求
|
||||
type DelKnowledgeGroupRequest struct {
|
||||
GroupID string `json:"group_id"`
|
||||
}
|
||||
|
||||
// DelKnowledgeGroup 知识库分组删除
|
||||
// see https://developer.work.weixin.qq.com/document/path/95971#%E5%88%A0%E9%99%A4%E5%88%86%E7%BB%84
|
||||
func (r *Client) DelKnowledgeGroup(req *DelKnowledgeGroupRequest) error {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(delKnowledgeGroupURL, accessToken), req); err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "DelKnowledgeGroup")
|
||||
}
|
||||
|
||||
// ModKnowledgeGroupRequest 知识库分组修改请求
|
||||
type ModKnowledgeGroupRequest struct {
|
||||
GroupID string `json:"group_id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// ModKnowledgeGroup 知识库分组修改
|
||||
// see https://developer.work.weixin.qq.com/document/path/95971#%E4%BF%AE%E6%94%B9%E5%88%86%E7%BB%84
|
||||
func (r *Client) ModKnowledgeGroup(req *ModKnowledgeGroupRequest) error {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(modKnowledgeGroupURL, accessToken), req); err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "ModKnowledgeGroup")
|
||||
}
|
||||
|
||||
// ListKnowledgeGroupRequest 知识库分组列表请求
|
||||
type ListKnowledgeGroupRequest struct {
|
||||
Cursor string `json:"cursor"`
|
||||
Limit int `json:"limit"`
|
||||
GroupID string `json:"group_id"`
|
||||
}
|
||||
|
||||
// ListKnowledgeGroupResponse 知识库分组列表响应
|
||||
type ListKnowledgeGroupResponse struct {
|
||||
util.CommonError
|
||||
NextCursor string `json:"next_cursor"`
|
||||
HasMore int `json:"has_more"`
|
||||
GroupList []KnowledgeGroup `json:"group_list"`
|
||||
}
|
||||
|
||||
// KnowledgeGroup 知识库分组
|
||||
type KnowledgeGroup struct {
|
||||
GroupID string `json:"group_id"`
|
||||
Name string `json:"name"`
|
||||
IsDefault int `json:"is_default"`
|
||||
}
|
||||
|
||||
// ListKnowledgeGroup 知识库分组列表
|
||||
// see https://developer.work.weixin.qq.com/document/path/95971#%E8%8E%B7%E5%8F%96%E5%88%86%E7%BB%84%E5%88%97%E8%A1%A8
|
||||
func (r *Client) ListKnowledgeGroup(req *ListKnowledgeGroupRequest) (*ListKnowledgeGroupResponse, 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(listKnowledgeGroupURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &ListKnowledgeGroupResponse{}
|
||||
err = util.DecodeWithError(response, result, "ListKnowledgeGroup")
|
||||
return result, err
|
||||
}
|
||||
|
||||
// AddKnowledgeIntentRequest 知识库问答添加请求
|
||||
type AddKnowledgeIntentRequest struct {
|
||||
GroupID string `json:"group_id"`
|
||||
Question IntentQuestion `json:"question"`
|
||||
SimilarQuestions IntentSimilarQuestions `json:"similar_questions"`
|
||||
Answers []IntentAnswerReq `json:"answers"`
|
||||
}
|
||||
|
||||
// IntentQuestion 主问题
|
||||
type IntentQuestion struct {
|
||||
Text IntentQuestionText `json:"text"`
|
||||
}
|
||||
|
||||
// IntentQuestionText 问题文本
|
||||
type IntentQuestionText struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// IntentSimilarQuestions 相似问题
|
||||
type IntentSimilarQuestions struct {
|
||||
Items []IntentQuestion `json:"items"`
|
||||
}
|
||||
|
||||
// IntentAnswerReq 回答请求
|
||||
type IntentAnswerReq struct {
|
||||
Text IntentAnswerText `json:"text"`
|
||||
Attachments []IntentAnswerAttachmentReq `json:"attachments"`
|
||||
}
|
||||
|
||||
// IntentAnswerText 回答文本
|
||||
type IntentAnswerText struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// IntentAnswerAttachmentReq 回答附件请求
|
||||
type IntentAnswerAttachmentReq struct {
|
||||
MsgType string `json:"msgtype"`
|
||||
Image IntentAnswerAttachmentImgReq `json:"image,omitempty"`
|
||||
Video IntentAnswerAttachmentVideoReq `json:"video,omitempty"`
|
||||
Link IntentAnswerAttachmentLink `json:"link,omitempty"`
|
||||
MiniProgram IntentAnswerAttachmentMiniProgramReq `json:"miniprogram,omitempty"`
|
||||
}
|
||||
|
||||
// IntentAnswerAttachmentImgReq 图片类型回答附件请求
|
||||
type IntentAnswerAttachmentImgReq struct {
|
||||
MediaID string `json:"media_id"`
|
||||
}
|
||||
|
||||
// IntentAnswerAttachmentVideoReq 视频类型回答附件请求
|
||||
type IntentAnswerAttachmentVideoReq struct {
|
||||
MediaID string `json:"media_id"`
|
||||
}
|
||||
|
||||
// IntentAnswerAttachmentLink 链接类型回答附件
|
||||
type IntentAnswerAttachmentLink struct {
|
||||
Title string `json:"title"`
|
||||
PicURL string `json:"picurl"`
|
||||
Desc string `json:"desc"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// IntentAnswerAttachmentMiniProgramReq 小程序类型回答附件请求
|
||||
type IntentAnswerAttachmentMiniProgramReq struct {
|
||||
Title string `json:"title"`
|
||||
ThumbMediaID string `json:"thumb_media_id"`
|
||||
AppID string `json:"appid"`
|
||||
PagePath string `json:"pagepath"`
|
||||
}
|
||||
|
||||
// AddKnowledgeIntentResponse 知识库问答添加响应
|
||||
type AddKnowledgeIntentResponse struct {
|
||||
util.CommonError
|
||||
IntentID string `json:"intent_id"`
|
||||
}
|
||||
|
||||
// AddKnowledgeIntent 知识库问答添加
|
||||
// see https://developer.work.weixin.qq.com/document/path/95972#%E6%B7%BB%E5%8A%A0%E9%97%AE%E7%AD%94
|
||||
func (r *Client) AddKnowledgeIntent(req *AddKnowledgeIntentRequest) (*AddKnowledgeIntentResponse, 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(addKnowledgeIntentURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &AddKnowledgeIntentResponse{}
|
||||
err = util.DecodeWithError(response, result, "AddKnowledgeIntent")
|
||||
return result, err
|
||||
}
|
||||
|
||||
// DelKnowledgeIntentRequest 知识库问答删除请求
|
||||
type DelKnowledgeIntentRequest struct {
|
||||
IntentID string `json:"intent_id"`
|
||||
}
|
||||
|
||||
// DelKnowledgeIntent 知识库问答删除
|
||||
// see https://developer.work.weixin.qq.com/document/path/95972#%E5%88%A0%E9%99%A4%E9%97%AE%E7%AD%94
|
||||
func (r *Client) DelKnowledgeIntent(req *DelKnowledgeIntentRequest) error {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(delKnowledgeIntentURL, accessToken), req); err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "DelKnowledgeIntent")
|
||||
}
|
||||
|
||||
// ModKnowledgeIntentRequest 知识库问答修改请求
|
||||
type ModKnowledgeIntentRequest struct {
|
||||
IntentID string `json:"intent_id"`
|
||||
Question IntentQuestion `json:"question"`
|
||||
SimilarQuestions IntentSimilarQuestions `json:"similar_questions"`
|
||||
Answers []IntentAnswerReq `json:"answers"`
|
||||
}
|
||||
|
||||
// ModKnowledgeIntent 知识库问答修改
|
||||
// see https://developer.work.weixin.qq.com/document/path/95972#%E4%BF%AE%E6%94%B9%E9%97%AE%E7%AD%94
|
||||
func (r *Client) ModKnowledgeIntent(req *ModKnowledgeIntentRequest) error {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(modKnowledgeIntentURL, accessToken), req); err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "ModKnowledgeIntent")
|
||||
}
|
||||
|
||||
// ListKnowledgeIntentRequest 知识库问答列表请求
|
||||
type ListKnowledgeIntentRequest struct {
|
||||
Cursor string `json:"cursor"`
|
||||
Limit int `json:"limit"`
|
||||
GroupID string `json:"group_id"`
|
||||
IntentID string `json:"intent_id"`
|
||||
}
|
||||
|
||||
// ListKnowledgeIntentResponse 知识库问答列表响应
|
||||
type ListKnowledgeIntentResponse struct {
|
||||
util.CommonError
|
||||
NextCursor string `json:"next_cursor"`
|
||||
HasMore int `json:"has_more"`
|
||||
IntentList []KnowledgeIntent `json:"intent_list"`
|
||||
}
|
||||
|
||||
// KnowledgeIntent 问答摘要
|
||||
type KnowledgeIntent struct {
|
||||
GroupID string `json:"group_id"`
|
||||
IntentID string `json:"intent_id"`
|
||||
Question IntentQuestion `json:"question"`
|
||||
SimilarQuestions IntentSimilarQuestions `json:"similar_questions"`
|
||||
Answers []IntentAnswerRes `json:"answers"`
|
||||
}
|
||||
|
||||
// IntentAnswerRes 回答返回
|
||||
type IntentAnswerRes struct {
|
||||
Text IntentAnswerText `json:"text"`
|
||||
Attachments []IntentAnswerAttachmentRes `json:"attachments"`
|
||||
}
|
||||
|
||||
// IntentAnswerAttachmentRes 回答附件返回
|
||||
type IntentAnswerAttachmentRes struct {
|
||||
MsgType string `json:"msgtype"`
|
||||
Image IntentAnswerAttachmentImgRes `json:"image,omitempty"`
|
||||
Video IntentAnswerAttachmentVideoRes `json:"video,omitempty"`
|
||||
Link IntentAnswerAttachmentLink `json:"link,omitempty"`
|
||||
MiniProgram IntentAnswerAttachmentMiniProgramRes `json:"miniprogram,omitempty"`
|
||||
}
|
||||
|
||||
// IntentAnswerAttachmentImgRes 图片类型回答附件返回
|
||||
type IntentAnswerAttachmentImgRes struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// IntentAnswerAttachmentVideoRes 视频类型回答附件返回
|
||||
type IntentAnswerAttachmentVideoRes struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// IntentAnswerAttachmentMiniProgramRes 小程序类型回答附件返回
|
||||
type IntentAnswerAttachmentMiniProgramRes struct {
|
||||
Title string `json:"title"`
|
||||
AppID string `json:"appid"`
|
||||
PagePath string `json:"pagepath"`
|
||||
}
|
||||
|
||||
// ListKnowledgeIntent 知识库问答列表
|
||||
// see https://developer.work.weixin.qq.com/document/path/95972#%E8%8E%B7%E5%8F%96%E9%97%AE%E7%AD%94%E5%88%97%E8%A1%A8
|
||||
func (r *Client) ListKnowledgeIntent(req *ListKnowledgeIntentRequest) (*ListKnowledgeIntentResponse, 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(listKnowledgeIntentURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &ListKnowledgeIntentResponse{}
|
||||
err = util.DecodeWithError(response, result, "ListKnowledgeIntent")
|
||||
return result, err
|
||||
}
|
||||
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