Module: Dingxin::Sms

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

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
"0.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



21
22
23
# File 'lib/dingxin/sms.rb', line 21

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.canonicalized_query_string(params) ⇒ Object

规范化参数



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dingxin/sms.rb', line 65

def canonicalized_query_string(params)
  cqstring = ''
  params.sort_by{|key, val| key}.each do |key, value|
    if cqstring.empty?
      cqstring += "#{encode(key)}=#{encode(value)}"
    else
      cqstring += "&#{encode(key)}=#{encode(value)}"
    end
  end
  cqstring
end

.configure {|configuration| ... } ⇒ Object

Yields:



25
26
27
# File 'lib/dingxin/sms.rb', line 25

def configure
  yield(configuration)
end

.encode(input) ⇒ Object

对字符串进行 PERCENT 编码 apidock.com/ruby/ERB/Util/url_encode



60
61
62
# File 'lib/dingxin/sms.rb', line 60

def encode(input)
  output = url_encode(input)
end

.get_long_url(params) ⇒ Object



53
54
55
56
# File 'lib/dingxin/sms.rb', line 53

def get_long_url(params)
  coded_params = canonicalized_query_string(params)
  url = 'http://dingxin2.market.alicloudapi.com/dx/longSendSms?' + coded_params
end

.get_url(params) ⇒ Object



48
49
50
51
# File 'lib/dingxin/sms.rb', line 48

def get_url(params)
  coded_params = canonicalized_query_string(params)
  url = 'http://dingxin.market.alicloudapi.com/dx/sendSms?' + coded_params
end

.long_send(mobile, tpl_id, param) ⇒ Object

curl -i -X POST ‘dingxin2.market.alicloudapi.com/dx/longSendSms?mobile=159XXXX9999&param=param&tpl_id=TP1802095’ -H ‘Authorization:APPCODE 你自己的AppCode’



39
40
41
42
43
44
45
46
# File 'lib/dingxin/sms.rb', line 39

def long_send(mobile, tpl_id, param)
  Typhoeus.post(get_long_url({
    'mobile' => mobile,
    'tpl_id' => tpl_id,
    'param' => param
    }),
    headers: { "Authorization" => "APPCODE #{configuration.app_code}" })
end

.send(mobile, tpl_id, param) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/dingxin/sms.rb', line 29

def send(mobile, tpl_id, param)
  Typhoeus.post(get_url({
    'mobile' => mobile,
    'tpl_id' => tpl_id,
    'param' => param
    }),
    headers: { "Authorization" => "APPCODE #{configuration.app_code}" })
end