Class: Aliyun::Sms::PhoneCode
- Inherits:
-
Object
- Object
- Aliyun::Sms::PhoneCode
- Defined in:
- lib/aliyun/sms/phone_code.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
-
#access_key_secret ⇒ Object
Returns the value of attribute access_key_secret.
-
#action ⇒ Object
Returns the value of attribute action.
-
#format ⇒ Object
Returns the value of attribute format.
-
#region_id ⇒ Object
Returns the value of attribute region_id.
-
#sign_name ⇒ Object
Returns the value of attribute sign_name.
-
#signature_method ⇒ Object
Returns the value of attribute signature_method.
-
#signature_version ⇒ Object
Returns the value of attribute signature_version.
-
#sms_version ⇒ Object
Returns the value of attribute sms_version.
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
- .create_params(template_code, phone_number, content) ⇒ Object
-
.send(template_code, phone_number, params) ⇒ Object
TODO: 错误处理.
- .sign(key_secret, params) ⇒ Object
- .sign_result(key_secret, params) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ PhoneCode
constructor
A new instance of PhoneCode.
Constructor Details
#initialize ⇒ PhoneCode
Returns a new instance of PhoneCode.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aliyun/sms/phone_code.rb', line 21 def initialize @access_key_secret = '' @access_key_id = '' @sign_name = '' @action ||= 'SingleSendSms' @format ||= 'JSON' @region_id ||= 'cn-hangzhou' @signature_method ||= 'HMAC-SHA1' @signature_version ||= '1.0' @sms_version ||= '2016-09-27' end |
Class Attribute Details
Instance Attribute Details
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
12 13 14 |
# File 'lib/aliyun/sms/phone_code.rb', line 12 def access_key_id @access_key_id end |
#access_key_secret ⇒ Object
Returns the value of attribute access_key_secret.
12 13 14 |
# File 'lib/aliyun/sms/phone_code.rb', line 12 def access_key_secret @access_key_secret end |
#action ⇒ Object
Returns the value of attribute action.
12 13 14 |
# File 'lib/aliyun/sms/phone_code.rb', line 12 def action @action end |
#format ⇒ Object
Returns the value of attribute format.
12 13 14 |
# File 'lib/aliyun/sms/phone_code.rb', line 12 def format @format end |
#region_id ⇒ Object
Returns the value of attribute region_id.
12 13 14 |
# File 'lib/aliyun/sms/phone_code.rb', line 12 def region_id @region_id end |
#sign_name ⇒ Object
Returns the value of attribute sign_name.
12 13 14 |
# File 'lib/aliyun/sms/phone_code.rb', line 12 def sign_name @sign_name end |
#signature_method ⇒ Object
Returns the value of attribute signature_method.
12 13 14 |
# File 'lib/aliyun/sms/phone_code.rb', line 12 def signature_method @signature_method end |
#signature_version ⇒ Object
Returns the value of attribute signature_version.
12 13 14 |
# File 'lib/aliyun/sms/phone_code.rb', line 12 def signature_version @signature_version end |
#sms_version ⇒ Object
Returns the value of attribute sms_version.
12 13 14 |
# File 'lib/aliyun/sms/phone_code.rb', line 12 def sms_version @sms_version end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
40 41 42 |
# File 'lib/aliyun/sms/phone_code.rb', line 40 def configure yield(configuration) end |
.create_params(template_code, phone_number, content) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/aliyun/sms/phone_code.rb', line 44 def create_params(template_code, phone_number, content) sms_params ={ 'AccessKeyId' => configuration.access_key_id, 'Action' => configuration.action, 'Format' => configuration.format, 'ParamString' => , 'RecNum' => phone_number, 'RegionId' => configuration.region_id, 'SignName' => configuration.sign_name, 'SignatureMethod' => configuration.signature_method, 'SignatureNonce' => seed_signature_nonce, 'SignatureVersion' => configuration.signature_version, 'TemplateCode' => template_code, 'Timestamp' => , 'Version' => configuration.sms_version, } end |
.send(template_code, phone_number, params) ⇒ Object
TODO: 错误处理
63 64 65 66 67 68 69 |
# File 'lib/aliyun/sms/phone_code.rb', line 63 def send(template_code, phone_number, params) Net::HTTP.post( URI("https://sms.aliyuncs.com"), headers: {"Content-Type": "application/x-www-form-urlencoded"}, body: sign_result(configuration.access_key_secret, params) ) end |
.sign(key_secret, params) ⇒ Object
75 76 77 78 79 |
# File 'lib/aliyun/sms/phone_code.rb', line 75 def sign(key_secret, params) signature = 'POST' + '&' + encode('/') + '&' + encode(URI.encode_www_form(params)) sign = Base64.encode64(OpenSSL::HMAC.digest('sha1', "#{key_secret}&", signature)) encode(sign.chomp) end |
.sign_result(key_secret, params) ⇒ Object
71 72 73 |
# File 'lib/aliyun/sms/phone_code.rb', line 71 def sign_result(key_secret, params) body_data = "Signature=" + sign(key_secret, params) + '&' + query_string(params) end |