Merge branch 'dev-lwl/firenze' into test
This commit is contained in:
commit
bdfde60379
|
@ -49,3 +49,39 @@ func SendBizMsg(param *firenzeproto.SendBizMsgParam) (*base.BaseResponse, error)
|
|||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func SendBroadcastMsg(param *firenzeproto.SendBroadcastMsgParam) (*base.BaseResponse, error) {
|
||||
defer logger.Recover()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*2000)
|
||||
defer cancel()
|
||||
|
||||
jsonStr, err := json.Marshal(param)
|
||||
if err != nil {
|
||||
logger.Error("build data error: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", sendBizMsgUrl, bytes.NewBuffer(jsonStr))
|
||||
if err != nil {
|
||||
logger.Error("NewRequest error %v", err)
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.Error("failed to add case, err : %v", err)
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
res := new(base.BaseResponse)
|
||||
bs, _ := ioutil.ReadAll(resp.Body)
|
||||
err = json.Unmarshal(bs, &res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
|
|
@ -2,8 +2,14 @@ package firenze
|
|||
|
||||
import "encoding/json"
|
||||
|
||||
// 单条消息
|
||||
type SendBizMsgParam struct {
|
||||
Sid string `json:"sid"`
|
||||
Mid int64 `json:"mid"`
|
||||
Msg json.RawMessage `json:"msg"`
|
||||
}
|
||||
|
||||
// 广播
|
||||
type SendBroadcastMsgParam struct {
|
||||
Msg json.RawMessage `json:"msg"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue