mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-23 13:42:25 +08:00
Compare commits
7 Commits
c81d0b1215
...
feature/au
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1cee8868e | ||
|
|
aa1afc5a35 | ||
|
|
9e810be88a | ||
|
|
06719f77b7 | ||
|
|
b70ecd93a7 | ||
|
|
dea33e0e48 | ||
|
|
e02af1dc0f |
@@ -55,7 +55,7 @@ issues:
|
|||||||
linters-settings:
|
linters-settings:
|
||||||
funlen:
|
funlen:
|
||||||
lines: 66
|
lines: 66
|
||||||
statements: 40
|
statements: 50
|
||||||
|
|
||||||
#issues:
|
#issues:
|
||||||
# include:
|
# include:
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ const (
|
|||||||
checkEncryptedDataURL = "https://api.weixin.qq.com/wxa/business/checkencryptedmsg?access_token=%s"
|
checkEncryptedDataURL = "https://api.weixin.qq.com/wxa/business/checkencryptedmsg?access_token=%s"
|
||||||
|
|
||||||
getPhoneNumber = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?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 登录/用户信息
|
// Auth 登录/用户信息
|
||||||
@@ -114,37 +116,61 @@ type PhoneInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPhoneNumberContext 小程序通过 code 获取用户手机号
|
// GetPhoneNumberContext 小程序通过 code 获取用户手机号
|
||||||
func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (*GetPhoneNumberResponse, error) {
|
func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (result *GetPhoneNumberResponse, err error) {
|
||||||
var response []byte
|
var accessToken string
|
||||||
var (
|
if accessToken, err = auth.GetAccessToken(); err != nil {
|
||||||
at string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if at, err = auth.GetAccessToken(); err != nil {
|
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
header := map[string]string{"Content-Type": "application/json;charset=utf-8"}
|
var (
|
||||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(getPhoneNumber, at), bodyBytes, header); err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var result GetPhoneNumberResponse
|
err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber")
|
||||||
if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
|
return
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPhoneNumber 小程序通过 code 获取用户手机号
|
// GetPhoneNumber 小程序通过 code 获取用户手机号
|
||||||
func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
||||||
return auth.GetPhoneNumberContext(context2.Background(), code)
|
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
|
||||||
|
// }
|
||||||
|
|||||||
@@ -11,5 +11,7 @@ type Config struct {
|
|||||||
AppSecret string `json:"app_secret"` // appSecret
|
AppSecret string `json:"app_secret"` // appSecret
|
||||||
AppKey string `json:"app_key"` // appKey
|
AppKey string `json:"app_key"` // appKey
|
||||||
OfferID string `json:"offer_id"` // offerId
|
OfferID string `json:"offer_id"` // offerId
|
||||||
|
Token string `json:"token"` // token
|
||||||
|
EncodingAESKey string `json:"encoding_aes_key"` // EncodingAESKey
|
||||||
Cache cache.Cache
|
Cache cache.Cache
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ const (
|
|||||||
MsgTypeLink = "link"
|
MsgTypeLink = "link"
|
||||||
// MsgTypeMiniProgramPage 小程序卡片
|
// MsgTypeMiniProgramPage 小程序卡片
|
||||||
MsgTypeMiniProgramPage = "miniprogrampage"
|
MsgTypeMiniProgramPage = "miniprogrampage"
|
||||||
|
// MsgTypeEvent 事件
|
||||||
|
MsgTypeEvent MsgType = "event"
|
||||||
|
// DataTypeXML XML格式数据
|
||||||
|
DataTypeXML = "xml"
|
||||||
|
// DataTypeJSON JSON格式数据
|
||||||
|
DataTypeJSON = "json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CommonToken 消息中通用的结构
|
// CommonToken 消息中通用的结构
|
||||||
|
|||||||
375
miniprogram/message/message.go
Normal file
375
miniprogram/message/message.go
Normal file
@@ -0,0 +1,375 @@
|
|||||||
|
package message
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"encoding/xml"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram/security"
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConfirmReceiveMethod 确认收货方式
|
||||||
|
type ConfirmReceiveMethod int8
|
||||||
|
|
||||||
|
const (
|
||||||
|
// EventTypeTradeManageRemindAccessAPI 提醒接入发货信息管理服务API
|
||||||
|
// 小程序完成账期授权时/小程序产生第一笔交易时/已产生交易但从未发货的小程序,每天一次
|
||||||
|
EventTypeTradeManageRemindAccessAPI EventType = "trade_manage_remind_access_api"
|
||||||
|
// EventTypeTradeManageRemindShipping 提醒需要上传发货信息
|
||||||
|
// 曾经发过货的小程序,订单超过48小时未发货时
|
||||||
|
EventTypeTradeManageRemindShipping EventType = "trade_manage_remind_shipping"
|
||||||
|
// EventTypeTradeManageOrderSettlement 订单将要结算或已经结算
|
||||||
|
// 订单完成发货时/订单结算时
|
||||||
|
EventTypeTradeManageOrderSettlement EventType = "trade_manage_order_settlement"
|
||||||
|
// EventTypeAddExpressPath 运单轨迹更新事件
|
||||||
|
EventTypeAddExpressPath EventType = "add_express_path"
|
||||||
|
// EventTypeSecvodUpload 短剧媒资上传完成事件
|
||||||
|
EventTypeSecvodUpload EventType = "secvod_upload_event"
|
||||||
|
// EventTypeSecvodAudit 短剧媒资审核状态事件
|
||||||
|
EventTypeSecvodAudit EventType = "secvod_audit_event"
|
||||||
|
// EventTypeWxaMediaCheck 媒体内容安全异步审查结果通知
|
||||||
|
EventTypeWxaMediaCheck EventType = "wxa_media_check"
|
||||||
|
// EventTypeXpayGoodsDeliverNotify 道具发货推送事件
|
||||||
|
EventTypeXpayGoodsDeliverNotify EventType = "xpay_goods_deliver_notify"
|
||||||
|
// EventTypeXpayCoinPayNotify 代币支付推送事件
|
||||||
|
EventTypeXpayCoinPayNotify EventType = "xpay_coin_pay_notify"
|
||||||
|
// ConfirmReceiveMethodAuto 自动确认收货
|
||||||
|
ConfirmReceiveMethodAuto ConfirmReceiveMethod = 1
|
||||||
|
// ConfirmReceiveMethodManual 手动确认收货
|
||||||
|
ConfirmReceiveMethodManual ConfirmReceiveMethod = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
// PushReceiver 接收消息推送
|
||||||
|
// 暂仅支付Aes加密方式
|
||||||
|
type PushReceiver struct {
|
||||||
|
*context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPushReceiver 实例化
|
||||||
|
func NewPushReceiver(ctx *context.Context) *PushReceiver {
|
||||||
|
return &PushReceiver{
|
||||||
|
Context: ctx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMsg 获取接收到的消息(如果是加密的返回解密数据)
|
||||||
|
func (receiver *PushReceiver) GetMsg(r *http.Request) (string, []byte, error) {
|
||||||
|
// 判断请求格式
|
||||||
|
var dataType string
|
||||||
|
contentType := r.Header.Get("Content-Type")
|
||||||
|
if strings.HasPrefix(contentType, "text/xml") {
|
||||||
|
// xml格式
|
||||||
|
dataType = DataTypeXML
|
||||||
|
} else {
|
||||||
|
// json格式
|
||||||
|
dataType = DataTypeJSON
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取参数,验证签名
|
||||||
|
signature := r.FormValue("signature")
|
||||||
|
timestamp := r.FormValue("timestamp")
|
||||||
|
nonce := r.FormValue("nonce")
|
||||||
|
encryptType := r.FormValue("encrypt_type")
|
||||||
|
// 验证签名
|
||||||
|
tmpArr := []string{
|
||||||
|
receiver.Token,
|
||||||
|
timestamp,
|
||||||
|
nonce,
|
||||||
|
}
|
||||||
|
sort.Strings(tmpArr)
|
||||||
|
tmpSignature := util.Signature(tmpArr...)
|
||||||
|
if tmpSignature != signature {
|
||||||
|
return dataType, nil, errors.New("signature error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if encryptType == "aes" {
|
||||||
|
// 解密
|
||||||
|
var reqData DataReceived
|
||||||
|
if dataType == DataTypeXML {
|
||||||
|
if err := xml.NewDecoder(r.Body).Decode(&reqData); err != nil {
|
||||||
|
return dataType, nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := json.NewDecoder(r.Body).Decode(&reqData); err != nil {
|
||||||
|
return dataType, nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, rawMsgBytes, err := util.DecryptMsg(receiver.AppID, reqData.Encrypt, receiver.EncodingAESKey)
|
||||||
|
return dataType, rawMsgBytes, err
|
||||||
|
}
|
||||||
|
// 不加密
|
||||||
|
byteData, err := io.ReadAll(r.Body)
|
||||||
|
return dataType, byteData, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMsgData 获取接收到的消息(解密数据)
|
||||||
|
func (receiver *PushReceiver) GetMsgData(r *http.Request) (MsgType, EventType, PushData, error) {
|
||||||
|
dataType, decryptMsg, err := receiver.GetMsg(r)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", nil, err
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
msgType MsgType
|
||||||
|
eventType EventType
|
||||||
|
)
|
||||||
|
if dataType == DataTypeXML {
|
||||||
|
var commonToken CommonPushData
|
||||||
|
if err := xml.Unmarshal(decryptMsg, &commonToken); err != nil {
|
||||||
|
return "", "", nil, err
|
||||||
|
}
|
||||||
|
msgType, eventType = commonToken.MsgType, commonToken.Event
|
||||||
|
} else {
|
||||||
|
var commonToken CommonPushData
|
||||||
|
if err := json.Unmarshal(decryptMsg, &commonToken); err != nil {
|
||||||
|
return "", "", nil, err
|
||||||
|
}
|
||||||
|
msgType, eventType = commonToken.MsgType, commonToken.Event
|
||||||
|
}
|
||||||
|
if msgType == MsgTypeEvent {
|
||||||
|
pushData, err := receiver.getEvent(dataType, eventType, decryptMsg)
|
||||||
|
// 暂不支持其他事件类型
|
||||||
|
return msgType, eventType, pushData, err
|
||||||
|
}
|
||||||
|
// 暂不支持其他消息类型
|
||||||
|
return msgType, eventType, decryptMsg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getEvent 获取事件推送的数据
|
||||||
|
func (receiver *PushReceiver) getEvent(dataType string, eventType EventType, decryptMsg []byte) (PushData, error) {
|
||||||
|
switch eventType {
|
||||||
|
case EventTypeTradeManageRemindAccessAPI:
|
||||||
|
// 提醒接入发货信息管理服务API
|
||||||
|
var pushData PushDataRemindAccessAPI
|
||||||
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||||
|
return &pushData, err
|
||||||
|
case EventTypeTradeManageRemindShipping:
|
||||||
|
// 提醒需要上传发货信息
|
||||||
|
var pushData PushDataRemindShipping
|
||||||
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||||
|
return &pushData, err
|
||||||
|
case EventTypeTradeManageOrderSettlement:
|
||||||
|
// 订单将要结算或已经结算
|
||||||
|
var pushData PushDataOrderSettlement
|
||||||
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||||
|
return &pushData, err
|
||||||
|
case EventTypeWxaMediaCheck:
|
||||||
|
// 媒体内容安全异步审查结果通知
|
||||||
|
var pushData MediaCheckAsyncData
|
||||||
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||||
|
return &pushData, err
|
||||||
|
case EventTypeAddExpressPath:
|
||||||
|
// 运单轨迹更新
|
||||||
|
var pushData PushDataAddExpressPath
|
||||||
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||||
|
return &pushData, err
|
||||||
|
case EventTypeSecvodUpload:
|
||||||
|
// 短剧媒资上传完成
|
||||||
|
var pushData PushDataSecVodUpload
|
||||||
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||||
|
return &pushData, err
|
||||||
|
case EventTypeSecvodAudit:
|
||||||
|
// 短剧媒资审核状态
|
||||||
|
var pushData PushDataSecVodAudit
|
||||||
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||||
|
return &pushData, err
|
||||||
|
case EventTypeXpayGoodsDeliverNotify:
|
||||||
|
// 道具发货推送事件
|
||||||
|
var pushData PushDataXpayGoodsDeliverNotify
|
||||||
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||||
|
return &pushData, err
|
||||||
|
case EventTypeXpayCoinPayNotify:
|
||||||
|
// 代币支付推送事件
|
||||||
|
var pushData PushDataXpayCoinPayNotify
|
||||||
|
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||||
|
return &pushData, err
|
||||||
|
}
|
||||||
|
// 暂不支持其他事件类型,直接返回解密后的数据,由调用方处理
|
||||||
|
return decryptMsg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// unmarshal 解析推送的数据
|
||||||
|
func (receiver *PushReceiver) unmarshal(dateType string, decryptMsg []byte, pushData interface{}) error {
|
||||||
|
if dateType == DataTypeXML {
|
||||||
|
return xml.Unmarshal(decryptMsg, pushData)
|
||||||
|
}
|
||||||
|
return json.Unmarshal(decryptMsg, pushData)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataReceived 接收到的数据
|
||||||
|
type DataReceived struct {
|
||||||
|
Encrypt string `json:"Encrypt" xml:"Encrypt"` // 加密的消息体
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushData 推送的数据(已转对应的结构体)
|
||||||
|
type PushData interface{}
|
||||||
|
|
||||||
|
// CommonPushData 推送数据通用部分
|
||||||
|
type CommonPushData struct {
|
||||||
|
XMLName xml.Name `json:"-" xml:"xml"`
|
||||||
|
MsgType MsgType `json:"MsgType" xml:"MsgType"` // 消息类型,为固定值 "event"
|
||||||
|
Event EventType `json:"Event" xml:"Event"` // 事件类型
|
||||||
|
ToUserName string `json:"ToUserName" xml:"ToUserName"` // 小程序的原始 ID
|
||||||
|
FromUserName string `json:"FromUserName" xml:"FromUserName"` // 发送方账号(一个 OpenID,此时发送方是系统账号)
|
||||||
|
CreateTime int64 `json:"CreateTime" xml:"CreateTime"` // 消息创建时间 (整型),时间戳
|
||||||
|
}
|
||||||
|
|
||||||
|
// MediaCheckAsyncData 媒体内容安全异步审查结果通知
|
||||||
|
type MediaCheckAsyncData struct {
|
||||||
|
CommonPushData
|
||||||
|
Appid string `json:"appid" xml:"appid"`
|
||||||
|
TraceID string `json:"trace_id" xml:"trace_id"`
|
||||||
|
Version int `json:"version" xml:"version"`
|
||||||
|
Detail []*MediaCheckDetail `json:"detail" xml:"detail"`
|
||||||
|
Errcode int `json:"errcode" xml:"errcode"`
|
||||||
|
Errmsg string `json:"errmsg" xml:"errmsg"`
|
||||||
|
Result MediaCheckAsyncResult `json:"result" xml:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MediaCheckDetail 检测结果详情
|
||||||
|
type MediaCheckDetail struct {
|
||||||
|
Strategy string `json:"strategy" xml:"strategy"`
|
||||||
|
Errcode int `json:"errcode" xml:"errcode"`
|
||||||
|
Suggest security.CheckSuggest `json:"suggest" xml:"suggest"`
|
||||||
|
Label int `json:"label" xml:"label"`
|
||||||
|
Prob int `json:"prob" xml:"prob"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MediaCheckAsyncResult 检测结果
|
||||||
|
type MediaCheckAsyncResult struct {
|
||||||
|
Suggest security.CheckSuggest `json:"suggest" xml:"suggest"`
|
||||||
|
Label security.CheckLabel `json:"label" xml:"label"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushDataOrderSettlement 订单将要结算或已经结算通知
|
||||||
|
type PushDataOrderSettlement struct {
|
||||||
|
CommonPushData
|
||||||
|
TransactionID string `json:"transaction_id" xml:"transaction_id"` // 支付订单号
|
||||||
|
MerchantID string `json:"merchant_id" xml:"merchant_id"` // 商户号
|
||||||
|
SubMerchantID string `json:"sub_merchant_id" xml:"sub_merchant_id"` // 子商户号
|
||||||
|
MerchantTradeNo string `json:"merchant_trade_no" xml:"merchant_trade_no"` // 商户订单号
|
||||||
|
PayTime int64 `json:"pay_time" xml:"pay_time"` // 支付成功时间,秒级时间戳
|
||||||
|
ShippedTime int64 `json:"shipped_time" xml:"shipped_time"` // 发货时间,秒级时间戳
|
||||||
|
EstimatedSettlementTime int64 `json:"estimated_settlement_time" xml:"estimated_settlement_time"` // 预计结算时间,秒级时间戳。发货时推送才有该字段
|
||||||
|
ConfirmReceiveMethod ConfirmReceiveMethod `json:"confirm_receive_method" xml:"confirm_receive_method"` // 确认收货方式:1. 自动确认收货;2. 手动确认收货。结算时推送才有该字段
|
||||||
|
ConfirmReceiveTime int64 `json:"confirm_receive_time" xml:"confirm_receive_time"` // 确认收货时间,秒级时间戳。结算时推送才有该字段
|
||||||
|
SettlementTime int64 `json:"settlement_time" xml:"settlement_time"` // 订单结算时间,秒级时间戳。结算时推送才有该字段
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushDataRemindShipping 提醒需要上传发货信息
|
||||||
|
type PushDataRemindShipping struct {
|
||||||
|
CommonPushData
|
||||||
|
TransactionID string `json:"transaction_id" xml:"transaction_id"` // 微信支付订单号
|
||||||
|
MerchantID string `json:"merchant_id" xml:"merchant_id"` // 商户号
|
||||||
|
SubMerchantID string `json:"sub_merchant_id" xml:"sub_merchant_id"` // 子商户号
|
||||||
|
MerchantTradeNo string `json:"merchant_trade_no" xml:"merchant_trade_no"` // 商户订单号
|
||||||
|
PayTime int64 `json:"pay_time" xml:"pay_time"` // 支付成功时间,秒级时间戳
|
||||||
|
Msg string `json:"msg" xml:"msg"` // 消息文本内容
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushDataRemindAccessAPI 提醒接入发货信息管理服务API信息
|
||||||
|
type PushDataRemindAccessAPI struct {
|
||||||
|
CommonPushData
|
||||||
|
Msg string `json:"msg" xml:"msg"` // 消息文本内容
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushDataAddExpressPath 运单轨迹更新信息
|
||||||
|
type PushDataAddExpressPath struct {
|
||||||
|
CommonPushData
|
||||||
|
DeliveryID string `json:"DeliveryID" xml:"DeliveryID"` // 快递公司ID
|
||||||
|
WayBillID string `json:"WaybillId" xml:"WaybillId"` // 运单ID
|
||||||
|
OrderID string `json:"OrderId" xml:"OrderId"` // 订单ID
|
||||||
|
Version int `json:"Version" xml:"Version"` // 轨迹版本号(整型)
|
||||||
|
Count int `json:"Count" xml:"Count"` // 轨迹节点数(整型)
|
||||||
|
Actions []*PushDataAddExpressPathAction `json:"Actions" xml:"Actions"` // 轨迹节点列表
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushDataAddExpressPathAction 轨迹节点
|
||||||
|
type PushDataAddExpressPathAction struct {
|
||||||
|
ActionTime int64 `json:"ActionTime" xml:"ActionTime"` // 轨迹节点 Unix 时间戳
|
||||||
|
ActionType int `json:"ActionType" xml:"ActionType"` // 轨迹节点类型
|
||||||
|
ActionMsg string `json:"ActionMsg" xml:"ActionMsg"` // 轨迹节点详情
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushDataSecVodUpload 短剧媒资上传完成
|
||||||
|
type PushDataSecVodUpload struct {
|
||||||
|
CommonPushData
|
||||||
|
UploadEvent SecVodUploadEvent `json:"upload_event" xml:"upload_event"` // 上传完成事件
|
||||||
|
}
|
||||||
|
|
||||||
|
// SecVodUploadEvent 短剧媒资上传完成事件
|
||||||
|
type SecVodUploadEvent struct {
|
||||||
|
MediaID string `json:"media_id" xml:"media_id"` // 媒资id
|
||||||
|
SourceContext string `json:"source_context" xml:"source_context"` // 透传上传接口中开发者设置的值。
|
||||||
|
Errcode int `json:"errcode" xml:"errcode"` // 错误码,上传失败时该值非
|
||||||
|
Errmsg string `json:"errmsg" xml:"errmsg"` // 错误提示
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushDataSecVodAudit 短剧媒资审核状态
|
||||||
|
type PushDataSecVodAudit struct {
|
||||||
|
CommonPushData
|
||||||
|
AuditEvent SecVodAuditEvent `json:"audit_event" xml:"audit_event"` // 审核状态事件
|
||||||
|
}
|
||||||
|
|
||||||
|
// SecVodAuditEvent 短剧媒资审核状态事件
|
||||||
|
type SecVodAuditEvent struct {
|
||||||
|
DramaID string `json:"drama_id" xml:"drama_id"` // 剧目id
|
||||||
|
SourceContext string `json:"source_context" xml:"source_context"` // 透传上传接口中开发者设置的值
|
||||||
|
AuditDetail DramaAuditDetail `json:"audit_detail" xml:"audit_detail"` // 剧目审核结果,单独每一集的审核结果可以根据drama_id查询剧集详情得到
|
||||||
|
}
|
||||||
|
|
||||||
|
// DramaAuditDetail 剧目审核结果
|
||||||
|
type DramaAuditDetail struct {
|
||||||
|
Status int `json:"status" xml:"status"` // 审核状态,0为无效值;1为审核中;2为最终失败;3为审核通过;4为驳回重填
|
||||||
|
CreateTime int64 `json:"create_time" xml:"create_time"` // 提审时间戳
|
||||||
|
AuditTime int64 `json:"audit_time" xml:"audit_time"` // 审核时间戳
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushDataXpayGoodsDeliverNotify 道具发货推送
|
||||||
|
type PushDataXpayGoodsDeliverNotify struct {
|
||||||
|
CommonPushData
|
||||||
|
OpenID string `json:"OpenId" xml:"OpenId"` // 用户openid
|
||||||
|
OutTradeNo string `json:"OutTradeNo" xml:"OutTradeNo"` // 业务订单号
|
||||||
|
Env int `json:"Env" xml:"Env"` //,环境配置 0:现网环境(也叫正式环境)1:沙箱环境
|
||||||
|
WeChatPayInfo WeChatPayInfo `json:"WeChatPayInfo" xml:"WeChatPayInfo"` // 微信支付信息 非微信支付渠道可能没有
|
||||||
|
GoodsInfo GoodsInfo `json:"GoodsInfo" xml:"GoodsInfo"` // 道具参数信息
|
||||||
|
}
|
||||||
|
|
||||||
|
// WeChatPayInfo 微信支付信息
|
||||||
|
type WeChatPayInfo struct {
|
||||||
|
MchOrderNo string `json:"MchOrderNo" xml:"MchOrderNo"` // 微信支付商户单号
|
||||||
|
TransactionID string `json:"TransactionId" xml:"TransactionId"` // 交易单号(微信支付订单号)
|
||||||
|
PaidTime int64 `json:"PaidTime" xml:"PaidTime"` // 用户支付时间,Linux秒级时间戳
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoodsInfo 道具参数信息
|
||||||
|
type GoodsInfo struct {
|
||||||
|
ProductID string `json:"ProductId" xml:"ProductId"` // 道具ID
|
||||||
|
Quantity int `json:"Quantity" xml:"Quantity"` // 数量
|
||||||
|
OrigPrice int64 `json:"OrigPrice" xml:"OrigPrice"` // 物品原始价格 (单位:分)
|
||||||
|
ActualPrice int64 `json:"ActualPrice" xml:"ActualPrice"` // 物品实际支付价格(单位:分)
|
||||||
|
Attach string `json:"Attach" xml:"Attach"` // 透传信息
|
||||||
|
}
|
||||||
|
|
||||||
|
// PushDataXpayCoinPayNotify 代币支付推送
|
||||||
|
type PushDataXpayCoinPayNotify struct {
|
||||||
|
CommonPushData
|
||||||
|
OpenID string `json:"OpenId" xml:"OpenId"` // 用户openid
|
||||||
|
OutTradeNo string `json:"OutTradeNo" xml:"OutTradeNo"` // 业务订单号
|
||||||
|
Env int `json:"Env" xml:"Env"` //,环境配置 0:现网环境(也叫正式环境)1:沙箱环境
|
||||||
|
WeChatPayInfo WeChatPayInfo `json:"WeChatPayInfo" xml:"WeChatPayInfo"` // 微信支付信息 非微信支付渠道可能没有
|
||||||
|
CoinInfo CoinInfo `json:"CoinInfo" xml:"CoinInfo"` // 代币参数信息
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoinInfo 代币参数信息
|
||||||
|
type CoinInfo struct {
|
||||||
|
Quantity int `json:"Quantity" xml:"Quantity"` // 数量
|
||||||
|
OrigPrice int64 `json:"OrigPrice" xml:"OrigPrice"` // 物品原始价格 (单位:分)
|
||||||
|
ActualPrice int64 `json:"ActualPrice" xml:"ActualPrice"` // 物品实际支付价格(单位:分)
|
||||||
|
Attach string `json:"Attach" xml:"Attach"` // 透传信息
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/silenceper/wechat/v2/miniprogram/encryptor"
|
"github.com/silenceper/wechat/v2/miniprogram/encryptor"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/message"
|
"github.com/silenceper/wechat/v2/miniprogram/message"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/minidrama"
|
"github.com/silenceper/wechat/v2/miniprogram/minidrama"
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram/order"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/privacy"
|
"github.com/silenceper/wechat/v2/miniprogram/privacy"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/qrcode"
|
"github.com/silenceper/wechat/v2/miniprogram/qrcode"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/riskcontrol"
|
"github.com/silenceper/wechat/v2/miniprogram/riskcontrol"
|
||||||
@@ -140,6 +141,16 @@ func (miniProgram *MiniProgram) GetVirtualPayment() *virtualpayment.VirtualPayme
|
|||||||
return virtualpayment.NewVirtualPayment(miniProgram.ctx)
|
return virtualpayment.NewVirtualPayment(miniProgram.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMessageReceiver 获取消息推送接收器
|
||||||
|
func (miniProgram *MiniProgram) GetMessageReceiver() *message.PushReceiver {
|
||||||
|
return message.NewPushReceiver(miniProgram.ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetShipping 小程序发货信息管理服务
|
||||||
|
func (miniProgram *MiniProgram) GetShipping() *order.Shipping {
|
||||||
|
return order.NewShipping(miniProgram.ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// GetMiniDrama 小程序娱乐微短剧
|
// GetMiniDrama 小程序娱乐微短剧
|
||||||
func (miniProgram *MiniProgram) GetMiniDrama() *minidrama.MiniDrama {
|
func (miniProgram *MiniProgram) GetMiniDrama() *minidrama.MiniDrama {
|
||||||
return minidrama.NewMiniDrama(miniProgram.ctx)
|
return minidrama.NewMiniDrama(miniProgram.ctx)
|
||||||
|
|||||||
269
miniprogram/order/shipping.go
Normal file
269
miniprogram/order/shipping.go
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
package order
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// 发货信息录入
|
||||||
|
uploadShippingInfoURL = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=%s"
|
||||||
|
|
||||||
|
// 查询订单发货状态
|
||||||
|
getShippingOrderURL = "https://api.weixin.qq.com/wxa/sec/order/get_order?access_token=%s"
|
||||||
|
|
||||||
|
// 查询订单列表
|
||||||
|
getShippingOrderListURL = "https://api.weixin.qq.com/wxa/sec/order/get_order_list?access_token=%s"
|
||||||
|
|
||||||
|
// 确认收货提醒接口
|
||||||
|
notifyConfirmReceiveURL = "https://api.weixin.qq.com/wxa/sec/order/notify_confirm_receive?access_token=%s"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Shipping 发货信息管理
|
||||||
|
type Shipping struct {
|
||||||
|
*context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewShipping init
|
||||||
|
func NewShipping(ctx *context.Context) *Shipping {
|
||||||
|
return &Shipping{ctx}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UploadShippingInfo 发货信息录入
|
||||||
|
// see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order-shipping/order-shipping.html
|
||||||
|
func (shipping *Shipping) UploadShippingInfo(in *UploadShippingInfoRequest) (err error) {
|
||||||
|
accessToken, err := shipping.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := fmt.Sprintf(uploadShippingInfoURL, accessToken)
|
||||||
|
response, err := util.PostJSON(uri, in)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用通用方法返回错误
|
||||||
|
return util.DecodeWithCommonError(response, "UploadShippingInfo")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetShippingOrder 查询订单发货状态
|
||||||
|
func (shipping *Shipping) GetShippingOrder(in *GetShippingOrderRequest) (res ShippingOrderResponse, err error) {
|
||||||
|
accessToken, err := shipping.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := fmt.Sprintf(getShippingOrderURL, accessToken)
|
||||||
|
response, err := util.PostJSON(uri, in)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = util.DecodeWithError(response, &res, "GetShippingOrder")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetShippingOrderList 查询订单列表
|
||||||
|
func (shipping *Shipping) GetShippingOrderList(in *GetShippingOrderListRequest) (res GetShippingOrderListResponse, err error) {
|
||||||
|
accessToken, err := shipping.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := fmt.Sprintf(getShippingOrderListURL, accessToken)
|
||||||
|
response, err := util.PostJSON(uri, in)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = util.DecodeWithError(response, &res, "GetShippingOrderList")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyConfirmReceive 确认收货提醒接口
|
||||||
|
func (shipping *Shipping) NotifyConfirmReceive(in *NotifyConfirmReceiveRequest) (err error) {
|
||||||
|
accessToken, err := shipping.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uri := fmt.Sprintf(notifyConfirmReceiveURL, accessToken)
|
||||||
|
response, err := util.PostJSON(uri, in)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用通用方法返回错误
|
||||||
|
return util.DecodeWithCommonError(response, "NotifyConfirmReceive")
|
||||||
|
}
|
||||||
|
|
||||||
|
// UploadShippingInfoRequest 发货信息录入请求参数
|
||||||
|
type UploadShippingInfoRequest struct {
|
||||||
|
OrderKey *ShippingOrderKey `json:"order_key"` // 订单,需要上传物流信息的订单
|
||||||
|
LogisticsType LogisticsType `json:"logistics_type"` // 物流模式
|
||||||
|
DeliveryMode DeliveryMode `json:"delivery_mode"` // 发货模式
|
||||||
|
IsAllDelivered bool `json:"is_all_delivered"` // 分拆发货模式时必填,用于标识分拆发货模式下是否已全部发货完成
|
||||||
|
ShippingList []*ShippingInfo `json:"shipping_list"` // 物流信息列表,发货物流单列表,支持统一发货(单个物流单)和分拆发货(多个物流单)两种模式
|
||||||
|
UploadTime *time.Time `json:"upload_time"` // 上传时间,用于标识请求的先后顺序
|
||||||
|
Payer *ShippingPayer `json:"payer"` // 支付人信息
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShippingOrderKey 订单
|
||||||
|
type ShippingOrderKey struct {
|
||||||
|
OrderNumberType NumberType `json:"order_number_type"` // 订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号。
|
||||||
|
TransactionID string `json:"transaction_id"` // 原支付交易对应的微信订单号
|
||||||
|
Mchid string `json:"mchid"` // 支付下单商户的商户号,由微信支付生成并下发
|
||||||
|
OutTradeNo string `json:"out_trade_no"` // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShippingPayer 支付者信息
|
||||||
|
type ShippingPayer struct {
|
||||||
|
Openid string `json:"openid"` // 用户标识,用户在小程序appid下的唯一标识
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShippingInfo 物流信息
|
||||||
|
type ShippingInfo struct {
|
||||||
|
TrackingNo string `json:"tracking_no"` // 物流单号,物流快递发货时必填
|
||||||
|
ExpressCompany string `json:"express_company"` // 物流公司编码,快递公司ID,物流快递发货时必填;参见「查询物流公司编码列表」
|
||||||
|
ItemDesc string `json:"item_desc"` // 商品信息,例如:微信红包抱枕*1个,限120个字以内
|
||||||
|
Contact ShippingContact `json:"contact"` // 联系方式,当发货的物流公司为顺丰时,联系方式为必填,收件人或寄件人联系方式二选一
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShippingContact 联系方式
|
||||||
|
type ShippingContact struct {
|
||||||
|
ConsignorContact string `json:"consignor_contact"` // 寄件人联系方式,寄件人联系方式,采用掩码传输,最后4位数字不能打掩码
|
||||||
|
ReceiverContact string `json:"receiver_contact"` // 收件人联系方式,收件人联系方式,采用掩码传输,最后4位数字不能打掩码
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeliveryMode 发货模式
|
||||||
|
type DeliveryMode uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DeliveryModeUnifiedDelivery 统一发货
|
||||||
|
DeliveryModeUnifiedDelivery DeliveryMode = 1
|
||||||
|
// DeliveryModeSplitDelivery 分拆发货
|
||||||
|
DeliveryModeSplitDelivery DeliveryMode = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
// LogisticsType 物流模式
|
||||||
|
type LogisticsType uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
// LogisticsTypeExpress 实体物流配送采用快递公司进行实体物流配送形式
|
||||||
|
LogisticsTypeExpress LogisticsType = 1
|
||||||
|
// LogisticsTypeSameCity 同城配送
|
||||||
|
LogisticsTypeSameCity LogisticsType = 2
|
||||||
|
// LogisticsTypeVirtual 虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式
|
||||||
|
LogisticsTypeVirtual LogisticsType = 3
|
||||||
|
// LogisticsTypeSelfPickup 用户自提
|
||||||
|
LogisticsTypeSelfPickup LogisticsType = 4
|
||||||
|
)
|
||||||
|
|
||||||
|
// NumberType 订单单号类型
|
||||||
|
type NumberType uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
// NumberTypeOutTradeNo 使用下单商户号和商户侧单号
|
||||||
|
NumberTypeOutTradeNo NumberType = 1
|
||||||
|
// NumberTypeTransactionID 使用微信支付单号
|
||||||
|
NumberTypeTransactionID NumberType = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetShippingOrderRequest 查询订单发货状态参数
|
||||||
|
type GetShippingOrderRequest struct {
|
||||||
|
TransactionID string `json:"transaction_id"` // 原支付交易对应的微信订单号
|
||||||
|
MerchantID string `json:"merchant_id"` // 支付下单商户的商户号,由微信支付生成并下发
|
||||||
|
SubMerchantID string `json:"sub_merchant_id"` //二级商户号
|
||||||
|
MerchantTradeNo string `json:"merchant_trade_no"` //商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一。
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShippingItem 物流信息
|
||||||
|
type ShippingItem struct {
|
||||||
|
TrackingNo string `json:"tracking_no"` // 物流单号,示例值: "323244567777
|
||||||
|
ExpressCompany string `json:"express_company"` // 物流公司编码,快递公司ID,物流快递发货时必填;参见「查询物流公司编码列表」
|
||||||
|
UploadTime int64 `json:"upload_time"` // 上传物流信息时间,时间戳形式
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShippingDetail 发货信息
|
||||||
|
type ShippingDetail struct {
|
||||||
|
DeliveryMode DeliveryMode `json:"delivery_mode"` // 发货模式
|
||||||
|
LogisticsType LogisticsType `json:"logistics_type"` // 物流模式
|
||||||
|
FinishShipping bool `json:"finish_shipping"` // 是否已全部发货
|
||||||
|
FinishShippingCount int `json:"finish_shipping_count"` // 已完成全部发货的次数
|
||||||
|
GoodsDesc string `json:"goods_desc"` // 在小程序后台发货信息录入页录入的商品描述
|
||||||
|
ShippingList []*ShippingItem `json:"shipping_list"` // 物流信息列表
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShippingOrder 订单发货状态
|
||||||
|
type ShippingOrder struct {
|
||||||
|
TransactionID string `json:"transaction_id"` // 原支付交易对应的微信订单号
|
||||||
|
MerchantTradeNo string `json:"merchant_trade_no"` // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
|
||||||
|
MerchantID string `json:"merchant_id"` // 支付下单商户的商户号,由微信支付生成并下发
|
||||||
|
SubMerchantID string `json:"sub_merchant_id"` // 二级商户号
|
||||||
|
Description string `json:"description"` // 以分号连接的该支付单的所有商品描述,当超过120字时自动截断并以 “...” 结尾
|
||||||
|
PaidAmount int64 `json:"paid_amount"` // 支付单实际支付金额,整型,单位:分钱
|
||||||
|
Openid string `json:"openid"` // 支付者openid
|
||||||
|
TradeCreateTime int64 `json:"trade_create_time"` // 交易创建时间,时间戳形式
|
||||||
|
PayTime int64 `json:"pay_time"` // 支付时间,时间戳形式
|
||||||
|
InComplaint bool `json:"in_complaint"` // 是否处在交易纠纷中
|
||||||
|
OrderState State `json:"order_state"` // 订单状态枚举:(1) 待发货;(2) 已发货;(3) 确认收货;(4) 交易完成;(5) 已退款
|
||||||
|
Shipping *ShippingDetail `json:"shipping"` // 订单发货信息
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShippingOrderResponse 查询订单发货状态返回参数
|
||||||
|
type ShippingOrderResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
Order ShippingOrder `json:"order"` // 订单发货信息
|
||||||
|
}
|
||||||
|
|
||||||
|
// State 订单状态
|
||||||
|
type State uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
// StateWaitShipment 待发货
|
||||||
|
StateWaitShipment State = 1
|
||||||
|
// StateShipped 已发货
|
||||||
|
StateShipped State = 2
|
||||||
|
// StateConfirm 确认收货
|
||||||
|
StateConfirm State = 3
|
||||||
|
// StateComplete 交易完成
|
||||||
|
StateComplete State = 4
|
||||||
|
// StateRefund 已退款
|
||||||
|
StateRefund State = 5
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetShippingOrderListRequest 查询订单列表请求参数
|
||||||
|
type GetShippingOrderListRequest struct {
|
||||||
|
PayTimeRange *TimeRange `json:"pay_time_range"` // 支付时间范围
|
||||||
|
OrderState State `json:"order_state,omitempty"` // 订单状态
|
||||||
|
Openid string `json:"openid,omitempty"` // 支付者openid
|
||||||
|
LastIndex string `json:"last_index,omitempty"` // 翻页时使用,获取第一页时不用传入,如果查询结果中 has_more 字段为 true,则传入该次查询结果中返回的 last_index 字段可获取下一页
|
||||||
|
PageSize int64 `json:"page_size"` // 每页数量,最多50条
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimeRange 时间范围
|
||||||
|
type TimeRange struct {
|
||||||
|
BeginTime int64 `json:"begin_time,omitempty"` // 查询开始时间,时间戳形式
|
||||||
|
EndTime int64 `json:"end_time,omitempty"` // 查询结束时间,时间戳形式
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetShippingOrderListResponse 查询订单列表返回参数
|
||||||
|
type GetShippingOrderListResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
OrderList []*ShippingOrder `json:"order_list"`
|
||||||
|
LastIndex string `json:"last_index"`
|
||||||
|
HasMore bool `json:"has_more"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyConfirmReceiveRequest 确认收货提醒接口请求参数
|
||||||
|
type NotifyConfirmReceiveRequest struct {
|
||||||
|
TransactionID string `json:"transaction_id"` // 原支付交易对应的微信订单号
|
||||||
|
MerchantID string `json:"merchant_id"` // 支付下单商户的商户号,由微信支付生成并下发
|
||||||
|
SubMerchantID string `json:"sub_merchant_id"` // 二级商户号
|
||||||
|
MerchantTradeNo string `json:"merchant_trade_no"` // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
|
||||||
|
ReceivedTime int64 `json:"received_time"` // 收货时间,时间戳形式
|
||||||
|
}
|
||||||
@@ -117,6 +117,24 @@ const (
|
|||||||
|
|
||||||
// queryPublishGoods 查询批量发布道具任务状态
|
// queryPublishGoods 查询批量发布道具任务状态
|
||||||
queryPublishGoods = "/xpay/query_publish_goods"
|
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 (
|
const (
|
||||||
|
|||||||
@@ -145,6 +145,8 @@ type OrderItem struct {
|
|||||||
WxOrderID string `json:"wx_order_id"` // 微信内部单号
|
WxOrderID string `json:"wx_order_id"` // 微信内部单号
|
||||||
ChannelOrderID string `json:"channel_order_id"` // 渠道订单号,为用户微信支付详情页面上的商户单号
|
ChannelOrderID string `json:"channel_order_id"` // 渠道订单号,为用户微信支付详情页面上的商户单号
|
||||||
WxPayOrderID string `json:"wxpay_order_id"` // 微信支付交易单号,为用户微信支付详情页面上的交易单号
|
WxPayOrderID string `json:"wxpay_order_id"` // 微信支付交易单号,为用户微信支付详情页面上的交易单号
|
||||||
|
SettTime int64 `json:"sett_time"` // 结算时间,unix 秒级时间戳,结算时间的秒级时间戳,大于 0 表示结算成功
|
||||||
|
SettState uint `json:"sett_state"` // 结算状态 0-未开始结算 1-结算中 2-结算成功
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryOrderResponse 查询创建的订单(现金单,非代币单)响应参数
|
// QueryOrderResponse 查询创建的订单(现金单,非代币单)响应参数
|
||||||
|
|||||||
@@ -479,6 +479,7 @@ func (s *VirtualPayment) requestAddress(params URLParams) (url string, err error
|
|||||||
case queryUserBalance:
|
case queryUserBalance:
|
||||||
case currencyPay:
|
case currencyPay:
|
||||||
case cancelCurrencyPay:
|
case cancelCurrencyPay:
|
||||||
|
case defaultUnifiedOrderURL:
|
||||||
if params.PaySign, params.Signature, err = s.PaySignature(params.Path, params.Content); err != nil {
|
if params.PaySign, params.Signature, err = s.PaySignature(params.Path, params.Content); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ const (
|
|||||||
getGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/get?access_token=%s"
|
getGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/get?access_token=%s"
|
||||||
// delGroupWelcomeTemplateURL 删除入群欢迎语素材
|
// delGroupWelcomeTemplateURL 删除入群欢迎语素材
|
||||||
delGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/del?access_token=%s"
|
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 创建企业群发请求
|
// AddMsgTemplateRequest 创建企业群发请求
|
||||||
@@ -422,3 +426,47 @@ func (r *Client) DelGroupWelcomeTemplate(req *DelGroupWelcomeTemplateRequest) er
|
|||||||
}
|
}
|
||||||
return nil
|
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