Class: AlidayuSmsSender
- Inherits:
-
Object
- Object
- AlidayuSmsSender
- Defined in:
- lib/alidayu_sms.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#template_code ⇒ Object
Returns the value of attribute template_code.
Instance Method Summary collapse
-
#batchSendSms(options = {}) ⇒ Object
发送短信.
-
#initialize(options = {}) ⇒ AlidayuSmsSender
constructor
A new instance of AlidayuSmsSender.
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( = {}) if load_config.present? && load_config[:alidayu].present? = load_config[:alidayu].merge() end = HashWithIndifferentAccess.new() check_system_params() # 基础类实例 self.source = AlidayuSms::Alidayu.new() # 动态方法 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] = { 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() end end end end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
20 21 22 |
# File 'lib/alidayu_sms.rb', line 20 def source @source end |
#template_code ⇒ Object
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( = {}) = HashWithIndifferentAccess.new() arr = %w(sms_param phones extend sms_free_sign_name sms_template_code) attr, flag = [], false arr.each do |a| flag = true unless [a] attr << [a] end check_params(flag, ) puts "阿里大鱼传入参数为:#{attr}" source.standard_send_msg(attr) end |