1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-05 21:22:27 +08:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Bryan
890e9fed43 企业微信 OAuth2:支持获取 ExternalUserID (#565) 2022-04-29 21:40:27 +08:00
Bryan
3cbc95732a 企业微信客服消息: 修复发送消息时 MsgID 为空会报错的问题 (#563) 2022-04-28 21:59:36 +08:00
bear
182339c00f 添加企业微信外部联系部分的 sdk (#562) 2022-04-27 23:50:28 +08:00
yucui xiao
e952b1d55a 微信小程序回调消息兼容json格式 (#560) 2022-04-26 15:59:51 +08:00
houseme
4b972c740f fix: ptr Elem() error (#561)
* [feature] Format the code and improve Mini Program authorization to obtain openid(miniprogram/auth/auth.go Code2Session)

* [feature] CheckEncryptedData (https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.checkEncryptedData.html)

* upgrade json error

* upgrade json error

* [feature] Wallet Transfer returns the pointer object

* feat:Adaptation of new go-redis components

* improve code

* feat:upgrade golangci-lint-action version

* fix

* test ci

* fix

* test ci

* fix

* test

* improve code

* feat:GetPhoneNumber return ptr

* fix: ptr Elem() error

* improve code

Co-authored-by: houseme <houseme@outlook.com>
2022-04-26 11:10:24 +08:00
13 changed files with 535 additions and 27 deletions

1
go.mod
View File

@@ -9,6 +9,7 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cast v1.4.1
github.com/stretchr/testify v1.7.1
github.com/tidwall/gjson v1.14.1
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
gopkg.in/h2non/gock.v1 v1.1.2
)

6
go.sum
View File

@@ -66,6 +66,12 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

View File

@@ -112,22 +112,24 @@ type PhoneInfo struct {
}
// GetPhoneNumber 小程序通过code获取用户手机号
func (auth *Auth) GetPhoneNumber(code string) (result *GetPhoneNumberResponse, err error) {
func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
var response []byte
var (
at string
at string
err error
)
if at, err = auth.GetAccessToken(); err != nil {
return
return nil, err
}
body := map[string]interface{}{
"code": code,
}
if response, err = util.PostJSON(fmt.Sprintf(getPhoneNumber, at), body); err != nil {
return
return nil, err
}
var result GetPhoneNumberResponse
if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
return
return nil, err
}
return
return &result, nil
}

View File

@@ -117,7 +117,7 @@ type MixMessage struct {
URL string `xml:"Url"`
// 事件相关
Event EventType `xml:"Event"`
Event EventType `xml:"Event" json:"Event"`
EventKey string `xml:"EventKey"`
Ticket string `xml:"Ticket"`
Latitude string `xml:"Latitude"`
@@ -149,6 +149,8 @@ type MixMessage struct {
Poiname string `xml:"Poiname"`
}
subscribeMsgPopupEventList []SubscribeMsgPopupEvent `json:"-"`
SubscribeMsgPopupEvent []struct {
List SubscribeMsgPopupEvent `xml:"List"`
} `xml:"SubscribeMsgPopupEvent"`
@@ -209,9 +211,26 @@ type MixMessage struct {
// SubscribeMsgPopupEvent 订阅通知事件推送的消息体
type SubscribeMsgPopupEvent struct {
TemplateID string `xml:"TemplateId"`
SubscribeStatusString string `xml:"SubscribeStatusString"`
PopupScene int `xml:"PopupScene"`
TemplateID string `xml:"TemplateId" json:"TemplateId"`
SubscribeStatusString string `xml:"SubscribeStatusString" json:"SubscribeStatusString"`
PopupScene int `xml:"PopupScene" json:"PopupScene,string"`
}
// SetSubscribeMsgPopupEvents 设置订阅消息事件
func (s *MixMessage) SetSubscribeMsgPopupEvents(list []SubscribeMsgPopupEvent) {
s.subscribeMsgPopupEventList = list
}
// GetSubscribeMsgPopupEvents 获取订阅消息事件数据
func (s *MixMessage) GetSubscribeMsgPopupEvents() []SubscribeMsgPopupEvent {
if s.subscribeMsgPopupEventList != nil {
return s.subscribeMsgPopupEventList
}
list := make([]SubscribeMsgPopupEvent, len(s.SubscribeMsgPopupEvent))
for i, item := range s.SubscribeMsgPopupEvent {
list[i] = item.List
}
return list
}
// EventPic 发图事件推送
@@ -248,10 +267,10 @@ func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
// CommonToken 消息中通用的结构
type CommonToken struct {
XMLName xml.Name `xml:"xml"`
ToUserName CDATA `xml:"ToUserName"`
FromUserName CDATA `xml:"FromUserName"`
CreateTime int64 `xml:"CreateTime"`
MsgType MsgType `xml:"MsgType"`
ToUserName CDATA `xml:"ToUserName" json:"ToUserName"`
FromUserName CDATA `xml:"FromUserName" json:"FromUserName"`
CreateTime int64 `xml:"CreateTime" json:"CreateTime"`
MsgType MsgType `xml:"MsgType" json:"MsgType"`
}
// SetToUserName set ToUserName

View File

@@ -1,6 +1,7 @@
package server
import (
"encoding/json"
"encoding/xml"
"errors"
"fmt"
@@ -9,13 +10,14 @@ import (
"reflect"
"runtime/debug"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
"github.com/silenceper/wechat/v2/officialaccount/context"
"github.com/silenceper/wechat/v2/officialaccount/message"
"github.com/silenceper/wechat/v2/util"
"github.com/tidwall/gjson"
)
// Server struct
@@ -35,10 +37,11 @@ type Server struct {
ResponseRawXMLMsg []byte
ResponseMsg interface{}
isSafeMode bool
random []byte
nonce string
timestamp int64
isSafeMode bool
isJSONContent bool
random []byte
nonce string
timestamp int64
}
// NewServer init
@@ -98,6 +101,10 @@ func (srv *Server) handleRequest() (reply *message.Reply, err error) {
srv.isSafeMode = true
}
//set request contentType
contentType := srv.Request.Header.Get("Content-Type")
srv.isJSONContent = strings.Contains(contentType, "application/json")
// set openID
srv.openID = srv.Query("openid")
@@ -125,9 +132,9 @@ func (srv *Server) getMessage() (interface{}, error) {
var rawXMLMsgBytes []byte
var err error
if srv.isSafeMode {
var encryptedXMLMsg message.EncryptedXMLMsg
if err := xml.NewDecoder(srv.Request.Body).Decode(&encryptedXMLMsg); err != nil {
return nil, fmt.Errorf("从body中解析xml失败,err=%v", err)
encryptedXMLMsg, dataErr := srv.getEncryptBody()
if dataErr != nil {
return nil, dataErr
}
// 验证消息签名
@@ -161,9 +168,48 @@ func (srv *Server) getMessage() (interface{}, error) {
return srv.parseRequestMessage(rawXMLMsgBytes)
}
func (srv *Server) getEncryptBody() (*message.EncryptedXMLMsg, error) {
var encryptedXMLMsg = &message.EncryptedXMLMsg{}
if srv.isJSONContent {
if err := json.NewDecoder(srv.Request.Body).Decode(encryptedXMLMsg); err != nil {
return nil, fmt.Errorf("从body中解析json失败,err=%v", err)
}
} else {
if err := xml.NewDecoder(srv.Request.Body).Decode(encryptedXMLMsg); err != nil {
return nil, fmt.Errorf("从body中解析xml失败,err=%v", err)
}
}
return encryptedXMLMsg, nil
}
func (srv *Server) parseRequestMessage(rawXMLMsgBytes []byte) (msg *message.MixMessage, err error) {
msg = &message.MixMessage{}
err = xml.Unmarshal(rawXMLMsgBytes, msg)
if !srv.isJSONContent {
err = xml.Unmarshal(rawXMLMsgBytes, msg)
return
}
//parse json
err = json.Unmarshal(rawXMLMsgBytes, msg)
if err != nil {
return
}
// nonstandard json, 目前小程序订阅消息返回数据格式不标准订阅消息模板单个List返回是对象多个List返回是数组。
if msg.MsgType == message.MsgTypeEvent {
listData := gjson.Get(string(rawXMLMsgBytes), "List")
if listData.IsObject() {
listItem := message.SubscribeMsgPopupEvent{}
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItem); parseErr != nil {
return msg, parseErr
}
msg.SetSubscribeMsgPopupEvents([]message.SubscribeMsgPopupEvent{listItem})
} else if listData.IsArray() {
listItems := make([]message.SubscribeMsgPopupEvent, 0)
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItems); parseErr != nil {
return msg, parseErr
}
msg.SetSubscribeMsgPopupEvents(listItems)
}
}
return
}

View File

@@ -0,0 +1,3 @@
### 企业微信 客户联系部分
相关文档正在梳理中...

View File

@@ -0,0 +1,17 @@
package externalcontact
import (
"github.com/silenceper/wechat/v2/work/context"
)
// Client 外部联系接口实例
type Client struct {
*context.Context
}
// NewClient 初始化实例
func NewClient(ctx *context.Context) *Client {
return &Client{
ctx,
}
}

View File

@@ -0,0 +1,177 @@
package externalcontact
import (
"encoding/json"
"fmt"
"github.com/silenceper/wechat/v2/util"
)
const (
// FetchExternalContactUserListURL 获取客户列表
FetchExternalContactUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list"
// FetchExternalContactUserDetailURL 获取客户详情
FetchExternalContactUserDetailURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get"
// FetchBatchExternalContactUserDetailURL 批量获取客户详情
FetchBatchExternalContactUserDetailURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/batch/get_by_user"
// UpdateUserRemarkURL 更新客户备注信息
UpdateUserRemarkURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remark"
)
// ExternalUserListResponse 外部联系人列表响应
type ExternalUserListResponse struct {
util.CommonError
ExternalUserID []string `json:"external_userid"`
}
// GetExternalUserList 获取客户列表
// @see https://developer.work.weixin.qq.com/document/path/92113
func (r *Client) GetExternalUserList(userID string) ([]string, error) {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return nil, err
}
var response []byte
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%v&userid=%v", FetchExternalContactUserListURL, accessToken, userID))
if err != nil {
return nil, err
}
var result ExternalUserListResponse
err = util.DecodeWithError(response, &result, "GetExternalUserList")
if err != nil {
return nil, err
}
return result.ExternalUserID, nil
}
// ExternalUserDetailResponse 外部联系人详情响应
type ExternalUserDetailResponse struct {
util.CommonError
ExternalUser
}
// ExternalUser 外部联系人
type ExternalUser struct {
ExternalUserID string `json:"external_userid"`
Name string `json:"name"`
Avatar string `json:"avatar"`
Type int64 `json:"type"`
Gender int64 `json:"gender"`
UnionID string `json:"unionid"`
Position string `json:"position"`
CorpName string `json:"corp_name"`
CorpFullName string `json:"corp_full_name"`
ExternalProfile string `json:"external_profile"`
FollowUser []FollowUser `json:"follow_user"`
NextCursor string `json:"next_cursor"`
}
// FollowUser 跟进用户(指企业内部用户)
type FollowUser struct {
UserID string `json:"userid"`
Remark string `json:"remark"`
Description string `json:"description"`
CreateTime string `json:"create_time"`
Tags []Tag `json:"tags"`
RemarkCorpName string `json:"remark_corp_name"`
RemarkMobiles []string `json:"remark_mobiles"`
OperUserID string `json:"oper_userid"`
AddWay int64 `json:"add_way"`
WeChatChannels WechatChannel `json:"wechat_channels"`
State string `json:"state"`
}
// Tag 已绑定在外部联系人的标签
type Tag struct {
GroupName string `json:"group_name"`
TagName string `json:"tag_name"`
Type int64 `json:"type"`
TagID string `json:"tag_id"`
}
// WechatChannel 视频号添加的场景
type WechatChannel struct {
NickName string `json:"nickname"`
Source string `json:"source"`
}
// GetExternalUserDetail 获取外部联系人详情
func (r *Client) GetExternalUserDetail(externalUserID string, nextCursor ...string) (*ExternalUser, error) {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return nil, err
}
var response []byte
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%v&external_userid=%v&cursor=%v", FetchExternalContactUserDetailURL, accessToken, externalUserID, nextCursor))
if err != nil {
return nil, err
}
var result ExternalUserDetailResponse
err = util.DecodeWithError(response, &result, "get_external_user_detail")
if err != nil {
return nil, err
}
return &result.ExternalUser, nil
}
// BatchGetExternalUserDetailsRequest 批量获取外部联系人详情请求
type BatchGetExternalUserDetailsRequest struct {
UserIDList []string `json:"userid_list"`
Cursor string `json:"cursor"`
}
// ExternalUserDetailListResponse 批量获取外部联系人详情响应
type ExternalUserDetailListResponse struct {
util.CommonError
ExternalContactList []ExternalUser `json:"external_contact_list"`
}
// BatchGetExternalUserDetails 批量获取外部联系人详情
func (r *Client) BatchGetExternalUserDetails(request BatchGetExternalUserDetailsRequest) ([]ExternalUser, error) {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return nil, err
}
var response []byte
jsonData, _ := json.Marshal(request)
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", FetchBatchExternalContactUserDetailURL, accessToken), string(jsonData))
if err != nil {
return nil, err
}
var result ExternalUserDetailListResponse
err = util.DecodeWithError(response, &result, "BatchGetExternalUserDetails")
if err != nil {
return nil, err
}
return result.ExternalContactList, nil
}
// UpdateUserRemarkRequest 修改客户备注信息请求体
type UpdateUserRemarkRequest struct {
UserID string `json:"userid"`
ExternalUserID string `json:"external_userid"`
Remark string `json:"remark"`
Description string `json:"description"`
RemarkCompany string `json:"remark_company"`
RemarkMobiles []string `json:"remark_mobiles"`
RemarkPicMediaid string `json:"remark_pic_mediaid"`
}
// UpdateUserRemark 修改客户备注信息
func (r *Client) UpdateUserRemark(request UpdateUserRemarkRequest) error {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return err
}
var response []byte
jsonData, _ := json.Marshal(request)
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", UpdateUserRemarkURL, accessToken), string(jsonData))
if err != nil {
return err
}
return util.DecodeWithCommonError(response, "UpdateUserRemark")
}

View File

@@ -0,0 +1,39 @@
package externalcontact
import (
"fmt"
"github.com/silenceper/wechat/v2/util"
)
const (
// FetchFollowUserListURL 获取配置了客户联系功能的成员列表
FetchFollowUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list"
)
// followerUserResponse 客户联系功能的成员列表响应
type followerUserResponse struct {
util.CommonError
FollowUser []string `json:"follow_user"`
}
//GetFollowUserList 获取配置了客户联系功能的成员列表
//@see https://developer.work.weixin.qq.com/document/path/92571
func (r *Client) GetFollowUserList() ([]string, error) {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return nil, err
}
var response []byte
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%s", FetchFollowUserListURL, accessToken))
if err != nil {
return nil, err
}
var result followerUserResponse
err = util.DecodeWithError(response, &result, "GetFollowUserList")
if err != nil {
return nil, err
}
return result.FollowUser, nil
}

191
work/externalcontact/tag.go Normal file
View File

@@ -0,0 +1,191 @@
package externalcontact
import (
"encoding/json"
"fmt"
"github.com/silenceper/wechat/v2/util"
)
const (
// GetCropTagURL 获取标签列表
GetCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list"
// AddCropTagURL 添加标签
AddCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag"
// EditCropTagURL 修改标签
EditCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_corp_tag"
// DelCropTagURL 删除标签
DelCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag"
// MarkCropTagURL 为客户打上、删除标签
MarkCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag"
)
// GetCropTagRequest 获取企业标签请求
type GetCropTagRequest struct {
TagID []string `json:"tag_id"`
GroupID []string `json:"group_id"`
}
// GetCropTagListResponse 获取企业标签列表响应
type GetCropTagListResponse struct {
util.CommonError
TagGroup []TagGroup `json:"tag_group"`
}
// TagGroup 企业标签组
type TagGroup struct {
GroupID string `json:"group_id"`
GroupName string `json:"group_name"`
CreateTime string `json:"create_time"`
GroupOrder int `json:"group_order"`
Deleted bool `json:"deleted"`
Tag []TagGroupTagItem `json:"tag"`
}
// TagGroupTagItem 企业标签内的子项
type TagGroupTagItem struct {
ID string `json:"id"`
Name string `json:"name"`
CreateTime int `json:"create_time"`
Order int `json:"order"`
Deleted bool `json:"deleted"`
}
// GetCropTagList 获取企业标签库
// @see https://developer.work.weixin.qq.com/document/path/92117
func (r *Client) GetCropTagList(req GetCropTagRequest) ([]TagGroup, error) {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return nil, err
}
var response []byte
jsonData, _ := json.Marshal(req)
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", GetCropTagURL, accessToken), string(jsonData))
if err != nil {
return nil, err
}
var result GetCropTagListResponse
err = util.DecodeWithError(response, &result, "GetCropTagList")
if err != nil {
return nil, err
}
return result.TagGroup, nil
}
// AddCropTagRequest 添加企业标签请求
type AddCropTagRequest struct {
GroupID string `json:"group_id"`
GroupName string `json:"group_name"`
Order int `json:"order"`
Tag []AddCropTagItem `json:"tag"`
AgentID int `json:"agentid"`
}
// AddCropTagItem 添加企业标签子项
type AddCropTagItem struct {
Name string `json:"name"`
Order int `json:"order"`
}
// AddCropTagResponse 添加企业标签响应
type AddCropTagResponse struct {
util.CommonError
TagGroup TagGroup `json:"tag_group"`
}
// AddCropTag 添加企业客户标签
// @see https://developer.work.weixin.qq.com/document/path/92117
func (r *Client) AddCropTag(req AddCropTagRequest) (*TagGroup, error) {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return nil, err
}
var response []byte
jsonData, _ := json.Marshal(req)
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", AddCropTagURL, accessToken), string(jsonData))
if err != nil {
return nil, err
}
var result AddCropTagResponse
err = util.DecodeWithError(response, &result, "AddCropTag")
if err != nil {
return nil, err
}
return &result.TagGroup, nil
}
// EditCropTagRequest 编辑客户企业标签请求
type EditCropTagRequest struct {
ID string `json:"id"`
Name string `json:"name"`
Order int `json:"order"`
AgentID string `json:"agent_id"`
}
// EditCropTag 修改企业客户标签
// @see https://developer.work.weixin.qq.com/document/path/92117
func (r *Client) EditCropTag(req EditCropTagRequest) error {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return err
}
var response []byte
jsonData, _ := json.Marshal(req)
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", EditCropTagURL, accessToken), string(jsonData))
if err != nil {
return err
}
return util.DecodeWithCommonError(response, "EditCropTag")
}
// DeleteCropTagRequest 删除企业标签请求
type DeleteCropTagRequest struct {
TagID []string `json:"tag_id"`
GroupID []string `json:"group_id"`
AgentID string `json:"agent_id"`
}
// DeleteCropTag 删除企业客户标签
// @see https://developer.work.weixin.qq.com/document/path/92117
func (r *Client) DeleteCropTag(req DeleteCropTagRequest) error {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return err
}
var response []byte
jsonData, _ := json.Marshal(req)
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", DelCropTagURL, accessToken), string(jsonData))
if err != nil {
return err
}
return util.DecodeWithCommonError(response, "DeleteCropTag")
}
// MarkTagRequest 给客户打标签请求
type MarkTagRequest struct {
UserID string `json:"user_id"`
ExternalUserID string `json:"external_userid"`
AddTag []string `json:"add_tag"`
RemoveTag []string `json:"remove_tag"`
}
// MarkTag 为客户打上标签
// @see https://developer.work.weixin.qq.com/document/path/92118
func (r *Client) MarkTag(request MarkTagRequest) error {
var accessToken string
accessToken, err := r.GetAccessToken()
if err != nil {
return err
}
var response []byte
jsonData, _ := json.Marshal(request)
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", MarkCropTagURL, accessToken), string(jsonData))
if err != nil {
return err
}
return util.DecodeWithCommonError(response, "MarkTag")
}

View File

@@ -2,9 +2,9 @@ package sendmsg
// Message 发送消息
type Message struct {
ToUser string `json:"touser"` // 指定接收消息的客户UserID
OpenKFID string `json:"open_kfid"` // 指定发送消息的客服帐号ID
MsgID string `json:"msgid"` // 指定消息ID
ToUser string `json:"touser"` // 指定接收消息的客户UserID
OpenKFID string `json:"open_kfid"` // 指定发送消息的客服帐号ID
MsgID string `json:"msgid,omitempty"` // 指定消息ID
}
// Text 发送文本消息

View File

@@ -61,7 +61,8 @@ type ResUserInfo struct {
UserID string `json:"UserId"`
DeviceID string `json:"DeviceId"`
// 非企业成员授权时返回
OpenID string `json:"OpenId"`
OpenID string `json:"OpenId"`
ExternalUserID string `json:"external_userid"`
}
// UserFromCode 根据code获取用户信息

View File

@@ -4,6 +4,7 @@ import (
"github.com/silenceper/wechat/v2/credential"
"github.com/silenceper/wechat/v2/work/config"
"github.com/silenceper/wechat/v2/work/context"
"github.com/silenceper/wechat/v2/work/externalcontact"
"github.com/silenceper/wechat/v2/work/kf"
"github.com/silenceper/wechat/v2/work/msgaudit"
"github.com/silenceper/wechat/v2/work/oauth"
@@ -43,3 +44,8 @@ func (wk *Work) GetMsgAudit() (*msgaudit.Client, error) {
func (wk *Work) GetKF() (*kf.Client, error) {
return kf.NewClient(wk.ctx.Config)
}
// GetExternalContact get external_contact
func (wk *Work) GetExternalContact() *externalcontact.Client {
return externalcontact.NewClient(wk.ctx)
}