Class: Utils::Sms
- Inherits:
-
Object
- Object
- Utils::Sms
- Defined in:
- lib/utils/sms.rb
Class Method Summary collapse
-
.logger ⇒ Object
定义logger.
- .send(mobile, message, provider = '') ⇒ Object
- .send_by_yunpian(mobile, message) ⇒ Object
- .send_verify_code(mobile, code, provider = '') ⇒ Object
- .send_verify_code_by_yunpian(mobile, code) ⇒ Object
Class Method Details
.logger ⇒ Object
定义logger
6 7 8 |
# File 'lib/utils/sms.rb', line 6 def self.logger Rails.logger end |
.send(mobile, message, provider = '') ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/utils/sms.rb', line 10 def self.send(mobile,,provider='') provider = Rails.configuration.sms_provider if provider.blank? && Rails.configuration.respond_to?('sms_provider') result = false case provider when 'yunpian' result = send_by_yunpian(mobile,) end result end |
.send_by_yunpian(mobile, message) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/utils/sms.rb', line 19 def self.send_by_yunpian(mobile,) result = false apikey = Rails.configuration.sms_apikey if Rails.configuration.respond_to?('sms_apikey') uri = URI.parse("http://yunpian.com/v1/sms/send.json") response = Net::HTTP.post_form(uri, {"apikey" => apikey,"mobile"=>mobile,"text"=>}) ret = JSON.parse(response.body) if ret["code"] == 0 result = true end result end |
.send_verify_code(mobile, code, provider = '') ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/utils/sms.rb', line 31 def self.send_verify_code(mobile,code,provider='') provider = Rails.configuration.sms_provider if provider.blank? && Rails.configuration.respond_to?('sms_provider') result = false case provider when 'yunpian' result = send_verify_code_by_yunpian(mobile,code) end result end |
.send_verify_code_by_yunpian(mobile, code) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/utils/sms.rb', line 40 def self.send_verify_code_by_yunpian(mobile,code) result = false apikey = Rails.configuration.sms_apikey if Rails.configuration.respond_to?('sms_apikey') company = Rails.configuration.sms_company if Rails.configuration.respond_to?('sms_company') tpl_id = 1 tpl_id = Rails.configuration.sms_tpl_id if Rails.configuration.respond_to?('tpl_id') tpl_value = "#code#=#{code}&#company#=#{company}" uri = URI.parse("http://yunpian.com/v1/sms/tpl_send.json") response = Net::HTTP.post_form(uri, {"apikey" => apikey,"mobile"=>mobile, "tpl_id"=>tpl_id,"tpl_value"=>tpl_value}) ret = JSON.parse(response.body) logger.debug("send_verify_code_by_yunpian:" + ret.to_s) if ret["code"] == 0 result = true end result end |