This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
client.go
73 lines (65 loc) · 1.81 KB
/
client.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* ====================================================
# Copyright (C)2019 All rights reserved.
#
# Author : domchan
# Email : 814172254@qq.com
# File Name : client.go
# Created : 2019/1/16 19:19
# Last Modified : 2019/1/16 19:19
# Describe :
#
# ====================================================*/
package pub
import (
"github.com/hiruok/msg-pusher/config"
"github.com/hiruok/msg-pusher/pkg/pb/meta"
"github.com/hiruok/msg-pusher/pkg/send"
"github.com/hiruok/msg-pusher/pkg/send/email"
"github.com/hiruok/msg-pusher/pkg/send/sms"
"github.com/hiruok/msg-pusher/pkg/send/wechat"
"github.com/hiruok/msg-pusher/storer"
)
var (
clientMap = make(map[string]send.Sender)
)
func Init() {
smsConf := config.SmsConf()
for k, v := range smsConf {
clientMap["sms-"+k] = sms.NewClient(sms.Config{
AccessKeyId: v.AccessKeyId,
AccessSecret: v.AccessSecret,
GatewayURL: v.GatewayURL,
})
}
weChatConf := config.WeChatConf()
if weChatConf != nil {
clientMap["wechat"] = wechat.NewClient(
wechat.Config{
APPId: weChatConf.AppId,
APPSecret: weChatConf.AppSecret,
},
storer.Cache)
}
emailConf := config.EmailConf()
for k, v := range emailConf {
clientMap["email-"+k] = email.NewClient(email.Config{
ServerAddr: v.Addr,
Username: v.Username,
Password: v.Password,
Host: v.Host,
TLS: v.TLS,
})
}
}
// WeChatClient 获取微信客户端
func WeChatClient() send.Sender {
return clientMap["wechat"]
}
// SmsClient 根据服务商获取sms客户端发送消息
func SmsClient(s meta.Server) send.Sender {
return clientMap["sms-"+meta.Server_name[int32(s)]]
}
// EmailClient 根据服务商获取email客户端发送邮件
func EmailClient(s meta.Server) send.Sender {
return clientMap["email-"+meta.Server_name[int32(s)]]
}