项目结构如下:
├── README.md
├── config
│ └── config.go
├── config.conf
├── config.conf.example
├── enum
│ └── task_type.go
├── glide.lock
├── glide.yaml
├── hlog
│ ├── filelog.go
│ ├── filelog_test.go
│ └── hlog.go
├── main.go
├── main.go.example
├── models
│ ├── message.go
│ └── token.go
├── redis
│ ├── redis.go
│ └── redis_test.go
├── statics
│ └── global.go
├── task
│ ├── task.go
│ └── template_task.go
├── utils
│ ├── access_token.go
│ ├── crontab.go
│ └── push.go
└── vendor
└── github.com
[WeChat]
APPID=
SECRET=
TOKEN=
[Redis]
POOL_SIZE=
TIMEOUT=
HOST=
PASS=
DB=
[Log]
LOG_PATH=
WeChat 部分
Redis 部分
Log 部分
调用的时候这么写:
conf := config.Instance()
//例如 wechat 的 appid
appId := conf.ConMap["WeChat.APPID"]
mess := models.Message{
ToUser: "openid",
TemplateId: "templateid",
Url: "url",
Data: models.Data{
First: models.Raw{"xxx", "#173177"},
Subject: models.Raw{"xxx", "#173177"},
Sender: models.Raw{"xxx", "#173177"},
Remark: models.Raw{"xxx", "#173177"}}}
//封装成一个任务,TemplateTask 表示模板消息任务
task := task.TemplateTask{}
task.SetTask(mess)
package main
import (
"github.com/hundredlee/wechat_pusher/enum"
"github.com/hundredlee/wechat_pusher/models"
"github.com/hundredlee/wechat_pusher/task"
"github.com/hundredlee/wechat_pusher/utils"
"runtime"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
var tasks []task.Task
tasks = make([]task.Task, 100)
mess := models.Message{
ToUser: "oBv9cuLU5zyI27CtzI4VhV6Xabms",
TemplateId: "UXb6s5dahNC5Zt-xQIxbLJG1BdP8mP73LGLhNXl68J8",
Url: "http://baidu.com",
Data: models.Data{
First: models.Raw{"xxx", "#173177"},
Subject: models.Raw{"xxx", "#173177"},
Sender: models.Raw{"xxx", "#173177"},
Remark: models.Raw{"xxx", "#173177"}}}
task := task.TemplateTask{}
task.SetTask(mess)
for i := 0; i < 100; i++ {
tasks[i] = &task
}
utils.NewPush(&utils.Push{
Tasks:tasks,
TaskType:enum.TASK_TYPE_TEMPLATE,
Retries:4,
BufferNum:10,
}).Add("45 * * * * *")
utils.StartCron()
}
utils.NewPush(&utils.Push{
Tasks:tasks,
TaskType:enum.TASK_TYPE_TEMPLATE,
Retries:4,
BufferNum:10,
}).Add("45 * * * * *")
utils.StartCron()
1
chenqh 2017-06-15 19:55:30 +08:00 via iPhone
什么协议 图片推送能做到吗
|