notify

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2023 License: GPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

*

  • Copyright 2015 @ 56x.net.
  • name : notify
  • author : jarryliu
  • date : 2016-07-06 18:36
  • description :
  • history :

Index

Constants

View Source
const (
	TypeSiteMessage = iota
	TypeEmailMessage
	TypePhoneMessage
)

Variables

View Source
var (
	ErrNoSuchNotifyItem = domain.NewError(
		"err_no_such_notify_item", "通知项不存在")
	ErrNotSettingSmsProvider = domain.NewError(
		"err_not_setting_sms_provider", "未配置短信服务商")
	ErrNoSuchSmsProvider = domain.NewError(
		"err_not_such_sms_provider", "不存在短信服务商")
)
View Source
var (
	// 类型字典
	NotifyTypeMap = map[int]string{
		TypeSiteMessage:  "站内信",
		TypeEmailMessage: "邮件",
		TypePhoneMessage: "短信",
	}

	// 类型顺序
	NotifyTypeIndex = []int{
		TypeSiteMessage,
		TypeEmailMessage,
		TypePhoneMessage,
	}

	// 默认通知项
	DefaultNotifyItems = NotifyItemSet{
		&NotifyItem{
			Key:      "注册通知",
			TplId:    -1,
			NotifyBy: TypeSiteMessage,
			Content:  "您好,恭喜您已注册成为会员!",
			Tags:     map[string]string{},
		},
		&NotifyItem{
			Key:        "验证手机",
			TplId:      -1,
			ReadonlyBy: true,
			NotifyBy:   TypePhoneMessage,
			Content:    "您好,本次{operation}验证码为{code},有效期为{minutes}分钟。",
			Tags: map[string]string{
				"operation": "操作,如找回密码,重置手机等",
				"code":      "验证码",
				"minutes":   "有效时间",
			},
		},
		&NotifyItem{
			Key:        "验证邮箱",
			TplId:      -1,
			ReadonlyBy: true,
			NotifyBy:   TypeEmailMessage,
			Content:    "您好,本次{operation}验证码为{code},有效期为{minutes}分钟。",
			Tags: map[string]string{
				"operation": "操作,如找回密码,重置手机等",
				"code":      "验证码",
				"minutes":   "有效时间",
			},
		},
	}
)

Functions

func RegisterNotifyItem

func RegisterNotifyItem(key string, item *NotifyItem)

可通过外部添加

Types

type INotifyManager

type INotifyManager interface {
	// 获取所有的通知项
	GetAllNotifyItem() []NotifyItem
	// 获取通知项配置
	GetNotifyItem(key string) NotifyItem
	// 保存通知项设置
	SaveNotifyItem(item *NotifyItem) error
	// 保存短信API
	SaveSmsApiPerm(s *SmsApiPerm) error
	// 获取短信API信息
	GetSmsApiPerm(provider int) *SmsApiPerm
	// 发送手机短信
	SendPhoneMessage(phone string, msg PhoneMessage, data []string, templateId string) error
	// 发送邮件
	SendEmail(to string, msg *MailMessage, data []string) error
}

type INotifyRepo

type INotifyRepo interface {
	// 获取通知服务
	Manager() INotifyManager
	// 获取所有的通知项
	GetAllNotifyItem() []NotifyItem

	// 获取通知项
	GetNotifyItem(key string) *NotifyItem

	// 保存通知项
	SaveNotifyItem(v *NotifyItem) error
}

type MailMessage

type MailMessage struct {
	// 主题
	Subject string `json:"subject"`
	// 内容
	Body string `json:"body"`
}

邮件消息

type NotifyItem

type NotifyItem struct {
	Key string
	// 发送方式
	NotifyBy int
	// 不允许修改发送方式
	ReadonlyBy bool
	// 模板编号
	TplId int
	// 内容
	Content string
	// 模板包含的标签
	Tags map[string]string
}

通知项

type NotifyItemSet

type NotifyItemSet []*NotifyItem

通知项集合

type PhoneMessage

type PhoneMessage string

简讯

type SiteMessage

type SiteMessage struct {
	// 主题
	Subject string `json:"subject"`
	// 信息内容
	Message string `json:"message"`
}

站内信

type SmsApiPerm

type SmsApiPerm struct {
	// 短信提供商,1:通用HTTP接口,2:腾讯云短信,3:阿里云短信,4:创蓝短信
	Provider int
	// 接口KEY
	Key string
	// 接口密钥
	Secret string
	/** 签名 */
	Signature string
	// 默认模板编号
	TemplateId string
	// Http接口
	Extra *SmsExtraSetting
}

短信接口参数设置

type SmsApiSet

type SmsApiSet map[int]*SmsApiPerm

短信接口设置

type SmsExtraSetting

type SmsExtraSetting struct {
	/** 接口地址 */
	ApiUrl string
	/** 请求数据,如: phone={phone}&content={content}*/
	Params string
	/** 请求方式, GET或POST */
	Method string
	/** 编码 */
	Charset string
	/** 发送成功,包含的字符,用于检测是否发送成功 */
	SuccessChars string
}

* 短信接口额外信息配置

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL