Module: Txyun::Sms
- Defined in:
- lib/txyun/sms.rb,
lib/txyun/sms/version.rb,
lib/generators/txyun/sms/initializer_generator.rb
Defined Under Namespace
Classes: Configuration, InitializerGenerator
Constant Summary collapse
- VERSION =
"0.1.1"
Class Attribute Summary collapse
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
- .create_params(mobile_num, tpl_id, message_params, time_stamp, sig) ⇒ Object
- .send(mobile_num, template_code, message_params) ⇒ Object
Class Attribute Details
.configuration ⇒ Object
22 23 24 |
# File 'lib/txyun/sms.rb', line 22 def configuration @configuration ||= Configuration.new end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
26 27 28 |
# File 'lib/txyun/sms.rb', line 26 def configure yield(configuration) end |
.create_params(mobile_num, tpl_id, message_params, time_stamp, sig) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/txyun/sms.rb', line 30 def create_params(mobile_num, tpl_id, , time_stamp, sig) sms_params ={ 'tel' => { 'nationcode' => configuration.nationcode, 'mobile' => mobile_num }, 'sign' => configuration.sign, 'tpl_id' => tpl_id, 'params' => [], 'sig' => "#{sig}", 'time' => time_stamp, 'extend' => configuration.extend_code, 'ext' => configuration.ext } end |
.send(mobile_num, template_code, message_params) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/txyun/sms.rb', line 46 def send(mobile_num, template_code, ) temp_string = rand(100000..999999) current_url = "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=#{configuration.sdkappid}&random=#{temp_string}" time_stamp = Time.now.to_i wait_string = "appkey=#{configuration.appkey}&random=#{temp_string}&time=#{time_stamp}&mobile=#{mobile_num}" sig = Digest::SHA256.hexdigest(wait_string) sms_params = create_params(mobile_num, template_code, , time_stamp, sig) rpost = HTTParty.post(current_url, {body: sms_params.to_json}) end |