Documentation ¶
Index ¶
- Constants
- Variables
- func CloseAlidayu(waitSeconds ...int) error
- func InitAlidayu(prod bool, key, secret string)
- func IsIdle() bool
- func NewAlidayuResponseError(response string) error
- func SendMessage(msg IMessage, f ...MessageErrorFunc) error
- func SendMessageDirect(msg IMessage) error
- func SendMessageQueue(msg IMessage, f ...MessageErrorFunc) error
- func SetAlidayuQueue(thread_count, queue_capacity int)
- type Courier
- type Envelope
- type IMessage
- type Message
- type MessageDouble
- type MessageErrorFunc
- type MessageQuery
- type MessageSms
- type MessageTTS
- type MessageVoice
- type Postbox
Constants ¶
const ( URL_PRODUCTION string = "https://eco.taobao.com/router/rest" // 正式环境 (或者: http://gw.api.taobao.com/router/rest) URL_SANDBOX string = "http://gw.api.tbsandbox.com/router/rest" // 沙箱环境 (或者: http://gw.api.tbsandbox.com/router/rest) )
const ( DEFAULT_COURIER_SIZE int = 1 // 默认线程数 DEFAULT_CAPACITY_SIZE int = 30 // 默认线程承载数量 )
const ( MESSAGE_METHOD_DOUBLE string = "alibaba.aliqin.fc.voice.num.doublecall" // 多方通话 MESSAGE_METHOD_TTS = "alibaba.aliqin.fc.tts.num.singlecall" // 文本转语音通知 MESSAGE_METHOD_VOICE = "alibaba.aliqin.fc.voice.num.singlecall" // 发送语音 MESSAGE_METHOD_SMS = "alibaba.aliqin.fc.sms.num.send" // 短信发送 MESSAGE_METHOD_SMS_QUERY = "alibaba.aliqin.fc.sms.num.query" // 短信发送记录查询 )
const ( MESSAGE_FORMAT_JSON string = "json" // 短信JSON参数,推荐 MESSAGE_FORMAT_XML = "xml" // 短信XML参数 )
const ( MESSAGE_SIGN_METHOD_HMAC string = "hmac" // 签名方式-HMAC MESSAGE_SIGN_METHOD_MD5 = "md5" // 签名方式-MD5 )
Variables ¶
var ( AppURL string = URL_SANDBOX // alidayu的api地址 AppKey string // alidayu的key AppSecret string // alidayu的secret )
var ( ErrNoAppKey error = errors.New("goalidayu: Key and Secret must not be null!") ErrServiceClosed = errors.New("goalidayu: Service is closed!") ErrServiceOverflow = errors.New("goalidayu: Service is overflow!") ErrPostboxBusy = errors.New("goalidayu: Postbox is busy") ErrCourierBusy = errors.New("goalidayu: Courier is busy") )
var ( ErrMessageNil error = errors.New("goalidayu: Message must not be null!") ErrMessageMethod = errors.New("goalidayu: Invalid message method") ErrMessageFormat = errors.New("goalidayu: Invalid message format") ErrMessageSignMethod = errors.New("goalidayu: Invalid message sign method") )
Functions ¶
func CloseAlidayu ¶
CloseAlidayu 关闭服务 waitSeconds: 最大的等待时间
func InitAlidayu ¶
InitAlidayu 初始化服务 prod: 是否应用于正式环境 key: alidayu账号分配给应用的AppKey secret: alidayu账号分配给应用的AppSecret
func NewAlidayuResponseError ¶
func SendMessage ¶
func SendMessage(msg IMessage, f ...MessageErrorFunc) error
SendMessage 默认发送信息 基于SetAlidayuQueue的设置,与SendMessageQueue相同
func SendMessageDirect ¶
SendMessageDirect 同步发送信息 直接发送信息,尝试一次返回结果
func SendMessageQueue ¶
func SendMessageQueue(msg IMessage, f ...MessageErrorFunc) error
SendMessageQueue 异步发送信息 异步发送信息,基于SetAlidayuQueue的设置队列处理
func SetAlidayuQueue ¶
func SetAlidayuQueue(thread_count, queue_capacity int)
SetAlidayuQueue 设置服务队列 thread_count: 同时处理线程数 queue_capacity: 每个线程的承载数量能力
Types ¶
type Courier ¶
type Courier struct {
// contains filtered or unexported fields
}
func NewCourier ¶
func NewCourier() *Courier
func (*Courier) SendEnvelope ¶
type Envelope ¶
type Envelope struct { Message IMessage ErrorFunc MessageErrorFunc }
func NewEnvelope ¶
func NewEnvelope(msg IMessage, f MessageErrorFunc) *Envelope
func (*Envelope) FailToSend ¶
func (*Envelope) SuccessToSend ¶
func (e *Envelope) SuccessToSend()
type Message ¶
type Message struct { Method string `json:"method"` AppKey string `json:"app_key"` Session string `json:"session"` Timestamp string `json:"timestamp"` Format string `json:"format"` Version string `json:"v"` PartnerId string `json:"partner_id"` TargetAppKey string `json:"target_app_key"` Simplify bool `json:"simplify"` SignMethod string `json:"sign_method"` Sign string `json:"sign"` Err error `json:"-"` TryCount int `json:"-"` }
func NewMessage ¶
type MessageDouble ¶
type MessageDouble struct { Message `json:""` CallerTel string `json:"caller_num"` ShowCallerTel string `json:"caller_show_num"` CalledTel string `json:"called_num"` ShowCalledTel string `json:"called_show_num"` }
MessageDouble 多方通话
func (*MessageDouble) SetCalledTel ¶
func (s *MessageDouble) SetCalledTel(tel string, show string) *MessageDouble
SetCalledTel 设置多方通话的接收方电话号码
func (*MessageDouble) SetCallerTel ¶
func (s *MessageDouble) SetCallerTel(tel string, show string) *MessageDouble
SetCallerTel 设置多方通话的发起方电话号码
type MessageErrorFunc ¶
type MessageQuery ¶
type MessageQuery struct { Message `json:""` BizId string `json:"biz_id"` Tel string `json:"rec_num"` Date string `json:"query_date"` CurrentPage int64 `json:"current_page"` PageSize int64 `json:"page_size"` }
MessageQuery 短信发送记录查询
func (*MessageQuery) SetLast ¶
func (s *MessageQuery) SetLast() *MessageQuery
SetLast 设置只获取短信发送记录查询的最后一条发送状态
func (*MessageQuery) SetPage ¶
func (s *MessageQuery) SetPage(current, size int64) *MessageQuery
SetPage 设置短信发送记录查询的分页参数
func (*MessageQuery) SetTel ¶
func (s *MessageQuery) SetTel(tel string) *MessageQuery
SetTel 设置短信发送记录查询的手机号码
type MessageSms ¶
type MessageSms struct { Message `json:""` Type string `json:"sms_type"` FreeSignName string `json:"sms_free_sign_name"` Param string `json:"sms_param"` Tel string `json:"rec_num"` TemplateCode string `json:"sms_template_code"` }
MessageSms 短信发送
func (*MessageSms) SetContent ¶
func (s *MessageSms) SetContent(code string, param map[string]string) *MessageSms
SetContent 设置短信发送信息模板code及参数param
func (*MessageSms) SetTel ¶
func (s *MessageSms) SetTel(tel ...string) *MessageSms
SetTel 设置短信接收方的电话号码
type MessageTTS ¶
type MessageTTS struct { Message `json:""` Param string `json:"tts_param"` CalledTel string `json:"called_num"` ShowCalledTel string `json:"called_show_num"` TTSCode string `json:"tts_code"` }
MessageTTS 文本转语音通知
func (*MessageTTS) SetCalledTel ¶
func (s *MessageTTS) SetCalledTel(tel string, show string) *MessageTTS
SetCalledTel 设置文本转语音通知的接收方电话号码
func (*MessageTTS) SetContent ¶
func (s *MessageTTS) SetContent(code string, param map[string]string) *MessageTTS
SetContent 设置文本转语音通知的内容模板code和参数param
type MessageVoice ¶
type MessageVoice struct { Message `json:""` CalledTel string `json:"called_num"` ShowCalledTel string `json:"called_show_num"` VoiceCode string `json:"voice_code"` }
MessageVoice 发送语音
func (*MessageVoice) SetCalledTel ¶
func (s *MessageVoice) SetCalledTel(tel string, show string) *MessageVoice
SetCalledTel 设置发送语音接收方的电话号码
type Postbox ¶
func NewPostbox ¶
func (*Postbox) StuffMessage ¶
func (s *Postbox) StuffMessage(msg IMessage, f ...MessageErrorFunc) error