Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
|
877a9e10d3 | |
|
84ae733098 | |
|
cc5b1464a4 | |
|
5c982fb266 | |
|
89c9eeb4c4 |
19
config.go
19
config.go
|
@ -44,17 +44,18 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
Finance struct {
|
Finance struct {
|
||||||
CheckUserId string `json:"checkUserId"` //审核人
|
CheckUserId string `json:"checkUserId"` //审核人
|
||||||
Sync int64 `json:"sync"` //是否是异步,如果为异步,付款申请和业务申请是同时进行
|
Sync int64 `json:"sync"` //是否是异步,如果为异步,付款申请和业务申请是同时进行
|
||||||
Amount string `json:"amount"` //金额
|
Amount string `json:"amount"` //金额
|
||||||
GoodsInfo string `json:"goodsInfo"` //商品信息
|
GoodsInfo string `json:"goodsInfo"` //商品信息
|
||||||
PaymentAccount string `json:"payment_account"` //付款方账户
|
PaymentAccount string `json:"paymentAccount"` //付款方账户
|
||||||
TaxAmount string `json:"tax_amount"` //税率
|
TaxAmount string `json:"taxAmount"` //税率
|
||||||
CallbackUrl string `json:"callback_url"` //回调地址
|
CallbackUrl string `json:"callbackUrl"` //回调地址
|
||||||
Remark string `json:"remark"` //备注
|
Remark string `json:"remark"`
|
||||||
|
SystemName string `json:"systemName"` //业务系统名称
|
||||||
|
SubjectName string `json:"subjectName"` //户名
|
||||||
BankInfo BankInfo `json:"bankInfo"`
|
BankInfo BankInfo `json:"bankInfo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
BankInfo struct {
|
BankInfo struct {
|
||||||
ResellerName string `json:"resellerName"` //供应商名称
|
ResellerName string `json:"resellerName"` //供应商名称
|
||||||
BankName string `json:"bankName"` //银行名称
|
BankName string `json:"bankName"` //银行名称
|
||||||
|
|
14
const.go
14
const.go
|
@ -1,8 +1,8 @@
|
||||||
package l_msg_api
|
package l_msg_api
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ServerHost = "http://127.0.0.1:8001"
|
serverHost = "http://127.0.0.1:8001"
|
||||||
TimeOut = 80000000
|
timeOut = 60
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -14,9 +14,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AccessToken = "/oauth/v1/accesstoken"
|
accessToken = "/oauth/v1/accesstoken"
|
||||||
OaCreat = "/msg/v1/dingtalk/oa/create"
|
oaCreat = "/msg/v1/dingtalk/oa/create"
|
||||||
OaGet = "/msg/v1/dingtalk/oa/get"
|
oaGet = "/msg/v1/dingtalk/oa/get"
|
||||||
OaComment = "/msg/v1/dingtalk/oa/comment"
|
oaComment = "/msg/v1/dingtalk/oa/comment"
|
||||||
SendSms = "/msg/v1/sms/send"
|
sendSms = "/msg/v1/sms/send"
|
||||||
)
|
)
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module gitea.cdlsxd.cn/self-tools/l_msg_api
|
module gitea.cdlsxd.cn/self-tools/l_msg_api
|
||||||
|
|
||||||
go 1.23.6
|
go 1.22.2
|
||||||
|
|
||||||
require github.com/valyala/fasthttp v1.59.0
|
require github.com/valyala/fasthttp v1.59.0
|
||||||
|
|
||||||
|
|
16
msg.go
16
msg.go
|
@ -31,9 +31,11 @@ func NewMessageCenter(host, clientKey, clientSecret, serverIndex, tempIndex stri
|
||||||
|
|
||||||
// OACreate 发起OA审批
|
// OACreate 发起OA审批
|
||||||
func (m *MessageCenter) OACreate(dTalkUserId, treadNo string, formModel *FormsData) (data OAResponse, err error) {
|
func (m *MessageCenter) OACreate(dTalkUserId, treadNo string, formModel *FormsData) (data OAResponse, err error) {
|
||||||
formModel.formBase.OutTradeNo = treadNo
|
formModel.FormBase = FormBase{
|
||||||
formModel.formBase.OriginatorUserId = dTalkUserId
|
OutTradeNo: treadNo,
|
||||||
err = m.post(OaCreat, m.parseOACreateParam(formModel), &data)
|
OriginatorUserId: dTalkUserId,
|
||||||
|
}
|
||||||
|
err = m.post(oaCreat, m.parseOACreateParam(formModel), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -46,7 +48,7 @@ func (m *MessageCenter) OAGetDetail(outTradeNo string) (data OAGetDetailData, er
|
||||||
Base: m.base,
|
Base: m.base,
|
||||||
OutTradeNo: outTradeNo,
|
OutTradeNo: outTradeNo,
|
||||||
})
|
})
|
||||||
err = m.post(OaGet, param, &data)
|
err = m.post(oaGet, param, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -56,7 +58,7 @@ func (m *MessageCenter) OAGetDetail(outTradeNo string) (data OAGetDetailData, er
|
||||||
// SendSms 短信
|
// SendSms 短信
|
||||||
func (m *MessageCenter) SendSms(tels []string, jsonParam string) (data SmsSend, err error) {
|
func (m *MessageCenter) SendSms(tels []string, jsonParam string) (data SmsSend, err error) {
|
||||||
param := m.parseSmsSendParam(tels, jsonParam)
|
param := m.parseSmsSendParam(tels, jsonParam)
|
||||||
err = m.post(SendSms, param, &data)
|
err = m.post(sendSms, param, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -73,7 +75,7 @@ func (m *MessageCenter) SendBlackBoard(title, content string, deptidList []int,
|
||||||
receiver := blackboardReceiverView{
|
receiver := blackboardReceiverView{
|
||||||
deptidList, useridList,
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -93,7 +95,7 @@ func (m *MessageCenter) OAComment(outTradeNo, text, commentUserId string, file *
|
||||||
}
|
}
|
||||||
param, _ := json.Marshal(req)
|
param, _ := json.Marshal(req)
|
||||||
|
|
||||||
err = m.post(OaComment, param, &data)
|
err = m.post(oaComment, param, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ func (m *MessageCenter) parseOACreateParam(formModel *FormsData) (out []byte) {
|
||||||
}
|
}
|
||||||
req.FormComponentValues = formModel.FormComponentValues
|
req.FormComponentValues = formModel.FormComponentValues
|
||||||
req.Finance = formModel.Finance
|
req.Finance = formModel.Finance
|
||||||
req.formBase = formModel.formBase
|
req.FormBase = formModel.FormBase
|
||||||
out, _ = json.Marshal(req)
|
out, _ = json.Marshal(req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func (m *MessageCenter) getAccessToken() (string, error) {
|
||||||
var data accessTokenResponse
|
var data accessTokenResponse
|
||||||
|
|
||||||
var authParam, _ = json.Marshal(map[string]string{"client_key": m.ClientKey, "client_secret": m.ClientSecret})
|
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 {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ func (m *MessageCenter) getAccessToken() (string, error) {
|
||||||
|
|
||||||
func (m *MessageCenter) post(path string, data []byte, resReflect interface{}) (err error) {
|
func (m *MessageCenter) post(path string, data []byte, resReflect interface{}) (err error) {
|
||||||
var body responseBody
|
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 {
|
if err != nil {
|
||||||
return
|
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) {
|
func (m *MessageCenter) accessPost(path string, data []byte, resReflect interface{}) (err error) {
|
||||||
var body responseBody
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitea.cdlsxd.cn/self-tools/l_msg_api"
|
"gitea.cdlsxd.cn/self-tools/l_msg_api"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -9,10 +10,12 @@ import (
|
||||||
const (
|
const (
|
||||||
ClientKey = "ymt"
|
ClientKey = "ymt"
|
||||||
ClientSecret = "ymt"
|
ClientSecret = "ymt"
|
||||||
|
serverHost = "http://120.55.12.245:8200"
|
||||||
|
local = "http://127.0.0.1:8001"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSms(t *testing.T) {
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +26,7 @@ func TestSms(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOaCreate(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(local, ClientKey, ClientSecret, "sw_oa", "sw_oa_purchase")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -35,7 +38,7 @@ func TestOaCreate(t *testing.T) {
|
||||||
{Name: "采购总金额", Value: "11.22"},
|
{Name: "采购总金额", Value: "11.22"},
|
||||||
{Name: "预计到货时间", Value: "2025-03-21"},
|
{Name: "预计到货时间", Value: "2025-03-21"},
|
||||||
}
|
}
|
||||||
res, err := msg.OACreate("17101201090101570", "123456789123bgff", &l_msg_api.FormsData{
|
res, err := msg.OACreate("17101201090101570", "cxvxvxcgfgfvxvxv", &l_msg_api.FormsData{
|
||||||
FormComponentValues: form,
|
FormComponentValues: form,
|
||||||
Finance: &l_msg_api.Finance{
|
Finance: &l_msg_api.Finance{
|
||||||
Amount: "11.22",
|
Amount: "11.22",
|
||||||
|
@ -46,6 +49,8 @@ func TestOaCreate(t *testing.T) {
|
||||||
CallbackUrl: "www.baidu.com",
|
CallbackUrl: "www.baidu.com",
|
||||||
Remark: "测试备注",
|
Remark: "测试备注",
|
||||||
Sync: 1,
|
Sync: 1,
|
||||||
|
SystemName: "货易通",
|
||||||
|
SubjectName: "成都蓝色兄弟网络科技有限公司(0802)",
|
||||||
BankInfo: l_msg_api.BankInfo{
|
BankInfo: l_msg_api.BankInfo{
|
||||||
BankName: "中国银行",
|
BankName: "中国银行",
|
||||||
BankAccount: "43243243434",
|
BankAccount: "43243243434",
|
||||||
|
@ -59,10 +64,15 @@ func TestOaCreate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOaComment(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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
res, err := msg.OAComment("P24110515152043136-20250318181554", "sdk测试", "", nil)
|
res, err := msg.OAComment("P24110515152043136-20250318181554", "sdk测试", "", nil)
|
||||||
fmt.Println(res, err)
|
fmt.Println(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext(*testing.T) {
|
||||||
|
c := context.Background()
|
||||||
|
c.Done()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue