report
This commit is contained in:
parent
f32444afe2
commit
a52f8618da
|
|
@ -95,6 +95,33 @@ func (m *Message) SendText(args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Message) SendMail(receiver, title, content string) error {
|
||||||
|
|
||||||
|
// Build form data
|
||||||
|
formData := url.Values{}
|
||||||
|
formData.Set("sender", m.sender)
|
||||||
|
formData.Set("receiver", receiver)
|
||||||
|
formData.Set("type", "text")
|
||||||
|
formData.Set("title", title)
|
||||||
|
formData.Set("content", content)
|
||||||
|
|
||||||
|
reqUrl := fmt.Sprintf("%s/admin/message/send", m.address)
|
||||||
|
body, err := util.HttpPostForm(reqUrl, map[string]string{
|
||||||
|
"x-token": m.token,
|
||||||
|
}, formData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var rsp util.Response
|
||||||
|
if err := json.Unmarshal(body, &rsp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if rsp.Code != 0 {
|
||||||
|
return fmt.Errorf("%d:%s", rsp.Code, rsp.Message)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Message) SendTable(receiver string, table *goutil.TableData) error {
|
func (m *Message) SendTable(receiver string, table *goutil.TableData) error {
|
||||||
content := goutil.EncodeJSON(table)
|
content := goutil.EncodeJSON(table)
|
||||||
reqUrl := fmt.Sprintf("%s/admin/message/send", m.address)
|
reqUrl := fmt.Sprintf("%s/admin/message/send", m.address)
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ import (
|
||||||
|
|
||||||
func TestMessage_Send(t *testing.T) {
|
func TestMessage_Send(t *testing.T) {
|
||||||
|
|
||||||
s := NewMessage("http://u.batiao8.com", "c39e1c6e-38f7-422c-a7d1-9e05bf65596f", "batiao-mail")
|
s := NewMessage("http://u.batiao8.com", "c39e1c6e-38f7-422c-a7d1-9e05bf65596f", "batiao-report-mail")
|
||||||
|
|
||||||
mess := make([]string, 0)
|
mess := make([]string, 0)
|
||||||
mess = append(mess, `abcc`)
|
mess = append(mess, `abcc`)
|
||||||
err := s.Send("jiangyong@batiao8.com", strings.Join(mess, "\n"))
|
err := s.SendMail("jiangyong@batiao8.com", "测试", strings.Join(mess, "\n"))
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue