Module: SmartSMS::MessageService::ClassMethods

Defined in:
lib/smart_sms/message_service.rb

Overview

Class methods

Constant Summary collapse

DATETIME_FORMAT =
'%Y-%m-%d %H:%M:%S'

Instance Method Summary collapse

Instance Method Details

#deliver(phone, content, options = {}) ⇒ Object

发送短信到手机, 默认使用模板发送, 提供通用接口支持

  • phone: 需要接受短信的手机号码

  • content: 短信验证内容

Options:

  • method 如若要使用通用短信接口, 需要 :method => :general

  • tpl_id 选择发送短信的模板, 默认是2



21
22
23
24
25
26
27
28
29
30
# File 'lib/smart_sms/message_service.rb', line 21

def deliver(phone, content, options = {})
  if options[:method] == :general
    Request.post 'sms/send.json', mobile: phone, text: content, extend: options[:extend]
  else
    options[:code] = content
    message = parse_content options
    tpl_id = options[:tpl_id] || SmartSMS.config.template_id
    Request.post 'sms/tpl_send.json', tpl_id: tpl_id, mobile: phone, tpl_value: message
  end
end

#find(options = {}) ⇒ Object

参见 find_messages 方法



39
40
41
# File 'lib/smart_sms/message_service.rb', line 39

def find(options = {})
  find_messages 'sms/get.json', options
end

#find_by_sid(sid) ⇒ Object

根据sid来查询短信记录



34
35
36
# File 'lib/smart_sms/message_service.rb', line 34

def find_by_sid(sid)
  Request.post 'sms/get.json', sid: sid
end

#get_black_word(text = '') ⇒ Object

查询黑名单词语, 用于预先测试可能无法通过审核的模板



45
46
47
# File 'lib/smart_sms/message_service.rb', line 45

def get_black_word(text = '')
  Request.post 'sms/get_black_word.json', text: text
end

#get_reply(options = {}) ⇒ Object

查询用户回复的短信, 参见 find_messages 方法



50
51
52
# File 'lib/smart_sms/message_service.rb', line 50

def get_reply(options = {})
  find_messages 'sms/get_reply.json', options
end