-
Notifications
You must be signed in to change notification settings - Fork 1
/
jpush.go
83 lines (69 loc) · 3.18 KB
/
jpush.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
74
75
76
77
78
79
80
81
82
83
package push
import (
"context"
"github.com/houseme/go-push-api/internal/jums"
)
// Jums 推送客户端
type Jums struct {
ctx context.Context
client *jums.Jums
}
// SendSms 发送短信
func (j *Jums) SendSms(ctx context.Context, tempID int, phone, code, signID string) error {
var adu = []string{phone}
return j.client.Message().To(jums.ToSms("sms", adu)).Content(jums.MsgSms(signID, tempID, map[string]interface{}{"code": code})).Send()
}
// NewClient 创建推送客户端
func NewClient(ctx context.Context, key, secret string) *Jums {
return &Jums{
ctx: ctx,
client: jums.New(jums.Config{
Key: key,
Secret: secret,
}),
}
}
// SendPush 发送推送
func (j *Jums) SendPush(ctx context.Context, client *jums.Jums, title, content, url string, aud []string) error {
return nil
}
// SendEmail 发送邮件
func (j *Jums) SendEmail(ctx context.Context, tempID int, email, code, signID string) error {
var adu = []string{email}
return j.client.Message().To(jums.ToEmail("sms", adu)).Content(jums.MsgSms(signID, tempID, map[string]interface{}{"code": code})).Send()
}
// SendWechat 发送微信
func (j *Jums) SendWechat(ctx context.Context, tempID int, openID, code, signID string) error {
var adu = []string{openID}
return j.client.Message().To(jums.ToWechatMp("wechat", adu)).Content(jums.MsgSms(signID, tempID, map[string]interface{}{"code": code})).Send()
}
// SendAPP 发送APP
func (j *Jums) SendAPP(ctx context.Context, tempID int, appID, code, signID string) error {
var adu = []string{appID}
return j.client.Message().To(jums.ToApp("app", adu)).Content(jums.MsgSms(signID, tempID, map[string]interface{}{"code": code})).Send()
}
// SendWechatLite 发送微信小程序
func (j *Jums) SendWechatLite(ctx context.Context, tempID int, appID, code, signID string) error {
var adu = []string{appID}
return j.client.Message().To(jums.ToWechatLite("wechatmp", adu)).Content(jums.MsgSms(signID, tempID, map[string]interface{}{"code": code})).Send()
}
// SendWechatWork 发送企业微信
func (j *Jums) SendWechatWork(ctx context.Context, tempID int, appID, code, signID string) error {
var adu = []string{appID}
return j.client.Message().To(jums.ToWechatWork("wechatwk", adu)).Content(jums.MsgSms(signID, tempID, map[string]interface{}{"code": code})).Send()
}
// SendDingTalkCC 发送钉钉
func (j *Jums) SendDingTalkCC(ctx context.Context, tempID int, appID, code, signID string) error {
var adu = []string{appID}
return j.client.Message().To(jums.ToDingTalkCC("dingtalkcc", adu)).Content(jums.MsgSms(signID, tempID, map[string]interface{}{"code": code})).Send()
}
// SendWechatMp 发送微信公众号
func (j *Jums) SendWechatMp(ctx context.Context, tempID int, appID, code, signID string) error {
var adu = []string{appID}
return j.client.Message().To(jums.ToWechatMp("msg_wechatoa", adu)).Content(jums.MsgSms(signID, tempID, map[string]interface{}{"code": code})).Send()
}
// SendAlipayLife 发送支付宝生活号
func (j *Jums) SendAlipayLife(ctx context.Context, tempID int, appID, code, signID string) error {
var adu = []string{appID}
return j.client.Message().To(jums.ToAlipayLife("alipaylife", adu)).Content(jums.MsgSms(signID, tempID, map[string]interface{}{"code": code})).Send()
}