Module: Tencent::Sms

Defined in:
lib/tencent/sms.rb,
lib/tencent/sms/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.appidObject

Returns the value of attribute appid.



9
10
11
# File 'lib/tencent/sms.rb', line 9

def appid
  @appid
end

.appkeyObject

Returns the value of attribute appkey.



9
10
11
# File 'lib/tencent/sms.rb', line 9

def appkey
  @appkey
end

Class Method Details

.config {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Tencent::Sms)

    the object that the method was called on



11
12
13
# File 'lib/tencent/sms.rb', line 11

def config
  yield self if block_given?
end

.random_numberObject



40
41
42
# File 'lib/tencent/sms.rb', line 40

def random_number
  rand(10_000...99_999)
end

.sendsms(message) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tencent/sms.rb', line 15

def sendsms(message)
  random = random_number
  time = Time.now.to_i
  body = {
    :ext => "",
    :extend => "",
    :params => message[:params],
    :sig => sig(random, time, message[:mobile]),
    :sign => message[:sign],
    :tel => {
      :mobile => message[:mobile],
      :nationcode => message[:nationcode]
    },
    :time => time,
    :tpl_id => message[:tpl_id]
  }
  url = "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=#{appid}&random=#{random}"

  RestClient.post(url, body.to_json)
end

.sig(random, time, mobile) ⇒ Object



36
37
38
# File 'lib/tencent/sms.rb', line 36

def sig(random, time, mobile)
  Digest::SHA256.hexdigest "appkey=#{appkey}&random=#{random}&time=#{time}&mobile=#{mobile}"
end