feat: support mf calling api
This commit is contained in:
38
features/ue/mf_calling/service.go
Normal file
38
features/ue/mf_calling/service.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package mf_calling
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
neModel "be.ems/src/modules/network_element/model"
|
||||
)
|
||||
|
||||
func (s *MfCallingInfo) GetCallingInfoFromMF(neInfo neModel.NeInfo) ([]MfCallingInfo, int, error) {
|
||||
// 构造网元MF的API地址
|
||||
url := fmt.Sprintf("http://%s:%d/api/rest/psap/v1/mf/callingInfo", neInfo.IP, neInfo.Port)
|
||||
|
||||
// 可根据querys拼接更多参数
|
||||
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 假设MF返回格式为 {"totalCalls": 10, "Data": [...]}
|
||||
var mfResp struct {
|
||||
TotalCalls int `json:"totalCalls"`
|
||||
Data []MfCallingInfo `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &mfResp); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return mfResp.Data, mfResp.TotalCalls, nil
|
||||
}
|
||||
Reference in New Issue
Block a user