Fix FastHttpPost, update server URL, enhance paramset and tests
This commit is contained in:
parent
5b12078be4
commit
a8520b547a
|
@ -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) // 用完需要释放资源
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue