/
notice.go
56 lines (50 loc) · 1.19 KB
/
notice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package repository
import "github.com/GanEasy/WechatMessageServe/notice"
// func init() {
// maxWorkers := 1
// maxQueue := 2
// //初始化一个调试者,并指定它可以操作的 工人个数
// dispatch := notice.NewDispatcher(maxWorkers)
// notice.JobQueue = make(chan notice.Job, maxQueue) //指定任务的队列长度
// //并让它一直接运行
// dispatch.Run()
// // close(notice.JobQueue)
// }
// SendText 发送文本
func SendText(openID, text string) (err error) {
// openID = "o7UTkjr7if4AQgcPmveQ5wJ5alsA"
p := notice.TextNotice{
OpenID: openID,
Text: text,
}
notice.JobQueue <- notice.Job{
Notice: &p,
}
return nil
}
// SendArticle 发送文章
func SendArticle(openID, title, description, picURL, url string) (err error) {
p := notice.ArticleNotice{
OpenID: openID,
Title: title,
Description: description,
PicURL: picURL,
URL: url,
}
notice.JobQueue <- notice.Job{
Notice: &p,
}
return nil
}
// SendEmail 发送邮件
func SendEmail(address, title, body string) (err error) {
p := notice.EmailNotice{
Address: address,
Title: title,
Body: body,
}
notice.JobQueue <- notice.Job{
Notice: &p,
}
return nil
}