Fix FastHttpPost, update server URL, enhance paramset and tests

This commit is contained in:
renzhiyuan 2025-04-09 20:51:51 +08:00
parent 5b12078be4
commit a8520b547a
3 changed files with 10 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import (
) )
func FastHttpPost(url string, header map[string]string, body []byte, timeout int) ([]byte, error) { func FastHttpPost(url string, header map[string]string, body []byte, timeout int) ([]byte, error) {
req := fasthttp.AcquireRequest() req := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(req) // 用完需要释放资源 defer fasthttp.ReleaseRequest(req) // 用完需要释放资源

View File

@ -58,7 +58,7 @@ func (m *MessageCenter) send(ctx context.Context, path requestPathIndex, data []
case Rpc: case Rpc:
//return m.rpc(ctx, requestAddr, data, resReflect) //return m.rpc(ctx, requestAddr, data, resReflect)
default: default:
requestAddr := requestPath[path][m.option.RequestWay] requestAddr := requestPath[path][Http]
return m.post(ctx, requestAddr, data, resReflect) return m.post(ctx, requestAddr, data, resReflect)
} }
return return
@ -88,7 +88,7 @@ func (m *MessageCenter) post(ctx context.Context, path string, data []byte, resR
if err != nil { if err != nil {
return fmt.Errorf("未知的返回格式:%s", string(dataByte)) return fmt.Errorf("未知的返回格式:%s", string(dataByte))
} }
if err = json.Unmarshal(dataByte, &resReflect); err != nil { if err = json.Unmarshal(dataByte, resReflect); err != nil {
return fmt.Errorf("未知的返回格式:%s", string(dataByte)) return fmt.Errorf("未知的返回格式:%s", string(dataByte))
} }
@ -96,8 +96,9 @@ func (m *MessageCenter) post(ctx context.Context, path string, data []byte, resR
} }
func (m *MessageCenter) accessPost(path requestPathIndex, data []byte, resReflect interface{}) (err error) { func (m *MessageCenter) accessPost(path requestPathIndex, data []byte, resReflect interface{}) (err error) {
pathStr := requestPath[path][Http]
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, pathStr), m.header, data, timeOut)
if err != nil { if err != nil {
return return
} }

View File

@ -10,17 +10,17 @@ import (
const ( const (
ClientKey = "ymt" ClientKey = "ymt"
ClientSecret = "ymt" ClientSecret = "ymt"
serverHost = "http://120.55.12.245:8200" serverHost = "http://121.199.38.107:8000"
local = "http://127.0.0.1:8001" local = "http://127.0.0.1:8001"
) )
func TestSms(t *testing.T) { func TestSms(t *testing.T) {
msg, err := l_msg_api.NewMessageCenter(serverHost, ClientKey, ClientSecret, "smssass", "sasssms") msg, err := l_msg_api.NewMessageCenter(serverHost, ClientKey, ClientSecret, "sms", "sms")
if err != nil { if err != nil {
panic(err) panic(err)
} }
res, err := msg.SendSms([]string{"15082245107"}, `{"content": "测试"}`) res, err := msg.SendSms(context.TODO(), []string{"15082245107"}, `{"content": "测试"}`)
fmt.Println(res, err) fmt.Println(res, err)
} }
@ -38,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", "cxvxvxcgfgfvxvxv", &l_msg_api.FormsData{ res, err := msg.OACreate(context.TODO(), "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",
@ -68,7 +68,7 @@ func TestOaComment(t *testing.T) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
res, err := msg.OAComment("P24110515152043136-20250318181554", "sdk测试", "", nil) res, err := msg.OAComment(context.TODO(), "P24110515152043136-20250318181554", "sdk测试", "", nil)
fmt.Println(res, err) fmt.Println(res, err)
} }