| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package xnet
- import (
- "encoding/json"
- "gcore/core"
- "log"
- "net/http"
- )
- type DevConf struct {
- AppKey string
- AppSecret string
- GetTokenUrl string
- GetDeptUserListUrl string
- Token string
- Params map[string]string
- Headers map[string]string
- Cookie []*http.Cookie
- DeptId int
- }
- // @title GetToken
- // @description 获取access token
- // @param
- // @return
- func (m *DevConf) GetToken() error {
- params := map[string]string{"appkey": m.AppKey, "appsecret": m.AppSecret}
- content, err := GetX(m.GetTokenUrl, params, m.Headers, m.Cookie)
- if err != nil {
- log.Printf("GetToken error : %v", err)
- }
- //fmt.Printf("%v\n", content)
- ret := map[string]interface{}{}
- err = json.Unmarshal([]byte(content), &ret)
- if err != nil {
- log.Printf("Unmarshal error : %v", err)
- return err
- }
- m.Token = ret["access_token"].(string)
- m.Params["access_token"] = ret["access_token"].(string)
- m.Headers["Content-Type"] = "application/json"
- return nil
- }
- // @title GetDeptUserList
- // @description 获取部门成员的姓名和userid
- // @param
- // @return
- func (m *DevConf) GetDeptUserList() (deptUserList []map[string]string, err error) {
- cursor := 0
- size := 100
- for {
- data := map[string]interface{}{
- "dept_id": m.DeptId,
- "cursor": cursor,
- "size": size,
- }
- content, err := PostJson(m.GetDeptUserListUrl, m.Params, m.Headers, data, m.Cookie)
- if err != nil {
- log.Printf("GetToken error : %v", err)
- continue
- }
- ret := map[string]interface{}{}
- err = json.Unmarshal([]byte(content), &ret)
- if err != nil {
- log.Printf("Unmarshal error : %v", err)
- continue
- }
- result := ret["result"]
- for _, i := range result.(map[string]interface{})["list"].([]interface{}) {
- tmpData := core.StringInterfaceToStringString(i.(map[string]interface{}))
- deptUserList = append(deptUserList, tmpData)
- }
- //当前请求返回数据量小于size,跳出循环
- if len(result.(map[string]interface{})["list"].([]interface{})) < size {
- break
- }
- data["curosr"] = result.(map[string]interface{})["next_cursor"].(int64)
- }
- return
- }
- // @title GetDeptAttendanceData
- // @description 30天内部门考勤数据
- // @param
- // @return
- func GetDeptAttendanceData() {
- }
|