2019-04-22 02:59:20 +00:00

47 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package dao
import (
"context"
"errors"
"net/url"
"go-common/library/log"
"go-common/library/xstr"
)
const (
_notifyDataType = "4" // 消息类型1、回复我的2、@我3、收到的爱4、业务通知
_notifyURL = "/api/notify/send.user.notify.do"
_notifyMC = "1_8_2"
)
func (d *Dao) notifyURI() string {
return d.conf.Host.Message + _notifyURL
}
// SendNotify 发送站内信
func (d *Dao) SendNotify(c context.Context, title, content string, mids []int64) (err error) {
res := struct {
Code int `json:"code"`
Data struct {
TotalCount int
ErrorCount int
} `json:"data"`
}{}
params := url.Values{}
params.Set("mc", _notifyMC)
params.Set("title", title)
params.Set("data_type", _notifyDataType)
params.Set("context", content)
params.Set("mid_list", xstr.JoinInts(mids))
if err = d.httpClient.Post(c, d.notifyURI(), "", params, &res); err != nil {
log.Error("d.httpClient.Post(%s,%v,%d)", d.notifyURI(), params, err)
return
}
if res.Code != 0 {
err = errors.New("code != 0")
log.Error("d.httpClient.Post(%s,%v,%v,%d)", d.notifyURI(), params, err, res.Code)
}
return
}