Compare commits
No commits in common. "v1" and "v1.7.0" have entirely different histories.
|
@ -31,7 +31,7 @@ type (
|
|||
}
|
||||
|
||||
FormsData struct {
|
||||
formBase
|
||||
FormBase
|
||||
FormComponentValues []FormComponentValues `json:"form_component_values"` // 审批表单数据
|
||||
Finance *Finance `json:"finance"` // 财务模块调用
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ type (
|
|||
}
|
||||
|
||||
// 创建OA基础数据
|
||||
formBase struct {
|
||||
FormBase struct {
|
||||
OutTradeNo string `json:"out_trade_no"` // 流水号
|
||||
OriginatorUserId string `json:"originator_user_id"` // 钉钉申请人id
|
||||
}
|
||||
|
|
39
const.go
39
const.go
|
@ -13,39 +13,10 @@ const (
|
|||
DDDateField = "DDDateField"
|
||||
)
|
||||
|
||||
type RequestPath string
|
||||
|
||||
const (
|
||||
accessToken RequestPath = "/oauth/v1/accesstoken"
|
||||
oaCreat RequestPath = "/msg/v1/dingtalk/oa/create"
|
||||
oaGet RequestPath = "/msg/v1/dingtalk/oa/get"
|
||||
oaComment RequestPath = "/msg/v1/dingtalk/oa/comment"
|
||||
sendSms RequestPath = "/msg/v1/sms/send"
|
||||
sendSmsHs RequestPath = "/msg/v1/sms/send/hs"
|
||||
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"
|
||||
)
|
||||
|
||||
type SmsBusiness string
|
||||
|
||||
const (
|
||||
SmsBusinessHs SmsBusiness = "hs"
|
||||
SmsBusinessDefault SmsBusiness = "aliyun"
|
||||
)
|
||||
|
||||
var smsBusinessWithRequestPath = map[SmsBusiness]RequestPath{
|
||||
SmsBusinessHs: sendSmsHs,
|
||||
SmsBusinessDefault: sendSms,
|
||||
}
|
||||
|
||||
type (
|
||||
SmsOption func(*SmsOptionData)
|
||||
SmsOptionData struct {
|
||||
Business SmsBusiness
|
||||
}
|
||||
)
|
||||
|
||||
func WithBusiness(business SmsBusiness) SmsOption {
|
||||
|
||||
return func(OptionData *SmsOptionData) {
|
||||
OptionData.Business = business
|
||||
}
|
||||
}
|
||||
|
|
39
msg.go
39
msg.go
|
@ -2,7 +2,6 @@ package l_msg_api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type MessageCenter struct {
|
||||
|
@ -24,18 +23,16 @@ func NewMessageCenter(host, clientKey, clientSecret, serverIndex, tempIndex stri
|
|||
},
|
||||
}
|
||||
msg.header = map[string]string{"content-type": "application/json; charset=utf-8"}
|
||||
token, err := msg.getAccessToken()
|
||||
msg.header = map[string]string{"Authorization": token, "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 = formBase{
|
||||
OutTradeNo: treadNo,
|
||||
OriginatorUserId: dTalkUserId,
|
||||
}
|
||||
formModel.FormBase.OutTradeNo = treadNo
|
||||
formModel.FormBase.OriginatorUserId = dTalkUserId
|
||||
err = m.post(oaCreat, m.parseOACreateParam(formModel), &data)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -57,36 +54,18 @@ func (m *MessageCenter) OAGetDetail(outTradeNo string) (data OAGetDetailData, er
|
|||
}
|
||||
|
||||
// SendSms 短信
|
||||
// business SmsBusiness
|
||||
func (m *MessageCenter) SendSms(tels []string, jsonParam string, args ...SmsOption) (data SmsSend, err error) {
|
||||
var (
|
||||
e = new(SmsOptionData)
|
||||
)
|
||||
if len(tels) == 0 {
|
||||
err = errors.New("手机号不能为空")
|
||||
return
|
||||
}
|
||||
for _, arg := range args {
|
||||
arg(e)
|
||||
}
|
||||
if e.Business != "" {
|
||||
if _, ex := smsBusinessWithRequestPath[e.Business]; !ex {
|
||||
err = errors.New("business参数错误")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
e.Business = SmsBusinessDefault
|
||||
}
|
||||
path := smsBusinessWithRequestPath[e.Business]
|
||||
|
||||
func (m *MessageCenter) SendSms(tels []string, jsonParam string) (data SmsSend, err error) {
|
||||
param := m.parseSmsSendParam(tels, jsonParam)
|
||||
err = m.post(path, param, &data)
|
||||
err = m.post(sendSms, param, &data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BlackboardReceiverView struct {
|
||||
|
||||
// }
|
||||
// SendBlackBoard 钉钉公告
|
||||
// deptidList //接收部门ID列表,最大的列表长度为20。
|
||||
// UseridList //接收部用户ID列表,最大的列表长度为20。
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func (m *MessageCenter) getAccessToken() (string, error) {
|
|||
return data.AccessToken, err
|
||||
}
|
||||
|
||||
func (m *MessageCenter) post(path RequestPath, data []byte, resReflect interface{}) (err 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)
|
||||
if err != nil {
|
||||
|
@ -77,7 +77,7 @@ func (m *MessageCenter) post(path RequestPath, data []byte, resReflect interface
|
|||
return
|
||||
}
|
||||
|
||||
func (m *MessageCenter) accessPost(path RequestPath, data []byte, resReflect interface{}) (err error) {
|
||||
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 {
|
||||
|
|
|
@ -10,8 +10,7 @@ import (
|
|||
const (
|
||||
ClientKey = "ymt"
|
||||
ClientSecret = "ymt"
|
||||
serverHost = "http://120.55.12.245:8200"
|
||||
local = "http://127.0.0.1:8001"
|
||||
serverHost = "http://127.0.0.1:8001"
|
||||
)
|
||||
|
||||
func TestSms(t *testing.T) {
|
||||
|
@ -26,7 +25,7 @@ func TestSms(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOaCreate(t *testing.T) {
|
||||
msg, err := l_msg_api.NewMessageCenter(local, 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)
|
||||
}
|
||||
|
@ -38,7 +37,7 @@ func TestOaCreate(t *testing.T) {
|
|||
{Name: "采购总金额", Value: "11.22"},
|
||||
{Name: "预计到货时间", Value: "2025-03-21"},
|
||||
}
|
||||
res, err := msg.OACreate("17101201090101570", "cxvxvxcgfgfvxvxv", &l_msg_api.FormsData{
|
||||
res, err := msg.OACreate("17101201090101570", "123456789123bgff", &l_msg_api.FormsData{
|
||||
FormComponentValues: form,
|
||||
Finance: &l_msg_api.Finance{
|
||||
Amount: "11.22",
|
||||
|
@ -49,8 +48,6 @@ func TestOaCreate(t *testing.T) {
|
|||
CallbackUrl: "www.baidu.com",
|
||||
Remark: "测试备注",
|
||||
Sync: 1,
|
||||
SystemName: "货易通",
|
||||
SubjectName: "成都蓝色兄弟网络科技有限公司(0802)",
|
||||
BankInfo: l_msg_api.BankInfo{
|
||||
BankName: "中国银行",
|
||||
BankAccount: "43243243434",
|
||||
|
|
Loading…
Reference in New Issue