diff --git a/config.go b/config.go index ffd5607..bdb284d 100644 --- a/config.go +++ b/config.go @@ -31,7 +31,7 @@ type ( } FormsData struct { - formBase + FormBase FormComponentValues []FormComponentValues `json:"form_component_values"` // 审批表单数据 Finance *Finance `json:"finance"` // 财务模块调用 } @@ -64,7 +64,7 @@ type ( } // 创建OA基础数据 - formBase struct { + FormBase struct { OutTradeNo string `json:"out_trade_no"` // 流水号 OriginatorUserId string `json:"originator_user_id"` // 钉钉申请人id } diff --git a/const.go b/const.go index fd66466..c114602 100644 --- a/const.go +++ b/const.go @@ -1,8 +1,8 @@ package l_msg_api const ( - ServerHost = "http://127.0.0.1:8001" - TimeOut = 80000000 + serverHost = "http://127.0.0.1:8001" + timeOut = 60 ) const ( @@ -14,9 +14,9 @@ const ( ) const ( - AccessToken = "/oauth/v1/accesstoken" - OaCreat = "/msg/v1/dingtalk/oa/create" - OaGet = "/msg/v1/dingtalk/oa/get" - OaComment = "/msg/v1/dingtalk/oa/comment" - SendSms = "/msg/v1/sms/send" + accessToken = "/oauth/v1/accesstoken" + oaCreat = "/msg/v1/dingtalk/oa/create" + oaGet = "/msg/v1/dingtalk/oa/get" + oaComment = "/msg/v1/dingtalk/oa/comment" + sendSms = "/msg/v1/sms/send" ) diff --git a/msg.go b/msg.go index 9591b30..ea80a67 100644 --- a/msg.go +++ b/msg.go @@ -31,9 +31,9 @@ func NewMessageCenter(host, clientKey, clientSecret, serverIndex, tempIndex stri // 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) + formModel.FormBase.OutTradeNo = treadNo + formModel.FormBase.OriginatorUserId = dTalkUserId + err = m.post(oaCreat, m.parseOACreateParam(formModel), &data) if err != nil { return } @@ -46,7 +46,7 @@ func (m *MessageCenter) OAGetDetail(outTradeNo string) (data OAGetDetailData, er Base: m.base, OutTradeNo: outTradeNo, }) - err = m.post(OaGet, param, &data) + err = m.post(oaGet, param, &data) if err != nil { return } @@ -56,7 +56,7 @@ func (m *MessageCenter) OAGetDetail(outTradeNo string) (data OAGetDetailData, er // SendSms 短信 func (m *MessageCenter) SendSms(tels []string, jsonParam string) (data SmsSend, err error) { param := m.parseSmsSendParam(tels, jsonParam) - err = m.post(SendSms, param, &data) + err = m.post(sendSms, param, &data) if err != nil { return } @@ -73,7 +73,7 @@ func (m *MessageCenter) SendBlackBoard(title, content string, deptidList []int, receiver := blackboardReceiverView{ deptidList, useridList, } - err = m.post(SendSms, m.parseSendBlackBoardParam(title, content, receiver), &data) + err = m.post(sendSms, m.parseSendBlackBoardParam(title, content, receiver), &data) if err != nil { return } @@ -93,7 +93,7 @@ func (m *MessageCenter) OAComment(outTradeNo, text, commentUserId string, file * } param, _ := json.Marshal(req) - err = m.post(OaComment, param, &data) + err = m.post(oaComment, param, &data) if err != nil { return } diff --git a/paramset.go b/paramset.go index bd78477..ba11947 100644 --- a/paramset.go +++ b/paramset.go @@ -14,7 +14,7 @@ func (m *MessageCenter) parseOACreateParam(formModel *FormsData) (out []byte) { } req.FormComponentValues = formModel.FormComponentValues req.Finance = formModel.Finance - req.formBase = formModel.formBase + req.FormBase = formModel.FormBase out, _ = json.Marshal(req) return } @@ -45,7 +45,7 @@ func (m *MessageCenter) getAccessToken() (string, error) { var data accessTokenResponse var authParam, _ = json.Marshal(map[string]string{"client_key": m.ClientKey, "client_secret": m.ClientSecret}) - err := m.accessPost(AccessToken, authParam, &data) + err := m.accessPost(accessToken, authParam, &data) if err != nil { return "", err } @@ -55,7 +55,7 @@ func (m *MessageCenter) getAccessToken() (string, error) { 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) + res, err := httpclient.FastHttpPost(fmt.Sprintf("%s%s", m.Host, path), m.header, data, timeOut) if err != nil { return } @@ -79,7 +79,7 @@ func (m *MessageCenter) post(path string, data []byte, resReflect interface{}) ( 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) + res, err := httpclient.FastHttpPost(fmt.Sprintf("%s%s", m.Host, path), m.header, data, timeOut) if err != nil { return } diff --git a/test/msg_test.go b/test/msg_test.go index e8645e1..4623952 100644 --- a/test/msg_test.go +++ b/test/msg_test.go @@ -1,6 +1,7 @@ package test import ( + "context" "fmt" "gitea.cdlsxd.cn/self-tools/l_msg_api" "testing" @@ -9,10 +10,11 @@ import ( const ( ClientKey = "ymt" ClientSecret = "ymt" + serverHost = "http://127.0.0.1:8001" ) func TestSms(t *testing.T) { - msg, err := l_msg_api.NewMessageCenter(ClientKey, ClientSecret, "smssass", "sasssms") + msg, err := l_msg_api.NewMessageCenter(serverHost, ClientKey, ClientSecret, "smssass", "sasssms") if err != nil { panic(err) } @@ -23,7 +25,7 @@ func TestSms(t *testing.T) { } func TestOaCreate(t *testing.T) { - msg, err := l_msg_api.NewMessageCenter(ClientKey, ClientSecret, "sw_oa", "sw_oa_purchase") + msg, err := l_msg_api.NewMessageCenter(serverHost, ClientKey, ClientSecret, "sw_oa", "sw_oa_purchase") if err != nil { panic(err) } @@ -59,10 +61,15 @@ func TestOaCreate(t *testing.T) { } func TestOaComment(t *testing.T) { - msg, err := l_msg_api.NewMessageCenter(ClientKey, ClientSecret, "sw_oa", "sw_oa_purchase") + msg, err := l_msg_api.NewMessageCenter(serverHost, ClientKey, ClientSecret, "sw_oa", "sw_oa_purchase") if err != nil { panic(err) } res, err := msg.OAComment("P24110515152043136-20250318181554", "sdk测试", "", nil) fmt.Println(res, err) } + +func TestContext(*testing.T) { + c := context.Background() + c.Done() +}