mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-23 13:42:25 +08:00
Compare commits
2 Commits
v2.1.6-rc.
...
248141b2bb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
248141b2bb | ||
|
|
d55a170570 |
6
cache/memory.go
vendored
6
cache/memory.go
vendored
@@ -26,25 +26,31 @@ func NewMemory() *Memory {
|
|||||||
|
|
||||||
// Get return cached value
|
// Get return cached value
|
||||||
func (mem *Memory) Get(key string) interface{} {
|
func (mem *Memory) Get(key string) interface{} {
|
||||||
|
mem.Lock()
|
||||||
if ret, ok := mem.data[key]; ok {
|
if ret, ok := mem.data[key]; ok {
|
||||||
|
mem.Unlock()
|
||||||
if ret.Expired.Before(time.Now()) {
|
if ret.Expired.Before(time.Now()) {
|
||||||
mem.deleteKey(key)
|
mem.deleteKey(key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return ret.Data
|
return ret.Data
|
||||||
}
|
}
|
||||||
|
mem.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsExist check value exists in memcache.
|
// IsExist check value exists in memcache.
|
||||||
func (mem *Memory) IsExist(key string) bool {
|
func (mem *Memory) IsExist(key string) bool {
|
||||||
|
mem.Lock()
|
||||||
if ret, ok := mem.data[key]; ok {
|
if ret, ok := mem.data[key]; ok {
|
||||||
|
mem.Unlock()
|
||||||
if ret.Expired.Before(time.Now()) {
|
if ret.Expired.Before(time.Now()) {
|
||||||
mem.deleteKey(key)
|
mem.deleteKey(key)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
mem.Unlock()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,9 +66,8 @@ func (ak *DefaultAccessToken) GetAccessToken() (accessToken string, err error) {
|
|||||||
func (ak *DefaultAccessToken) GetAccessTokenContext(ctx context.Context) (accessToken string, err error) {
|
func (ak *DefaultAccessToken) GetAccessTokenContext(ctx context.Context) (accessToken string, err error) {
|
||||||
// 先从cache中取
|
// 先从cache中取
|
||||||
accessTokenCacheKey := fmt.Sprintf("%s_access_token_%s", ak.cacheKeyPrefix, ak.appID)
|
accessTokenCacheKey := fmt.Sprintf("%s_access_token_%s", ak.cacheKeyPrefix, ak.appID)
|
||||||
val := ak.cache.Get(accessTokenCacheKey)
|
if val := ak.cache.Get(accessTokenCacheKey); val != nil {
|
||||||
if accessToken = val.(string); accessToken != "" {
|
return val.(string), nil
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加上lock,是为了防止在并发获取token时,cache刚好失效,导致从微信服务器上获取到不同token
|
// 加上lock,是为了防止在并发获取token时,cache刚好失效,导致从微信服务器上获取到不同token
|
||||||
@@ -76,9 +75,8 @@ func (ak *DefaultAccessToken) GetAccessTokenContext(ctx context.Context) (access
|
|||||||
defer ak.accessTokenLock.Unlock()
|
defer ak.accessTokenLock.Unlock()
|
||||||
|
|
||||||
// 双检,防止重复从微信服务器获取
|
// 双检,防止重复从微信服务器获取
|
||||||
val = ak.cache.Get(accessTokenCacheKey)
|
if val := ak.cache.Get(accessTokenCacheKey); val != nil {
|
||||||
if accessToken = val.(string); accessToken != "" {
|
return val.(string), nil
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache失效,从微信服务器获取
|
// cache失效,从微信服务器获取
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"github.com/silenceper/wechat/v2/pay/config"
|
"github.com/silenceper/wechat/v2/pay/config"
|
||||||
"github.com/silenceper/wechat/v2/pay/notify"
|
"github.com/silenceper/wechat/v2/pay/notify"
|
||||||
"github.com/silenceper/wechat/v2/pay/order"
|
"github.com/silenceper/wechat/v2/pay/order"
|
||||||
"github.com/silenceper/wechat/v2/pay/redpacket"
|
|
||||||
"github.com/silenceper/wechat/v2/pay/refund"
|
"github.com/silenceper/wechat/v2/pay/refund"
|
||||||
"github.com/silenceper/wechat/v2/pay/transfer"
|
"github.com/silenceper/wechat/v2/pay/transfer"
|
||||||
)
|
)
|
||||||
@@ -38,8 +37,3 @@ func (pay *Pay) GetRefund() *refund.Refund {
|
|||||||
func (pay *Pay) GetTransfer() *transfer.Transfer {
|
func (pay *Pay) GetTransfer() *transfer.Transfer {
|
||||||
return transfer.NewTransfer(pay.cfg)
|
return transfer.NewTransfer(pay.cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRedpacket 红包
|
|
||||||
func (pay *Pay) GetRedpacket() *redpacket.Redpacket {
|
|
||||||
return redpacket.NewRedpacket(pay.cfg)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,131 +0,0 @@
|
|||||||
package redpacket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/xml"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/silenceper/wechat/v2/pay/config"
|
|
||||||
"github.com/silenceper/wechat/v2/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// redpacketGateway 发放红包接口
|
|
||||||
// https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
|
|
||||||
var redpacketGateway = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"
|
|
||||||
|
|
||||||
// Redpacket struct extends context
|
|
||||||
type Redpacket struct {
|
|
||||||
*config.Config
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRedpacket return an instance of Redpacket package
|
|
||||||
func NewRedpacket(cfg *config.Config) *Redpacket {
|
|
||||||
return &Redpacket{cfg}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Params 调用参数
|
|
||||||
type Params struct {
|
|
||||||
MchBillno string // 商户订单号
|
|
||||||
SendName string // 商户名称
|
|
||||||
ReOpenID string
|
|
||||||
TotalAmount int
|
|
||||||
TotalNum int
|
|
||||||
Wishing string
|
|
||||||
ClientIP string
|
|
||||||
ActName string
|
|
||||||
Remark string
|
|
||||||
|
|
||||||
RootCa string // ca证书
|
|
||||||
}
|
|
||||||
|
|
||||||
// request 接口请求参数
|
|
||||||
type request struct {
|
|
||||||
NonceStr string `xml:"nonce_str"`
|
|
||||||
Sign string `xml:"sign"`
|
|
||||||
MchID string `xml:"mch_id"`
|
|
||||||
MchBillno string `xml:"mch_billno"`
|
|
||||||
Wxappid string `xml:"wxappid"`
|
|
||||||
SendName string `xml:"send_name"`
|
|
||||||
ReOpenID string `xml:"re_openid"`
|
|
||||||
TotalAmount int `xml:"total_amount"`
|
|
||||||
TotalNum int `xml:"total_num"`
|
|
||||||
Wishing string `xml:"wishing"`
|
|
||||||
ClientIP string `xml:"client_ip"`
|
|
||||||
ActName string `xml:"act_name"`
|
|
||||||
Remark string `xml:"remark"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response 接口返回
|
|
||||||
type Response struct {
|
|
||||||
ReturnCode string `xml:"return_code"`
|
|
||||||
ReturnMsg string `xml:"return_msg"`
|
|
||||||
ResultCode string `xml:"result_code,omitempty"`
|
|
||||||
ErrCode string `xml:"err_code,omitempty"`
|
|
||||||
ErrCodeDes string `xml:"err_code_des,omitempty"`
|
|
||||||
MchBillno string `xml:"mch_billno,omitempty"`
|
|
||||||
MchID string `xml:"mch_id,omitempty"`
|
|
||||||
Wxappid string `xml:"wxappid"`
|
|
||||||
ReOpenID string `xml:"re_openid"`
|
|
||||||
TotalAmount int `xml:"total_amount"`
|
|
||||||
SendListid string `xml:"send_listid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendRedpacket 发放红包
|
|
||||||
func (redpacket *Redpacket) SendRedpacket(p *Params) (rsp *Response, err error) {
|
|
||||||
nonceStr := util.RandomStr(32)
|
|
||||||
param := make(map[string]string)
|
|
||||||
|
|
||||||
param["nonce_str"] = nonceStr
|
|
||||||
param["mch_id"] = redpacket.MchID
|
|
||||||
param["wxappid"] = redpacket.AppID
|
|
||||||
param["mch_billno"] = p.MchBillno
|
|
||||||
param["send_name"] = p.SendName
|
|
||||||
param["re_openid"] = p.ReOpenID
|
|
||||||
param["total_amount"] = strconv.Itoa(p.TotalAmount)
|
|
||||||
param["total_num"] = strconv.Itoa(p.TotalNum)
|
|
||||||
param["wishing"] = p.Wishing
|
|
||||||
param["client_ip"] = p.ClientIP
|
|
||||||
param["act_name"] = p.ActName
|
|
||||||
param["remark"] = p.Remark
|
|
||||||
//param["scene_id"] = "PRODUCT_2"
|
|
||||||
|
|
||||||
sign, err := util.ParamSign(param, redpacket.Key)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := request{
|
|
||||||
NonceStr: nonceStr,
|
|
||||||
Sign: sign,
|
|
||||||
MchID: redpacket.MchID,
|
|
||||||
Wxappid: redpacket.AppID,
|
|
||||||
MchBillno: p.MchBillno,
|
|
||||||
SendName: p.SendName,
|
|
||||||
ReOpenID: p.ReOpenID,
|
|
||||||
TotalAmount: p.TotalAmount,
|
|
||||||
TotalNum: p.TotalNum,
|
|
||||||
Wishing: p.Wishing,
|
|
||||||
ClientIP: p.ClientIP,
|
|
||||||
ActName: p.ActName,
|
|
||||||
Remark: p.Remark,
|
|
||||||
}
|
|
||||||
|
|
||||||
rawRet, err := util.PostXMLWithTLS(redpacketGateway, req, p.RootCa, redpacket.MchID)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = xml.Unmarshal(rawRet, &rsp)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if rsp.ReturnCode == "SUCCESS" {
|
|
||||||
if rsp.ResultCode == "SUCCESS" {
|
|
||||||
err = nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = fmt.Errorf("send redpacket error, errcode=%s,errmsg=%s", rsp.ErrCode, rsp.ErrCodeDes)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = fmt.Errorf("[msg : xmlUnmarshalError] [rawReturn : %s] [sign : %s]", string(rawRet), sign)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -13,8 +13,6 @@ const (
|
|||||||
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
|
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
|
||||||
// departmentListURL 获取部门列表
|
// departmentListURL 获取部门列表
|
||||||
departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s"
|
departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s"
|
||||||
// departmentGetURL 获取单个部门详情 https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=ACCESS_TOKEN&id=ID
|
|
||||||
departmentGetURL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%d"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -123,24 +121,3 @@ func (r *Client) DepartmentList() ([]*Department, error) {
|
|||||||
// 返回数据
|
// 返回数据
|
||||||
return result.Department, err
|
return result.Department, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DepartmentGet 获取单个部门详情
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/95351
|
|
||||||
func (r *Client) DepartmentGet(departmentID int) (*Department, error) {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.HTTPGet(fmt.Sprintf(departmentGetURL, accessToken, departmentID)); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &Department{}
|
|
||||||
if err = util.DecodeWithError(response, result, "DepartmentGet"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ type UserGetResponse struct {
|
|||||||
} `json:"external_profile"` // 成员对外属性,字段详情见对外属性;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
} `json:"external_profile"` // 成员对外属性,字段详情见对外属性;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserGet 读取成员
|
// UserGet 获取部门成员
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/90196
|
// @see https://developer.work.weixin.qq.com/document/path/90196
|
||||||
func (r *Client) UserGet(UserID string) (*UserGetResponse, error) {
|
func (r *Client) UserGet(UserID string) (*UserGetResponse, error) {
|
||||||
var (
|
var (
|
||||||
@@ -237,8 +237,8 @@ func (r *Client) UserGet(UserID string) (*UserGetResponse, error) {
|
|||||||
strings.Join([]string{
|
strings.Join([]string{
|
||||||
userGetURL,
|
userGetURL,
|
||||||
util.Query(map[string]interface{}{
|
util.Query(map[string]interface{}{
|
||||||
"access_token": accessToken,
|
"access_token": accessToken,
|
||||||
"userid": UserID,
|
"department_id": UserID,
|
||||||
}),
|
}),
|
||||||
}, "?")); err != nil {
|
}, "?")); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
package checkin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/silenceper/wechat/v2/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// getCheckinDataURL 获取打卡记录数据
|
|
||||||
getCheckinDataURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=%s"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// GetCheckinDataRequest 获取打卡记录数据请求
|
|
||||||
GetCheckinDataRequest struct {
|
|
||||||
OpenCheckinDataType int64 `json:"opencheckindatatype"`
|
|
||||||
StartTime int64 `json:"starttime"`
|
|
||||||
EndTime int64 `json:"endtime"`
|
|
||||||
UserIDList []string `json:"useridlist"`
|
|
||||||
}
|
|
||||||
// GetCheckinDataResponse 获取打卡记录数据响应
|
|
||||||
GetCheckinDataResponse struct {
|
|
||||||
util.CommonError
|
|
||||||
CheckinData []*GetCheckinDataItem `json:"checkindata"`
|
|
||||||
}
|
|
||||||
// GetCheckinDataItem 打卡记录数据
|
|
||||||
GetCheckinDataItem struct {
|
|
||||||
UserID string `json:"userid"`
|
|
||||||
GroupName string `json:"groupname"`
|
|
||||||
CheckinType string `json:"checkin_type"`
|
|
||||||
ExceptionType string `json:"exception_type"`
|
|
||||||
CheckinTime int64 `json:"checkin_time"`
|
|
||||||
LocationTitle string `json:"location_title"`
|
|
||||||
LocationDetail string `json:"location_detail"`
|
|
||||||
WifiName string `json:"wifiname"`
|
|
||||||
Notes string `json:"notes"`
|
|
||||||
WifiMac string `json:"wifimac"`
|
|
||||||
MediaIDs []string `json:"mediaids"`
|
|
||||||
SchCheckinTime int64 `json:"sch_checkin_time"`
|
|
||||||
GroupID int64 `json:"groupid"`
|
|
||||||
ScheduleID int64 `json:"schedule_id"`
|
|
||||||
TimelineID int64 `json:"timeline_id"`
|
|
||||||
Lat int64 `json:"lat,omitempty"`
|
|
||||||
Lng int64 `json:"lng,omitempty"`
|
|
||||||
DeviceID string `json:"deviceid,omitempty"`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetCheckinData 获取打卡记录数据
|
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/90262
|
|
||||||
func (r *Client) GetCheckinData(req *GetCheckinDataRequest) (*GetCheckinDataResponse, error) {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.PostJSON(fmt.Sprintf(getCheckinDataURL, accessToken), req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &GetCheckinDataResponse{}
|
|
||||||
if err = util.DecodeWithError(response, result, "GetCheckinData"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package checkin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/silenceper/wechat/v2/work/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Client 打卡接口实例
|
|
||||||
type Client struct {
|
|
||||||
*context.Context
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewClient 初始化实例
|
|
||||||
func NewClient(ctx *context.Context) *Client {
|
|
||||||
return &Client{
|
|
||||||
ctx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -70,7 +70,6 @@ type (
|
|||||||
GroupNickname string `json:"group_nickname"` //在群里的昵称
|
GroupNickname string `json:"group_nickname"` //在群里的昵称
|
||||||
Name string `json:"name"` //名字。仅当 need_name = 1 时返回 如果是微信用户,则返回其在微信中设置的名字 如果是企业微信联系人,则返回其设置对外展示的别名或实名
|
Name string `json:"name"` //名字。仅当 need_name = 1 时返回 如果是微信用户,则返回其在微信中设置的名字 如果是企业微信联系人,则返回其设置对外展示的别名或实名
|
||||||
UnionID string `json:"unionid,omitempty"` //外部联系人在微信开放平台的唯一身份标识(微信unionid),通过此字段企业可将外部联系人与公众号/小程序用户关联起来。仅当群成员类型是微信用户(包括企业成员未添加好友),且企业绑定了微信开发者ID有此字段(查看绑定方法)。第三方不可获取,上游企业不可获取下游企业客户的unionid字段
|
UnionID string `json:"unionid,omitempty"` //外部联系人在微信开放平台的唯一身份标识(微信unionid),通过此字段企业可将外部联系人与公众号/小程序用户关联起来。仅当群成员类型是微信用户(包括企业成员未添加好友),且企业绑定了微信开发者ID有此字段(查看绑定方法)。第三方不可获取,上游企业不可获取下游企业客户的unionid字段
|
||||||
State string `json:"state,omitempty"` //如果在配置入群方式时,配置了state参数,那么在获取客户群详情时,通过该方式入群的成员,会额外获取到相应的state参数
|
|
||||||
}
|
}
|
||||||
//GroupChatAdmin 群管理员
|
//GroupChatAdmin 群管理员
|
||||||
GroupChatAdmin struct {
|
GroupChatAdmin struct {
|
||||||
|
|||||||
@@ -1,359 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
@@ -11,8 +11,6 @@ const (
|
|||||||
uploadImgURL = "https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s"
|
uploadImgURL = "https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s"
|
||||||
// uploadTempFile 上传临时素材
|
// uploadTempFile 上传临时素材
|
||||||
uploadTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s"
|
uploadTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s"
|
||||||
// uploadAttachment 上传附件资源
|
|
||||||
uploadAttachment = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_attachment?access_token=%s&media_type=%s&attachment_type=%d"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// UploadImgResponse 上传图片响应
|
// UploadImgResponse 上传图片响应
|
||||||
@@ -29,14 +27,6 @@ type UploadTempFileResponse struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UploadAttachmentResponse 上传资源附件响应
|
|
||||||
type UploadAttachmentResponse struct {
|
|
||||||
util.CommonError
|
|
||||||
MediaID string `json:"media_id"`
|
|
||||||
CreateAt int64 `json:"created_at"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UploadImg 上传图片
|
// UploadImg 上传图片
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/90256
|
// @see https://developer.work.weixin.qq.com/document/path/90256
|
||||||
func (r *Client) UploadImg(filename string) (*UploadImgResponse, error) {
|
func (r *Client) UploadImg(filename string) (*UploadImgResponse, error) {
|
||||||
@@ -79,26 +69,3 @@ func (r *Client) UploadTempFile(filename string, mediaType string) (*UploadTempF
|
|||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UploadAttachment 上传附件资源
|
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/95098
|
|
||||||
// @mediaType 媒体文件类型,分别有图片(image)、视频(video)、普通文件(file)
|
|
||||||
// @attachment_type 附件类型,不同的附件类型用于不同的场景。1:朋友圈;2:商品图册
|
|
||||||
func (r *Client) UploadAttachment(filename string, mediaType string, attachmentType int) (*UploadAttachmentResponse, error) {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.PostFile("media", filename, fmt.Sprintf(uploadAttachment, accessToken, mediaType, attachmentType)); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &UploadAttachmentResponse{}
|
|
||||||
if err = util.DecodeWithError(response, result, "UploadAttachment"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"github.com/silenceper/wechat/v2/credential"
|
"github.com/silenceper/wechat/v2/credential"
|
||||||
"github.com/silenceper/wechat/v2/work/addresslist"
|
"github.com/silenceper/wechat/v2/work/addresslist"
|
||||||
"github.com/silenceper/wechat/v2/work/appchat"
|
"github.com/silenceper/wechat/v2/work/appchat"
|
||||||
"github.com/silenceper/wechat/v2/work/checkin"
|
|
||||||
"github.com/silenceper/wechat/v2/work/config"
|
"github.com/silenceper/wechat/v2/work/config"
|
||||||
"github.com/silenceper/wechat/v2/work/context"
|
"github.com/silenceper/wechat/v2/work/context"
|
||||||
"github.com/silenceper/wechat/v2/work/externalcontact"
|
"github.com/silenceper/wechat/v2/work/externalcontact"
|
||||||
@@ -86,8 +85,3 @@ func (wk *Work) GetAppChat() *appchat.Client {
|
|||||||
func (wk *Work) GetInvoice() *invoice.Client {
|
func (wk *Work) GetInvoice() *invoice.Client {
|
||||||
return invoice.NewClient(wk.ctx)
|
return invoice.NewClient(wk.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCheckin 获取打卡接口实例
|
|
||||||
func (wk *Work) GetCheckin() *checkin.Client {
|
|
||||||
return checkin.NewClient(wk.ctx)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user