diff --git a/httpclient/fasthttp.go b/httpclient/fasthttp.go index 4ebb4d7..b2829ee 100644 --- a/httpclient/fasthttp.go +++ b/httpclient/fasthttp.go @@ -7,6 +7,7 @@ import ( ) func FastHttpPost(url string, header map[string]string, body []byte, timeout int) ([]byte, error) { + req := fasthttp.AcquireRequest() defer fasthttp.ReleaseRequest(req) // 用完需要释放资源 diff --git a/paramset.go b/paramset.go index 2861f41..71337d0 100644 --- a/paramset.go +++ b/paramset.go @@ -58,7 +58,7 @@ func (m *MessageCenter) send(ctx context.Context, path requestPathIndex, data [] case Rpc: //return m.rpc(ctx, requestAddr, data, resReflect) default: - requestAddr := requestPath[path][m.option.RequestWay] + requestAddr := requestPath[path][Http] return m.post(ctx, requestAddr, data, resReflect) } return @@ -88,7 +88,7 @@ func (m *MessageCenter) post(ctx context.Context, path string, data []byte, resR if err != nil { 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)) } @@ -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) { + pathStr := requestPath[path][Http] 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 { return } diff --git a/test/msg_test.go b/test/msg_test.go index 7d560d6..96b42ea 100644 --- a/test/msg_test.go +++ b/test/msg_test.go @@ -10,17 +10,17 @@ import ( const ( ClientKey = "ymt" ClientSecret = "ymt" - serverHost = "http://120.55.12.245:8200" + serverHost = "http://121.199.38.107:8000" local = "http://127.0.0.1:8001" ) 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 { panic(err) } - res, err := msg.SendSms([]string{"15082245107"}, `{"content": "测试"}`) + res, err := msg.SendSms(context.TODO(), []string{"15082245107"}, `{"content": "测试"}`) fmt.Println(res, err) } @@ -38,7 +38,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(context.TODO(), "17101201090101570", "cxvxvxcgfgfvxvxv", &l_msg_api.FormsData{ FormComponentValues: form, Finance: &l_msg_api.Finance{ Amount: "11.22", @@ -68,7 +68,7 @@ func TestOaComment(t *testing.T) { if err != nil { panic(err) } - res, err := msg.OAComment("P24110515152043136-20250318181554", "sdk测试", "", nil) + res, err := msg.OAComment(context.TODO(), "P24110515152043136-20250318181554", "sdk测试", "", nil) fmt.Println(res, err) }