aa
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
package qywxapi
|
package qywxapi
|
||||||
|
|
||||||
import "encoding/json"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
)
|
||||||
|
|
||||||
func (a *API) GetProviderToken() (token string, err error) {
|
func (a *API) GetProviderToken() (token string, err error) {
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
@@ -14,3 +18,71 @@ func (a *API) GetProviderToken() (token string, err error) {
|
|||||||
}
|
}
|
||||||
return token, err
|
return token, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) GetToken() (token string, err error) {
|
||||||
|
result, err := a.AccessAPI(fmt.Sprintf("cgi-bin/gettoken?corpid=%s&corpsecret=%s", a.appID, a.secret), "", false)
|
||||||
|
if result["access_token"] != "" {
|
||||||
|
return result["access_token"].(string), err
|
||||||
|
}
|
||||||
|
return token, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type GroupchatListResult struct {
|
||||||
|
Errcode int `json:"errcode"`
|
||||||
|
Errmsg string `json:"errmsg"`
|
||||||
|
GroupChatList []struct {
|
||||||
|
ChatID string `json:"chat_id"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
} `json:"group_chat_list"`
|
||||||
|
NextCursor string `json:"next_cursor"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取客户群列表
|
||||||
|
func (a *API) GroupchatList(cursor string, limit int) (groupchatListResult *GroupchatListResult, err error) {
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"limit": limit,
|
||||||
|
"cursor": cursor,
|
||||||
|
}
|
||||||
|
str, _ := json.Marshal(params)
|
||||||
|
result, err := a.AccessAPI(fmt.Sprintf("cgi-bin/externalcontact/groupchat/list?access_token=%s", a.token), string(str), true)
|
||||||
|
if err == nil {
|
||||||
|
utils.Map2StructByJson(result, &groupchatListResult, false)
|
||||||
|
}
|
||||||
|
return groupchatListResult, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type GroupchatResutl struct {
|
||||||
|
Errcode int `json:"errcode"`
|
||||||
|
Errmsg string `json:"errmsg"`
|
||||||
|
GroupChat struct {
|
||||||
|
ChatID string `json:"chat_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
CreateTime int `json:"create_time"`
|
||||||
|
MemberList []struct {
|
||||||
|
Userid string `json:"userid"`
|
||||||
|
Type int `json:"type"`
|
||||||
|
JoinTime int `json:"join_time"`
|
||||||
|
JoinScene int `json:"join_scene"`
|
||||||
|
UnionID string `json:"unionid"`
|
||||||
|
Invitor struct {
|
||||||
|
Userid string `json:"userid"`
|
||||||
|
} `json:"invitor,omitempty"`
|
||||||
|
State string `json:"state,omitempty"`
|
||||||
|
} `json:"member_list"`
|
||||||
|
AdminList []interface{} `json:"admin_list"`
|
||||||
|
} `json:"group_chat"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取客户群详情
|
||||||
|
func (a *API) Groupchat(chat_id string) (groupchatListResult *GroupchatResutl, err error) {
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"chat_id": chat_id,
|
||||||
|
}
|
||||||
|
str, _ := json.Marshal(params)
|
||||||
|
result, err := a.AccessAPI(fmt.Sprintf("cgi-bin/externalcontact/groupchat/get?access_token=%s", a.token), string(str), true)
|
||||||
|
if err == nil {
|
||||||
|
utils.Map2StructByJson(result, &groupchatListResult, false)
|
||||||
|
}
|
||||||
|
return groupchatListResult, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package qywxapi
|
package qywxapi
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestGetProviderToken(t *testing.T) {
|
func TestGetProviderToken(t *testing.T) {
|
||||||
result, err := api.GetProviderToken()
|
result, err := api.GetProviderToken()
|
||||||
@@ -9,3 +12,30 @@ func TestGetProviderToken(t *testing.T) {
|
|||||||
}
|
}
|
||||||
sugarLogger.Debug(result)
|
sugarLogger.Debug(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestToken(t *testing.T) {
|
||||||
|
result, err := api.GetToken()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
sugarLogger.Debug(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGroupchatList(t *testing.T) {
|
||||||
|
result, err := api.GroupchatList("", 20)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGroupchat(t *testing.T) {
|
||||||
|
//wr0oKiEAAAw0osTU89uH7mtEg6YqzQ3A
|
||||||
|
//wr0oKiEAAAmSw5HwLHZQIb29yR6We_lg
|
||||||
|
//wr0oKiEAAAAi7dreYASbygbXrWtNxbNg
|
||||||
|
result, err := api.Groupchat("wr0oKiEAAAAi7dreYASbygbXrWtNxbNg")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ func New(appID, secret, token string, config ...*platformapi.APIConfig) *API {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) SetToken(token string) {
|
||||||
|
a.token = token
|
||||||
|
}
|
||||||
|
|
||||||
func (a *API) AccessAPI(action string, body string, isPost bool) (retVal map[string]interface{}, err error) {
|
func (a *API) AccessAPI(action string, body string, isPost bool) (retVal map[string]interface{}, err error) {
|
||||||
fullURL := utils.GenerateGetURL(prodURL, action, nil)
|
fullURL := utils.GenerateGetURL(prodURL, action, nil)
|
||||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ func init() {
|
|||||||
sugarLogger = logger.Sugar()
|
sugarLogger = logger.Sugar()
|
||||||
baseapi.Init(sugarLogger)
|
baseapi.Init(sugarLogger)
|
||||||
|
|
||||||
api = New("ww9a156bfa070e1857", "VlOJSlXw6TJRzYaUax-lIY8smcCIvfDe-ZZoIsYu7vfRYGIdhfs3UQCmB0papgk9", "")
|
api = New("ww9a156bfa070e1857", "q6H6WFV-c7gyyfBaxLxilIzeJv_mGk1CXtPqUR5qm4E", "cfHqzPxhClCnneMfhFtJVnY1ySVNs1B1Z4QZa130j5qFcLx1BUQJuEFuUdnKNdWqrWZaN3ElqKugY5kCxG3MONXtvzvAfzcJVH10RbNNq8sGCbZEaB7oMld-mrl2VZH4pqBlbWGfGfy7dj57FE0Uf900511PSM4X6QwmdKk9zHYCZLntR9ZoLi21BiW7zj_op50weRc_PGP98ciuCKM6lA")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user