This commit is contained in:
邹宗楠
2023-01-30 11:22:02 +08:00
parent 2dcecd6ff0
commit a67c57c92e
3 changed files with 83 additions and 2 deletions

View File

@@ -105,7 +105,7 @@ func TestCreateSession(t *testing.T) {
// 发送消息到企业微信
func TestSendMsg(t *testing.T) {
msg := &EnterpriseSendMsgReq{
Touser: "HeJiaMeng2",
Touser: "LiuLei",
Toparty: "",
Totag: "",
Msgtype: "textcard",
@@ -126,6 +126,6 @@ func TestSendMsg(t *testing.T) {
// 获取员工信息
func TestGetUserId(t *testing.T) {
phone, err := api.GetUserIdByMobile("15928865396")
phone, err := api.GetUserIdByMobile("18981810340")
globals.SugarLogger.Debugf("phone := %s,err :=%s", phone, err)
}

View File

@@ -0,0 +1,73 @@
package kuaishou_mini
import (
"encoding/json"
"fmt"
"git.rosy.net.cn/baseapi/platformapi"
"net/http"
"strings"
"sync"
)
const (
// KuaiShouBashUrl 基础域名
KuaiShouBashUrl = "https://open.kuaishou.com" // 域名
// 获取授权信息
KuaiShouAuthLogin = "oauth2/mp/code2session" // 授权登录
)
type API struct {
appSecret string // 应用唯一标识对应的密钥
appId string // 应用唯一标识
client *http.Client
config *platformapi.APIConfig
locker sync.RWMutex
msgToken string // accessToken
expiresIn int64 // 过期时间
}
func (a *API) GetAppID() string {
return a.appId
}
func (a *API) GetSecret() string {
return a.appSecret
}
// New 初始化
func New(appSecret, appId string, config ...*platformapi.APIConfig) *API {
curConfig := platformapi.DefAPIConfig
if len(config) > 0 {
curConfig = *config[0]
}
return &API{
appSecret: appSecret,
appId: appId,
client: &http.Client{Timeout: curConfig.ClientTimeout},
config: &curConfig,
}
}
// AccessAPI2 发送请求
func (a *API) AccessAPI2(url string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
data, err := json.Marshal(params)
if err != nil {
return nil, err
}
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodPost, url, strings.NewReader(string(data)))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
return request
},
a.config,
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
if jsonResult1 == nil {
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
}
retVal = jsonResult1
return platformapi.ErrLevelSuccess, nil
})
return retVal, err
}

View File

@@ -0,0 +1,8 @@
package kuaishou_mini
// AuthLoginKuaiShou 快手授权登录
func (a *API) AuthLoginKuaiShou(jsCode string) {
if a.appId == "" || a.appSecret == "" || jsCode == "" {
return
}
}