Class: AlidayuSmsSender

Inherits:
Object
  • Object
show all
Defined in:
lib/alidayu_sms.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AlidayuSmsSender

Returns a new instance of AlidayuSmsSender.



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
# File 'lib/alidayu_sms.rb', line 21

def initialize(options = {})
  if load_config.present? && load_config[:alidayu].present?
    options = load_config[:alidayu].merge(options)
  end
  options = HashWithIndifferentAccess.new(options)
  check_system_params(options)

  # 基础类实例
  self.source = AlidayuSms::Alidayu.new(options)

  # 动态方法
  class_eval do
    load_config[:alidayu][:sms_templates].each do |sms_template|
      define_method("send_code_for_#{sms_template[:name]}") do |phone, _sms_param = {}, extend = ""|
        _sms_param[:product] ||= load_config[:alidayu][:product]

        options = {
          sms_param: _sms_param.to_json,
          phones: phone, # 手机号码
          extend: extend, # 公共回传参数,在“消息返回”中会透传回该参数;举例:用户可以传入自己下级的会员ID,在消息返回时,该会员ID会包含在内,用户可以根据该会员ID识别是哪位会员使用了你的应用
          sms_free_sign_name: sms_template[:sms_free_sign_name], # 短信签名
          sms_template_code: sms_template[:sms_template_code] # 短信模板
        }
        AlidayuSmsSender.new.batchSendSms(options)
      end
    end
  end
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



20
21
22
# File 'lib/alidayu_sms.rb', line 20

def source
  @source
end

#template_codeObject

Returns the value of attribute template_code.



20
21
22
# File 'lib/alidayu_sms.rb', line 20

def template_code
  @template_code
end

Instance Method Details

#batchSendSms(options = {}) ⇒ Object

发送短信



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/alidayu_sms.rb', line 51

def batchSendSms(options = {})
  options = HashWithIndifferentAccess.new(options)
  arr = %w(sms_param phones extend sms_free_sign_name sms_template_code)
  attr, flag = [], false
  arr.each do |a|
    flag = true unless options[a]
    attr << options[a]
  end

  check_params(flag, options)
  puts "阿里大鱼传入参数为:#{attr}"

  source.standard_send_msg(attr)
end