package l_msg_api import ( "encoding/json" "fmt" "gitea.cdlsxd.cn/self-tools/l_msg_api/cache" "gitea.cdlsxd.cn/self-tools/l_msg_api/httpclient" "strings" ) func (m *MessageCenter) parseOACreateParam(formModel *FormsData) (out []byte) { req := formDataRequest{ Base: m.base, } req.FormComponentValues = formModel.FormComponentValues req.Finance = formModel.Finance req.FormBase = formModel.FormBase out, _ = json.Marshal(req) return } func (m *MessageCenter) parseSmsSendParam(tels []string, jsonParam string) (out []byte) { out, _ = json.Marshal(smsRequest{ Base: m.base, Tels: strings.Join(tels, ","), Param: jsonParam, }) return } func (m *MessageCenter) parseSendBlackBoardParam(title, content string, receiver blackboardReceiverView) (out []byte) { out, _ = json.Marshal(dingTalkBlackBoardSendReq{ Base: m.base, Content: content, Title: title, BlackboardReceiver: receiver, }) return } func (m *MessageCenter) getAccessToken() (string, error) { if tokenInterface, exist := cache.InstanceCacheMap().Get(m.ClientKey); exist { return tokenInterface.(string), nil } var data accessTokenResponse var authParam, _ = json.Marshal(map[string]string{"client_key": m.ClientKey, "client_secret": m.ClientSecret}) err := m.accessPost(accessToken, authParam, &data) if err != nil { return "", err } cache.InstanceCacheMap().Put(m.ClientKey, data.AccessToken) return data.AccessToken, err } func (m *MessageCenter) post(path string, data []byte, resReflect interface{}) (err error) { var body responseBody res, err := httpclient.FastHttpPost(fmt.Sprintf("%s%s", m.Host, path), m.header, data, timeOut) if err != nil { return } if err = json.Unmarshal(res, &body); err != nil { return fmt.Errorf("请求失败:%s", string(res)) } if body.Code != 0 { return fmt.Errorf("请求失败:%s", body.Msg) } dataByte, err := json.Marshal(body.Data) if err != nil { return fmt.Errorf("未知的返回格式:%s", string(dataByte)) } if err = json.Unmarshal(dataByte, &resReflect); err != nil { return fmt.Errorf("未知的返回格式:%s", string(dataByte)) } return } func (m *MessageCenter) accessPost(path string, data []byte, resReflect interface{}) (err error) { var body responseBody res, err := httpclient.FastHttpPost(fmt.Sprintf("%s%s", m.Host, path), m.header, data, timeOut) if err != nil { return } if err = json.Unmarshal(res, &body); err != nil { return fmt.Errorf("请求失败:%s", string(res)) } if body.Code != 0 { return fmt.Errorf("请求失败:%s", body.Msg) } dataByte, err := json.Marshal(body.Data) if err != nil { return fmt.Errorf("未知的返回格式:%s", string(dataByte)) } if err = json.Unmarshal(dataByte, &resReflect); err != nil { return fmt.Errorf("未知的返回格式:%s", string(dataByte)) } return }