diff --git a/platformapi/enterprise_wechat/enterprise_test.go b/platformapi/enterprise_wechat/enterprise_test.go index fed76f52..e3dc6a05 100644 --- a/platformapi/enterprise_wechat/enterprise_test.go +++ b/platformapi/enterprise_wechat/enterprise_test.go @@ -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) } diff --git a/platformapi/kuaishou_mini/kuaishou_api.go b/platformapi/kuaishou_mini/kuaishou_api.go new file mode 100644 index 00000000..b2ad6c3d --- /dev/null +++ b/platformapi/kuaishou_mini/kuaishou_api.go @@ -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 +} diff --git a/platformapi/kuaishou_mini/kuaishou_login.go b/platformapi/kuaishou_mini/kuaishou_login.go new file mode 100644 index 00000000..9a600fd8 --- /dev/null +++ b/platformapi/kuaishou_mini/kuaishou_login.go @@ -0,0 +1,8 @@ +package kuaishou_mini + +// AuthLoginKuaiShou 快手授权登录 +func (a *API) AuthLoginKuaiShou(jsCode string) { + if a.appId == "" || a.appSecret == "" || jsCode == "" { + return + } +}