wechat_pusher - 基于Golang开发的微信消息定时推送框架
wechat_pusherGithub
功能列表
如何开始?第一步:当然是go get
├── 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=
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",Sender: models.Raw{"xxx",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","#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() }
Run
utils.NewPush(&utils.Push{ Tasks:tasks,}).Add("45 * * * * *") utils.StartCron() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |