Orange is a message push service composed of golang, iris, mysql, and redis technology frameworks. Supports unified and configurable management and sending of WeChat subscription messages, SMS messages, and email messages. Supports sending of different strategies. Effectively manage template resources, filter sensitive words, customize additional configurations and template policies, record message bodies, and provide message sending services for multiple business directions. Supports simple text auto-replies.
Why do you need such a service? As the company's business increases and its services continue to increase, more and more messages need to be sent to users. It is necessary to send users such as order notifications, arrival notifications, evaluation messages, order success notifications, registration messages, and other promotional information. As we all know, the use of third-party sending interfaces such as WeChat subscription messages, Alibaba Cloud SMS, email sending and other interfaces is relatively time-consuming. For services that need to send a large number of messages, if used improperly, it will cause serious waste of resources and even affect the core business. logic. On the other hand, it would be too troublesome for each service to maintain its own set of logic for sending messages. There are many pitfalls, such as access_token maintenance, interface maintenance, n multiple template maintenance, sensitive word maintenance, and message status recording. If a company maintains such a set of logic for n multiple services, it will be redundant and a waste of manpower and material resources.
These two pictures can more intuitively see why I want to write such a small system. There are still some advantages.
1.golang
2.iris
3.redis
4.mysql
5.阿里云短信
6.微信订阅消息
7.邮件发送类库
8.mq平台
9.阿里云acm
go ( > = 1.13.1)
1.git clone https://github.com/lovesgg/orange_message_service.git
2.cd orange_message_service
3.执行命令开启mod支持: export GO111MODULE=on
4.更换代理: export GOPROXY=https://goproxy.cn
5.下载依赖: go mod vendor
6.cp conf/app.json.example conf/app.json
7.加配置信息如redis mysql 端口等
1.app.json 环境+端口
2.log.json 日志目录
3.message.json 消息配置模板 可自定义通道和模板
4.mysql.json mysql配置信息 需要自行定义数据库和表。根据自己需要的字段创建和对应代码中的字段即可。可直接使用.doc目录下的message.sql文件去建表
5.redis.json redis配置信息
6.sms.json 阿里云短信配置
7.wechat.json 微信订阅消息的appid配置
8.acm.json 阿里云应用配置
(如果需要追加.json文件,请在app/components/config/config.go中修改)
7.配置完信息可以拷贝配置文件到另一个目录啦
mkdir /data/www/orange_message_service/conf
cp -r orange_message_service/conf/ * /data/www/orange_message_service/conf
(这步骤是因为当您使用 rizla main.go时读的是这位置的配置)
8.创建日志目录
mkdir /data/logs/orange_message_service
9.mq订阅发布
请自行安装当前流行的mq平台。
/client/send 负责发送mq消息
/server/send 负责消费消息mq
(备注:/client/send 接口里边最后有说明 //执行mq发送 由server端来消费 这部分由您根据实际需要自行添加。如有问题可微信联系。)
10.到这里可以认为您的环境已经没问题
到orange_message_service根目录下执行 rizla main.go即可运行啦。当然您也可以go run main.go
如果运行报错请先自行排查环境是否都已经安装完毕,或者先自行百度。不清楚的可直接微信联系。
推荐message.json配置:可自定义
{
" 1000 " :{
" sequence " :[ " subscribe " ],
" subscribe " :{
" channel " : "微信订阅消息" ,
" template " : " SendDataTest " ,
" is_retry " :0
},
" sms " :{
" channel " : "阿里云" ,
" template " : " SendDataTest " ,
" is_retry " :0
}
},
" 1001 " :{
" sequence " :[ " email " ],
" email " :{
" channel " : "邮件" ,
" template " : " SendDataTest " ,
" is_retry " :0
}
}
}
1.key值唯一,上游服务根据这唯一通道+模板参数组成。一次调用只需要关注这id和必要参数即可。
2.sequence:通道数组。循环发送。比如[ " sms " , " email " , " subscribe " ] 此消息依次发送短信、邮件、订阅消息。
3.email | sms | subscribe 里的参数:
template对应的是一个方法,每个key对应的次方法唯一。
is_retry:如果发送失败是否需要重试。
详情参考以下接口调用。
├── README.md
├── app
│ ├── common
│ │ ├── aliyun.go
│ │ ├── constant.go
│ │ ├── enum
│ │ │ ├── event_name.go
│ │ │ ├── redis_expire.go
│ │ │ ├── redis_key.go
│ │ │ └── topic.go
│ │ ├── error.go
│ │ ├── structure.go
│ │ ├── templates.go
│ │ └── wechat.go
│ ├── components
│ │ ├── config
│ │ │ └── config.go
│ │ ├── eventdispatcher
│ │ │ ├── event.go
│ │ │ ├── eventdispatcher.go
│ │ │ ├── eventdispatcher_test.go
│ │ │ ├── listener.go
│ │ │ └── log.go
│ │ ├── go-email
│ │ │ └── go_email.go
│ │ ├── http
│ │ │ ├── client.go
│ │ │ └── request.go
│ │ ├── init.go
│ │ ├── mlog
│ │ │ └── log.go
│ │ ├── mysql
│ │ │ └── client.go
│ │ ├── redis
│ │ │ ├── client.go
│ │ │ ├── client_test.go
│ │ │ ├── hash.go
│ │ │ ├── hash_test.go
│ │ │ ├── string.go
│ │ │ └── string_test.go
│ │ ├── rpc
│ │ │ ├── base_rpc.go
│ │ │ └── config.go
│ │ ├── sms
│ │ │ ├── aliyun.go
│ │ │ └── aliyun_test.go
│ │ └── test
│ │ └── helper.go
│ ├── console
│ │ ├── commands
│ │ │ ├── hello.go
│ │ │ ├── init.go
│ │ │ └── server_send.go
│ │ └── root.go
│ ├── controllers
│ │ ├── base_controller.go
│ │ ├── client
│ │ │ ├── send_action.go
│ │ │ └── send_controller.go
│ │ └── server
│ │ ├── send_action.go
│ │ └── send_controller.go
│ ├── events
│ │ └── rpc_call_warning.go
│ ├── middleware
│ │ ├── recover_panic.go
│ │ ├── request_bootstrap.go
│ │ └── request_logger.go
│ ├── models
│ │ ├── message.go
│ │ └── request
│ │ └── request.go
│ ├── render
│ │ └── sms.go
│ ├── router
│ │ └── routes.go
│ ├── services
│ │ ├── client
│ │ │ └── client.go
│ │ ├── db.go
│ │ ├── repository
│ │ ├── rpc
│ │ ├── server
│ │ │ ├── email.go
│ │ │ ├── emailTemplates
│ │ │ │ └── email.go
│ │ │ ├── sms.go
│ │ │ ├── smsTemplates
│ │ │ │ └── sms.go
│ │ │ ├── subscribe.go
│ │ │ ├── subscribeTemplates
│ │ │ │ └── subscribe.go
│ │ │ └── word.go
│ │ └── wechat.go
│ └── utils
│ ├── compress
│ │ └── zlib.go
│ ├── helper.go
│ └── typeconv
│ └── type_trans.go
├── bin
│ ├── orange_message_service.supervisor.conf
│ ├── pre-commit
│ ├── start.sh
│ ├── stop.sh
│ └── supervisord.conf
├── build.sh
├── cmd
│ └── main.go
├── conf
│ ├── app.json
│ ├── app.json.example
│ ├── common.json
│ ├── email.json
│ ├── filter_words.json
│ ├── log.json
│ ├── message.json
│ ├── mysql.json
│ ├── redis.json
│ ├── rpc.json
│ ├── sms.json
│ └── wechat.json
├── docker-compose.yml
├── dockerfile
├── go.mod
├── go.sum
├── main.go
├── nursery
├── orange_message_service
├── output
│ └── server
└── runtime
说明:
1.入口main文件:main.go
2.可执行文件:orange_message_service
3.mod管理文件:go.mod/go.sum
4.路由文件:app/router/routers.go
5.项目配置文件:conf/
6.控制器路径:app/controllers
7.公共常量枚举:app/common
8.公共组件:app/components
9.启动文件:build.sh (rizla main.go 也行)
serial number | interface | Add ginseng | Remark |
---|---|---|---|
1 | /health/check | none | Return normal information to verify that the service starts normally. |
2 | /client/send | Refer to the following | Client receives |
3 | /server/send | Refer to the following | Server consumption and sending |
4 | /client/send-batch | Refer to the following | Send in bulk |
5 | /client/send-by-sync | Refer to the following | Coroutine batch sending (recommended to use this method) |
6 | /client/send-by-users | Refer to the following | Coroutine batch sending - batch users send the same template message (this method is recommended) |
7 | /customer/say | Refer to the following | Customer service automatically matches responses |
1. /client/send
{
" msg_key " :1000,
" source_id " :1,
" body " :[{
" goods_name " : "苹果" ,
" store_name " : " wg " ,
" address_detail " : " wgrg " ,
" phone " : " 1881000000 " ,
" note " : "你好" ,
" user_id " : " " ,
" order_no " : " 543646 "
}]
}
2. /server/send
{
" msg_key " :1000,
" source_id " :1,
" body " :{
" goods_name " : "苹果" ,
" store_name " : " wg " ,
" address_detail " : " wgrg " ,
" phone " : " 1881000000 " ,
" note " : "你好" ,
" user_id " : " " ,
" order_no " : " 543646 "
}
}
3./client/send-by-users
{
" msg_key " :1003,
" source_id " :1,
" users " :[
" [email protected] " ,
" [email protected] "
]
}
4./customer/say
{
" text " : " test "
}
包含一些说明图片
见orange_message_service/.doc 目录下的图片
此服务适合有经验的人。因为涉及一些第三方接口和几个环境的部署。建议用在发送消息比较多的场景。如果只是发很简单的消息不推荐用这个。
其中可能包含部分不足的地方。陆续优化中。如果用在生产环境,需要掌握熟悉了才部署。
欢迎好友来一起交流探讨。