xiaoetech/main.go
2026-07-30 18:11:06 +08:00

64 lines
1.6 KiB
Go

package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"strings"
"xiaoetech/service"
"github.com/faabiosr/cachego/file"
)
const (
XiaoEAppId = "appru2yutaz8506" // 店铺app_id
XiaoEClientId = "xopKH8sWbrt9308" // 店铺client_id
XiaoEAppSecret = "APFvqtqs0qh2dphCPbDq9VgpMXhLiBc2" // 店铺client_sercet
XiaoEGrantType = "client_credential" // 固定不变
GetUserListOpenApi = "https://api.xiaoe-tech.com/xe.user.batch.get/2.0.0"
)
func main() {
xiaoE := &service.DefaultAccessTokenManager{
Id: XiaoEAppId,
Name: "access_token",
GetRefreshRequestFunc: func() *http.Request {
params := make(map[string]string)
params["app_id"] = XiaoEAppId
params["client_id"] = XiaoEClientId
params["secret_key"] = XiaoEAppSecret
params["grant_type"] = XiaoEGrantType
str, err := json.Marshal(params)
if err != nil {
fmt.Println(err)
}
payload := strings.NewReader(string(str))
req, err := http.NewRequest(http.MethodGet, service.AccessTokenUrl, payload)
if err != nil {
return nil
}
return req
},
// os.TempDir() - 设置缓存路径,默认为系统默认缓存路径,为了方便查找建议修改路径
Cache: file.New(os.TempDir()),
}
// 小鹅云 客户端
xiaoEClient := service.NewClient(xiaoE)
// 调用示例 不需要传入access_token
UserListParams := make(map[string]interface{})
UserListParams["page"] = 1
UserListParams["page_size"] = 2
resp, err := xiaoEClient.CurlDo(http.MethodPost, GetUserListOpenApi, UserListParams)
if err != nil {
fmt.Println("err: ", err)
}
fmt.Println(string(resp))
}