l_msg_api/msg.go

102 lines
2.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package l_msg_api
import (
"encoding/json"
)
type MessageCenter struct {
Host string // 消息中心地址
ClientKey string // 客户端id,获取授权token需要
ClientSecret string
header map[string]string
base
}
func NewMessageCenter(host, clientKey, clientSecret, serverIndex, tempIndex string) (*MessageCenter, error) {
msg := &MessageCenter{
Host: host,
ClientKey: clientKey,
ClientSecret: clientSecret,
base: base{
ServerIndex: serverIndex,
TempIndex: tempIndex,
},
}
msg.header = map[string]string{"content-type": "application/json; charset=utf-8"}
accessToken, err := msg.getAccessToken()
msg.header = map[string]string{"Authorization": accessToken, "content-type": "application/json; charset=utf-8"}
return msg, err
}
// OACreate 发起OA审批
func (m *MessageCenter) OACreate(dTalkUserId, treadNo string, formModel *FormsData) (data OAResponse, err error) {
formModel.FormBase.OutTradeNo = treadNo
formModel.FormBase.OriginatorUserId = dTalkUserId
err = m.post(oaCreat, m.parseOACreateParam(formModel), &data)
if err != nil {
return
}
return
}
// OAGetDetail OA详情
func (m *MessageCenter) OAGetDetail(outTradeNo string) (data OAGetDetailData, err error) {
param, _ := json.Marshal(oAGetDetailRequest{
Base: m.base,
OutTradeNo: outTradeNo,
})
err = m.post(oaGet, param, &data)
if err != nil {
return
}
return
}
// SendSms 短信
func (m *MessageCenter) SendSms(tels []string, jsonParam string) (data SmsSend, err error) {
param := m.parseSmsSendParam(tels, jsonParam)
err = m.post(sendSms, param, &data)
if err != nil {
return
}
return
}
// BlackboardReceiverView struct {
// }
// SendBlackBoard 钉钉公告
// deptidList //接收部门ID列表最大的列表长度为20。
// UseridList //接收部用户ID列表最大的列表长度为20。
func (m *MessageCenter) SendBlackBoard(title, content string, deptidList []int, useridList []string) (data Default, err error) {
receiver := blackboardReceiverView{
deptidList, useridList,
}
err = m.post(sendSms, m.parseSendBlackBoardParam(title, content, receiver), &data)
if err != nil {
return
}
return
}
// OAComment OA评论,CommentUserId为空则默认审核发起人评论
func (m *MessageCenter) OAComment(outTradeNo, text, commentUserId string, file *DingOACommentReqFile) (data OAResponse, err error) {
req := &oACommentRequest{
Base: m.base,
OutTradeNo: outTradeNo,
Text: text,
CommentUserId: commentUserId,
}
if file != nil {
req.File = *file
}
param, _ := json.Marshal(req)
err = m.post(oaComment, param, &data)
if err != nil {
return
}
return
}