module Dingxin::Sms

Constants

VERSION

Attributes

configuration[W]

Public Class Methods

canonicalized_query_string(params) click to toggle source

规范化参数

# 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
configuration() click to toggle source
# File lib/dingxin/sms.rb, line 21
def configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/dingxin/sms.rb, line 25
def configure
  yield(configuration)
end
encode(input) click to toggle source

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

# File lib/dingxin/sms.rb, line 60
def encode(input)
  output = url_encode(input)
end
get_long_url(params) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

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

# 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) click to toggle source
# 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